File size: 7,469 Bytes
26e0321
93648d9
 
 
23ff911
8362b1b
93648d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26e0321
93648d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26e0321
93648d9
 
 
26e0321
93648d9
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import gradio as gr
from transformers import pipeline

# Define the path to your image (update it with the correct path)
image_path = "college_logo.jpg"  # Update this path if needed
  # Update this path

# Step 1: Load the Question Answering Pipeline
qa_pipeline = pipeline("question-answering", model="distilbert-base-uncased-distilled-squad")

# Step 2: Define the College Data (in English)
college_data = {
    "name": "Government Boys Degree College Daulatpur",
    "about": """
    The college was notified to work from 16th July 2003 on the directions of the then care-taker Minister for Education, Mr. Khan Muhammad Dahri.
    At the beginning, the college had no staff of its own, so it was borrowed from Government Degree College Sakrand.
    The college started its classes in the afternoon at Government High School Daulatpur as it had no specific building.
    With the help of the EDO Education, the possession of the Government Girls High School (Old) Daulatpur was given to the college.
    """,
    "extended_about": """
    Government Boys Degree College Daulatpur is one of the leading educational institutions in the region. It aims to provide high-quality education
    and a conducive environment for academic excellence. The college offers various undergraduate programs and is committed to the intellectual
    and professional growth of its students. It strives to nurture responsible citizens who contribute positively to society.
    """,
    "programs": ["ADSE-I", "ADSE-II", "ADAA-I", "ADAA-II", "BS (Zoology) (Proposed for this year)"],
    "teachers": {
        "Islamiat": ["Prof Mahfooz Khan (Associate Prof)", "M. Essa Samego (Lecturer)"],
        "Physics": ["Muhammad Aslam Palli (Associate Prof)", "Asif Ali Rajput (Lecturer)"],
        "Botany": ["Abdul Rahman Gaincho (Lecturer)"],
        "Chemistry": ["Ali Aijaz Dahri (Lecturer)"],
        "Math": ["Fida Hussain (Lecturer)"],
        "Librarian": ["Zulfiqar Ali (Senior Librarian)"],
        "DPE": ["Naseer Ahmed (DPE)"],
    },
    "staff": {
        "clerks": ["Mr. Younis Unar (Senior Clerk)", "Mr. Muhammad Bughio (Senior Clerk)", "Mr. Dadan Khan (Junior Clerk)"],
        "lab_assistants": ["Mr. Rahib Ali Unar (Lab Assistant)", "Mr. Shahbaz Khan (Lab Attendant)"],
        "other": ["Mr. Peruaz Ali (Sanitary Worker)"],
    },
    "facilities": [
        "Digital library with 20+ computers",
        "Parks: Alquran Park and Botany Park with 50+ plants",
        "Building: Two-floor building with 24 rooms",
        "Labs: Zoology, Botany, Physics, Chemistry",
        "Parking area",
        "Solar system",
        "RO Plant",
    ],
    "principal": "Prof Irshad Ali Otho",
    "rooms": 24,  # Replaced 'classes' with 'rooms'
    "established": "2003",
    "contact": {
        "location": "National Highway N6 bypass Daulatpur",
        "phone": "+92 300 3003249",
        "email": "[email protected]",
        "facebook": "https://www.facebook.com/share/19j9Z1iEvz/"
    },
}

# Step 3: Custom Question Logic (Simplified for English)
def answer_question(question):
    # Lowercase the question for simpler matching
    question = question.lower()

    # Rule-based answers for specific types of questions
    if "college name" in question or "what is the name" in question or "name of college" in question:
        return f"The name of the college is {college_data['name']}."

    elif "about college" in question or "tell me about the college" in question:
        return f"About the college:\n{college_data['about']}\n\n{college_data['extended_about']}"

    elif "program" in question or "course" in question:
        return f"Programs offered:\n- " + "\n- ".join(college_data["programs"])

    elif "teacher" in question or "faculty" in question or "lecturer" in question:
        if "english" in question:
            return "We do not have an English teacher at the college."
        for subject, teachers in college_data["teachers"].items():
            if subject.lower() in question:
                return f"The {subject} lecturer(s): " + ", ".join(teachers)
        return (
            "Teachers:\n" + "\n".join(
                [f"{subject}: " + ", ".join(teachers) for subject, teachers in college_data["teachers"].items()]
            )
        )

    elif "room" in question:
        return f"The college has {college_data['rooms']} rooms available."

    elif "facility" in question:
        return f"Facilities available:\n- " + "\n- ".join(college_data["facilities"])

    elif "principal" in question:
        return f"Our Principal is {college_data['principal']}."

    elif "staff" in question or "clerk" in question:
        clerks = "\n".join(college_data["staff"]["clerks"])
        lab_assistants = "\n".join(college_data["staff"]["lab_assistants"])
        other_staff = "\n".join(college_data["staff"]["other"])
        return f"Clerks:\n{clerks}\n\nLab Assistants:\n{lab_assistants}\n\nOther Staff:\n{other_staff}"

    elif "location" in question or "where" in question:
        return f"The college is located at {college_data['contact']['location']}."

    elif "contact" in question or "email" in question or "phone" in question:
        contact_info = college_data["contact"]
        return (
            f"Contact Details:\n"
            f"- Location: {contact_info['location']}\n"
            f"- Phone: {contact_info['phone']}\n"
            f"- Email: {contact_info['email']}\n"
            f"- Facebook: {contact_info['facebook']}"
        )

    elif "establish" in question or "founded" in question or "start" in question:
        return f"The college was established in {college_data['established']}."

    elif "ro plant" in question:
        return "Yes, we have an RO plant available at the college."

    else:
        return "I'm sorry, I couldn't understand your question. Please ask something about the college."

# Step 4: Create Gradio Interface
with gr.Blocks() as app:
    # Header with College Name and Logo (without download option)
    gr.Markdown("<h2 style='text-align:center; color: darkblue;'>Government Boys Degree College Daulatpur</h2>")
    gr.Image(image_path, elem_id="college_logo", width=150, interactive=False)  # Update with the correct path

    # Centralize the 'About the College' in the main area
    gr.Markdown("### About the College")
    about_college = gr.Textbox(value=f"{college_data['about']}\n\n{college_data['extended_about']}",
                               label="About the College", interactive=False, elem_id="about_college")

    # Question and Answer section
    question = gr.Textbox(label="Ask a question about the college")
    answer = gr.Textbox(label="Answer", interactive=False)
    question.submit(answer_question, inputs=question, outputs=answer)

    # Contact Us section at the end
    gr.Markdown("### Contact Us")
    contact_info = gr.Textbox(value=f"Location: {college_data['contact']['location']}\n"
                                  f"Phone: {college_data['contact']['phone']}\n"
                                  f"Email: {college_data['contact']['email']}\n"
                                  f"Facebook: {college_data['contact']['facebook']}",
                                  label="Contact Info", interactive=False, elem_id="contact_info")

    # Footer with 'Made by Musawir' and Email
    gr.Markdown("### Made by Musawir")
    gr.Markdown("Email: [[email protected]](mailto:[email protected])")

# Launch the app
app.launch()