Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
# Step 2: Import libraries
|
2 |
import gradio as gr
|
3 |
-
from transformers import pipeline
|
4 |
|
5 |
# Step 3: Define College Data
|
6 |
college_about = """
|
@@ -10,276 +9,130 @@ The college started its classes in the afternoon at Government High School Daula
|
|
10 |
With the help of the EDO Education, the possession of the Government Girls High School (Old) Daulatpur was given to the college.
|
11 |
"""
|
12 |
|
13 |
-
|
14 |
-
1. Prof Mahfooz Khan (Associate Prof, Islamiat)
|
15 |
-
2. Muhammad Aslam Palli (Associate Prof, Physics)
|
16 |
-
3. Abdul Rahman Gaincho (Botany)
|
17 |
-
4. M. Essa Samego (Lecturer, Islamiat)
|
18 |
-
5. Ali Aijaz Dahri (Lecturer, Chemistry)
|
19 |
-
6. Asif Ali Rajput (Lecturer, Physics)
|
20 |
-
7. Fida Hussain (Lecturer, Math)
|
21 |
-
8. Zulfiqar Ali (Senior Librarian)
|
22 |
-
"""
|
23 |
-
|
24 |
-
facilities = """
|
25 |
-
Facilities available:
|
26 |
-
1. Digital library with 20+ computers
|
27 |
-
2. Parks: Alquran Park and Botany Park with 50+ plants
|
28 |
-
3. Labs: Zoology, Botany, Physics, Chemistry
|
29 |
-
4. Parking area
|
30 |
-
5. Solar system and RO Plant
|
31 |
-
"""
|
32 |
-
|
33 |
-
# Step 4: Define College Dataset (from your data dictionary)
|
34 |
-
# Define the dataset
|
35 |
data = {
|
36 |
-
"
|
37 |
-
"
|
38 |
-
"tell me establish of college?",
|
39 |
-
"who is principal of college?",
|
40 |
-
"what a programs in college?",
|
41 |
-
"what a programs in college?",
|
42 |
-
"what a programs in college?",
|
43 |
-
"what a programs in college?",
|
44 |
-
"what a programs in college?",
|
45 |
-
"where is located?",
|
46 |
-
"islamiat teacher?",
|
47 |
-
"physics teacher?",
|
48 |
-
"botany teacher?",
|
49 |
-
"islamiat teacher?",
|
50 |
-
"chemistry teacher?",
|
51 |
-
"physics teacher?",
|
52 |
-
"math teacher?",
|
53 |
-
"who is librarian",
|
54 |
-
"who is DPE",
|
55 |
-
"lab assistant?",
|
56 |
-
"clerk?",
|
57 |
-
"clerk?",
|
58 |
-
"clerk?",
|
59 |
-
"lab assistant?",
|
60 |
-
"lab assistant?",
|
61 |
-
"lab assistant?",
|
62 |
-
"who is sanitary worker?",
|
63 |
-
"facilities?",
|
64 |
-
"facilities?",
|
65 |
-
"facilities?",
|
66 |
-
"facilities?",
|
67 |
-
"facilities?",
|
68 |
-
"facilities?",
|
69 |
-
"facilities?",
|
70 |
-
"facilities?",
|
71 |
-
"facilities?",
|
72 |
-
"facilities?",
|
73 |
-
"facilities?",
|
74 |
],
|
75 |
-
"
|
76 |
-
"
|
77 |
-
"
|
78 |
-
"
|
79 |
-
"
|
80 |
-
"
|
81 |
-
"
|
82 |
-
"
|
83 |
-
|
84 |
-
|
85 |
-
"
|
86 |
-
"
|
87 |
-
"
|
88 |
-
"
|
89 |
-
"
|
90 |
-
"
|
91 |
-
"Teaching Staff",
|
92 |
-
"Teaching Staff",
|
93 |
-
"Teaching Staff",
|
94 |
-
"Non-Teaching Staff",
|
95 |
-
"Non-Teaching Staff",
|
96 |
-
"Non-Teaching Staff",
|
97 |
-
"Non-Teaching Staff",
|
98 |
-
"Non-Teaching Staff",
|
99 |
-
"Non-Teaching Staff",
|
100 |
-
"Non-Teaching Staff",
|
101 |
-
"Non-Teaching Staff",
|
102 |
-
"Facilities",
|
103 |
-
"Facilities",
|
104 |
-
"Facilities",
|
105 |
-
"Facilities",
|
106 |
-
"Facilities",
|
107 |
-
"Facilities",
|
108 |
-
"Facilities",
|
109 |
-
"Facilities",
|
110 |
-
"Facilities",
|
111 |
-
"Facilities",
|
112 |
-
"Facilities",
|
113 |
-
],
|
114 |
-
"Name": [
|
115 |
-
"Government Boys Degree College Daulatpur",
|
116 |
-
"2003",
|
117 |
-
"Prof Irshad Ali Otho",
|
118 |
-
"ADSE-I",
|
119 |
-
"ADSE-II",
|
120 |
-
"ADAA-",
|
121 |
-
"ADAA",
|
122 |
-
"(Zoology),Proposed this year,",
|
123 |
-
"Bypass Daulatpur",
|
124 |
-
"Prof Mahfooz Khan",
|
125 |
-
"Muhammad Aslam Palli",
|
126 |
-
"Abdul Rahman Gaincho",
|
127 |
-
"M. Essa Samego",
|
128 |
-
"Ali Aijaz Dahri",
|
129 |
-
"Asif Ali Rajput",
|
130 |
-
"Fida Hussain",
|
131 |
-
"Zulfiqar Ali",
|
132 |
-
"Naseer Ahmed",
|
133 |
-
"Mr Abear Lund",
|
134 |
-
"Mr Younis Unar",
|
135 |
-
"Mr Muhammad Bughio",
|
136 |
-
"Mr Dadan Khan,",
|
137 |
-
"Mr Rahib Ali Unar",
|
138 |
-
"Mr M Saleem Unar",
|
139 |
-
"Mr Shahbaz Khan",
|
140 |
-
"Mr Peruaz Ali",
|
141 |
-
"Digital Library",
|
142 |
-
"Parks",
|
143 |
-
"Building",
|
144 |
-
"Zoology Lab",
|
145 |
-
"Botany Lab",
|
146 |
-
"Physics Lab",
|
147 |
-
"Chemistry Lab",
|
148 |
-
"Parking Area",
|
149 |
-
"Solar System",
|
150 |
"RO Plant",
|
151 |
],
|
152 |
-
"
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
"
|
157 |
-
"
|
158 |
-
"
|
159 |
-
"
|
160 |
-
|
161 |
-
"NA",
|
162 |
-
"Associate Professor",
|
163 |
-
"Associate Professor",
|
164 |
-
"Lecturer",
|
165 |
-
"Lecturer",
|
166 |
-
"Lecturer",
|
167 |
-
"Lecturer",
|
168 |
-
"Lecturer",
|
169 |
-
"Senior Librarian",
|
170 |
-
"DPE",
|
171 |
-
"Assistant",
|
172 |
-
"Senior Clerk",
|
173 |
-
"Senior Clerk",
|
174 |
-
"Junior Clerk",
|
175 |
-
"Lab Assistant",
|
176 |
-
"Lab Attendant",
|
177 |
-
"Lab Attendant",
|
178 |
-
"Sanitary Worker",
|
179 |
-
"NA",
|
180 |
-
"NA",
|
181 |
-
"NA",
|
182 |
-
"NA",
|
183 |
-
"NA",
|
184 |
-
"NA",
|
185 |
-
"NA",
|
186 |
-
"NA",
|
187 |
-
"NA",
|
188 |
-
"NA",
|
189 |
-
],
|
190 |
-
"Subject/Details": [
|
191 |
-
"NA",
|
192 |
-
"NA",
|
193 |
-
"NA",
|
194 |
-
"NA",
|
195 |
-
"NA",
|
196 |
-
"NA",
|
197 |
-
"NA",
|
198 |
-
"NA",
|
199 |
-
"NA",
|
200 |
-
"Islamiat",
|
201 |
-
"Physics",
|
202 |
-
"Botany",
|
203 |
-
"Islamiat",
|
204 |
-
"Chemistry",
|
205 |
-
"Physics",
|
206 |
-
"Math",
|
207 |
-
"NA",
|
208 |
-
"NA",
|
209 |
-
"NA",
|
210 |
-
"NA",
|
211 |
-
"NA",
|
212 |
-
"NA",
|
213 |
-
"NA",
|
214 |
-
"NA",
|
215 |
-
"NA",
|
216 |
-
"NA",
|
217 |
-
"20+ Computers",
|
218 |
-
"Alquran Park and Botany Park with 50+ plats",
|
219 |
-
"Two-floor building with 24 rooms",
|
220 |
-
"Available",
|
221 |
-
"Available",
|
222 |
-
"Available",
|
223 |
-
"Available",
|
224 |
-
"Available",
|
225 |
-
"Available",
|
226 |
-
"Available",
|
227 |
-
],
|
228 |
}
|
229 |
|
230 |
-
#
|
231 |
-
|
|
|
|
|
232 |
|
|
|
|
|
|
|
233 |
|
234 |
-
|
235 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
236 |
|
237 |
-
|
238 |
-
|
239 |
-
for q, name in zip(data["Questions"], data["Name"]): # Use "Name" for predefined answers
|
240 |
-
if question.lower() in q.lower():
|
241 |
-
return name
|
242 |
-
return "Sorry, I don't have an answer for that. Please ask a different question."
|
243 |
|
244 |
-
|
245 |
-
|
246 |
-
predefined_answer = get_predefined_answer(question)
|
247 |
-
if predefined_answer != "Sorry, I don't have an answer for that. Please ask a different question.":
|
248 |
-
return predefined_answer
|
249 |
-
else:
|
250 |
-
# Fallback to model-based answer if question is not predefined
|
251 |
-
context = f"{college_about}\n\n{faculty_data}\n\n{facilities}"
|
252 |
-
response = qa_model(question=question, context=context)
|
253 |
-
return response['answer']
|
254 |
|
|
|
|
|
255 |
|
256 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
257 |
with gr.Blocks(theme=gr.themes.Monochrome()) as app:
|
258 |
gr.Markdown("## Government Boys Degree College Daulatpur")
|
259 |
-
gr.Markdown("### Welcome to our College Information
|
260 |
-
gr.Image("college_logo.png", label="College Logo") #
|
|
|
261 |
|
262 |
with gr.Tabs():
|
263 |
with gr.Tab("About College"):
|
264 |
gr.Markdown(college_about)
|
265 |
-
with gr.Tab("
|
266 |
-
gr.Markdown(
|
|
|
|
|
|
|
|
|
|
|
267 |
with gr.Tab("Facilities"):
|
268 |
-
gr.Markdown(
|
269 |
with gr.Tab("Ask a Question"):
|
270 |
-
question = gr.Textbox(label="Ask about the college")
|
271 |
answer = gr.Textbox(label="Answer")
|
272 |
-
question.submit(
|
273 |
-
with gr.Tab("Predefined Data"):
|
274 |
-
predefined_data = "\n".join([f"{q} - Category: {cat}, Name: {name}, Designation: {desig}, Details: {details}"
|
275 |
-
for q, cat, name, desig, details in zip(data["Questions"], data["Category"], data["Name"], data["Designation"], data["Subject/Details"])])
|
276 |
-
gr.Markdown(predefined_data)
|
277 |
with gr.Tab("Contact Us"):
|
278 |
-
|
279 |
-
gr.Markdown(
|
|
|
|
|
|
|
|
|
|
|
|
|
280 |
|
281 |
gr.Markdown("### Made by Musawir Manzoor")
|
282 |
|
283 |
-
# Step
|
284 |
app.launch()
|
285 |
-
|
|
|
1 |
# Step 2: Import libraries
|
2 |
import gradio as gr
|
|
|
3 |
|
4 |
# Step 3: Define College Data
|
5 |
college_about = """
|
|
|
9 |
With the help of the EDO Education, the possession of the Government Girls High School (Old) Daulatpur was given to the college.
|
10 |
"""
|
11 |
|
12 |
+
# Restructured Data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
data = {
|
14 |
+
"Programs": [
|
15 |
+
"ADSE-I", "ADSE-II", "ADAA-I", "ADAA-II", "BS (Zoology) (Proposed for this year)"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
],
|
17 |
+
"Teachers": {
|
18 |
+
"Islamiat": ["Prof Mahfooz Khan (Associate Prof)", "M. Essa Samego (Lecturer)"],
|
19 |
+
"Physics": ["Muhammad Aslam Palli (Associate Prof)", "Asif Ali Rajput (Lecturer)"],
|
20 |
+
"Botany": ["Abdul Rahman Gaincho (Lecturer)"],
|
21 |
+
"Chemistry": ["Ali Aijaz Dahri (Lecturer)"],
|
22 |
+
"Math": ["Fida Hussain (Lecturer)"],
|
23 |
+
"Librarian": ["Zulfiqar Ali (Senior Librarian)"],
|
24 |
+
"DPE": ["Naseer Ahmed (DPE)"],
|
25 |
+
},
|
26 |
+
"Facilities": [
|
27 |
+
"Digital library with 20+ computers",
|
28 |
+
"Parks: Alquran Park and Botany Park with 50+ plants",
|
29 |
+
"Building: Two-floor building with 24 rooms",
|
30 |
+
"Labs: Zoology, Botany, Physics, Chemistry",
|
31 |
+
"Parking area",
|
32 |
+
"Solar system",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
"RO Plant",
|
34 |
],
|
35 |
+
"Location": "Bypass Daulatpur",
|
36 |
+
"Principal": "Prof Irshad Ali Otho",
|
37 |
+
"Established": "2003",
|
38 |
+
"Contact": {
|
39 |
+
"Location": "National Highway N6 bypass Daulatpur",
|
40 |
+
"Phone": "+92 300 3003249",
|
41 |
+
"Email": "[email protected]",
|
42 |
+
"Facebook": "https://www.facebook.com/share/19j9Z1iEvz/"
|
43 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
}
|
45 |
|
46 |
+
# Helper function to answer questions
|
47 |
+
def get_answer(question):
|
48 |
+
# Convert question to lowercase for easier matching
|
49 |
+
question = question.lower()
|
50 |
|
51 |
+
# Check for general categories
|
52 |
+
if "program" in question or "course" in question:
|
53 |
+
return f"Programs offered:\n- " + "\n- ".join(data["Programs"])
|
54 |
|
55 |
+
if "teacher" in question:
|
56 |
+
if "islamiat" in question:
|
57 |
+
return f"Islamiat Teachers:\n- " + "\n- ".join(data["Teachers"]["Islamiat"])
|
58 |
+
elif "physics" in question:
|
59 |
+
return f"Physics Teachers:\n- " + "\n- ".join(data["Teachers"]["Physics"])
|
60 |
+
elif "botany" in question:
|
61 |
+
return f"Botany Teacher:\n- " + "\n- ".join(data["Teachers"]["Botany"])
|
62 |
+
elif "chemistry" in question:
|
63 |
+
return f"Chemistry Teacher:\n- " + "\n- ".join(data["Teachers"]["Chemistry"])
|
64 |
+
elif "math" in question:
|
65 |
+
return f"Math Teacher:\n- " + "\n- ".join(data["Teachers"]["Math"])
|
66 |
+
elif "librarian" in question:
|
67 |
+
return f"Librarian:\n- " + "\n- ".join(data["Teachers"]["Librarian"])
|
68 |
+
elif "dpe" in question:
|
69 |
+
return f"DPE:\n- " + "\n- ".join(data["Teachers"]["DPE"])
|
70 |
+
else:
|
71 |
+
# Return all teachers if no specific subject is mentioned
|
72 |
+
all_teachers = "\n".join(
|
73 |
+
[f"{subject}: " + ", ".join(teachers) for subject, teachers in data["Teachers"].items()]
|
74 |
+
)
|
75 |
+
return f"All Teachers:\n{all_teachers}"
|
76 |
|
77 |
+
if "facility" in question:
|
78 |
+
return f"Facilities available:\n- " + "\n- ".join(data["Facilities"])
|
|
|
|
|
|
|
|
|
79 |
|
80 |
+
if "location" in question:
|
81 |
+
return f"College Location: {data['Location']}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
+
if "principal" in question:
|
84 |
+
return f"Principal: {data['Principal']}"
|
85 |
|
86 |
+
if "establish" in question or "founded" in question:
|
87 |
+
return f"Established in: {data['Established']}"
|
88 |
+
|
89 |
+
if "contact" in question:
|
90 |
+
contact_info = data["Contact"]
|
91 |
+
return (
|
92 |
+
f"Contact Details:\n"
|
93 |
+
f"- Location: {contact_info['Location']}\n"
|
94 |
+
f"- Phone: {contact_info['Phone']}\n"
|
95 |
+
f"- Email: {contact_info['Email']}\n"
|
96 |
+
f"- Facebook: {contact_info['Facebook']}"
|
97 |
+
)
|
98 |
+
|
99 |
+
return "Sorry, I don't have an answer for that. Please ask something else."
|
100 |
+
|
101 |
+
|
102 |
+
# Step 4: Create Gradio Interface
|
103 |
with gr.Blocks(theme=gr.themes.Monochrome()) as app:
|
104 |
gr.Markdown("## Government Boys Degree College Daulatpur")
|
105 |
+
gr.Markdown("### Welcome to our College Information App")
|
106 |
+
gr.Image("college_logo.png", label="College Logo") # Ensure "college_logo.png" exists
|
107 |
+
|
108 |
|
109 |
with gr.Tabs():
|
110 |
with gr.Tab("About College"):
|
111 |
gr.Markdown(college_about)
|
112 |
+
with gr.Tab("Programs"):
|
113 |
+
gr.Markdown("\n".join(data["Programs"]))
|
114 |
+
with gr.Tab("Teachers"):
|
115 |
+
all_teachers = "\n".join(
|
116 |
+
[f"{subject}: " + ", ".join(teachers) for subject, teachers in data["Teachers"].items()]
|
117 |
+
)
|
118 |
+
gr.Markdown(all_teachers)
|
119 |
with gr.Tab("Facilities"):
|
120 |
+
gr.Markdown("\n".join(data["Facilities"]))
|
121 |
with gr.Tab("Ask a Question"):
|
122 |
+
question = gr.Textbox(label="Ask a question about the college")
|
123 |
answer = gr.Textbox(label="Answer")
|
124 |
+
question.submit(get_answer, inputs=question, outputs=answer)
|
|
|
|
|
|
|
|
|
125 |
with gr.Tab("Contact Us"):
|
126 |
+
contact_info = data["Contact"]
|
127 |
+
gr.Markdown(
|
128 |
+
f"**Contact Details:**\n"
|
129 |
+
f"- Location: {contact_info['Location']}\n"
|
130 |
+
f"- Phone: {contact_info['Phone']}\n"
|
131 |
+
f"- Email: {contact_info['Email']}\n"
|
132 |
+
f"[Visit our Facebook Page]({contact_info['Facebook']})"
|
133 |
+
)
|
134 |
|
135 |
gr.Markdown("### Made by Musawir Manzoor")
|
136 |
|
137 |
+
# Step 5: Launch the App
|
138 |
app.launch()
|
|