Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,64 +1,138 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
from huggingface_hub import InferenceClient
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
"""
|
5 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
-
"""
|
7 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
max_tokens,
|
15 |
-
temperature,
|
16 |
-
top_p,
|
17 |
-
):
|
18 |
-
messages = [{"role": "system", "content": system_message}]
|
19 |
|
20 |
-
for
|
21 |
-
|
22 |
-
|
23 |
-
if val[1]:
|
24 |
-
messages.append({"role": "assistant", "content": val[1]})
|
25 |
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
-
|
|
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
max_tokens=max_tokens,
|
33 |
-
stream=True,
|
34 |
-
temperature=temperature,
|
35 |
-
top_p=top_p,
|
36 |
-
):
|
37 |
-
token = message.choices[0].delta.content
|
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 |
-
|
|
|
1 |
+
# Step 2: Import libraries
|
2 |
import gradio as gr
|
|
|
3 |
|
4 |
+
# Step 3: Define College Data
|
5 |
+
college_about = """
|
6 |
+
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.
|
7 |
+
At the beginning, the college had no staff of its own, so it was borrowed from Government Degree College Sakrand.
|
8 |
+
The college started its classes in the afternoon at Government High School Daulatpur as it had no specific building.
|
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()
|