College_app / app.py
Musawir19's picture
Update app.py
1cec144 verified
raw
history blame
8.17 kB
# Step 2: Import libraries
import gradio as gr
from transformers import pipeline
# Step 3: Define College Data
college_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.
"""
faculty_data = """
1. Prof Mahfooz Khan (Associate Prof, Islamiat)
2. Muhammad Aslam Palli (Associate Prof, Physics)
3. Abdul Rahman Gaincho (Botany)
4. M. Essa Samego (Lecturer, Islamiat)
5. Ali Aijaz Dahri (Lecturer, Chemistry)
6. Asif Ali Rajput (Lecturer, Physics)
7. Fida Hussain (Lecturer, Math)
8. Zulfiqar Ali (Senior Librarian)
"""
facilities = """
Facilities available:
1. Digital library with 20+ computers
2. Parks: Alquran Park and Botany Park with 50+ plants
3. Labs: Zoology, Botany, Physics, Chemistry
4. Parking area
5. Solar system and RO Plant
"""
# Step 4: Define College Dataset (from your data dictionary)
# Define the dataset
data = {
"Questions": [
"tell me name of college?",
"tell me establish of college?",
"who is principal of college?",
"what a programs in college?",
"what a programs in college?",
"what a programs in college?",
"what a programs in college?",
"what a programs in college?",
"where is located?",
"islamiat teacher?",
"physics teacher?",
"botany teacher?",
"islamiat teacher?",
"chemistry teacher?",
"physics teacher?",
"math teacher?",
"who is librarian",
"who is DPE",
"lab assistant?",
"clerk?",
"clerk?",
"clerk?",
"lab assistant?",
"lab assistant?",
"lab assistant?",
"who is sanitary worker?",
"facilities?",
"facilities?",
"facilities?",
"facilities?",
"facilities?",
"facilities?",
"facilities?",
"facilities?",
"facilities?",
"facilities?",
"facilities?",
],
"Category": [
"College Name",
"Established",
"Principal",
"Programs",
"Programs",
"Programs",
"Programs",
"Programs",
"Location",
"Teaching Staff",
"Teaching Staff",
"Teaching Staff",
"Teaching Staff",
"Teaching Staff",
"Teaching Staff",
"Teaching Staff",
"Teaching Staff",
"Teaching Staff",
"Non-Teaching Staff",
"Non-Teaching Staff",
"Non-Teaching Staff",
"Non-Teaching Staff",
"Non-Teaching Staff",
"Non-Teaching Staff",
"Non-Teaching Staff",
"Non-Teaching Staff",
"Facilities",
"Facilities",
"Facilities",
"Facilities",
"Facilities",
"Facilities",
"Facilities",
"Facilities",
"Facilities",
"Facilities",
"Facilities",
],
"Name": [
"Government Boys Degree College Daulatpur",
"2003",
"Prof Irshad Ali Otho",
"ADSE-I",
"ADSE-II",
"ADAA-",
"ADAA",
"(Zoology),Proposed this year,",
"Bypass Daulatpur",
"Prof Mahfooz Khan",
"Muhammad Aslam Palli",
"Abdul Rahman Gaincho",
"M. Essa Samego",
"Ali Aijaz Dahri",
"Asif Ali Rajput",
"Fida Hussain",
"Zulfiqar Ali",
"Naseer Ahmed",
"Mr Abear Lund",
"Mr Younis Unar",
"Mr Muhammad Bughio",
"Mr Dadan Khan,",
"Mr Rahib Ali Unar",
"Mr M Saleem Unar",
"Mr Shahbaz Khan",
"Mr Peruaz Ali",
"Digital Library",
"Parks",
"Building",
"Zoology Lab",
"Botany Lab",
"Physics Lab",
"Chemistry Lab",
"Parking Area",
"Solar System",
"RO Plant",
],
"Designation": [
"NA",
"NA",
"NA",
"NA",
"NA",
"NA",
"NA",
"NA",
"NA",
"Associate Professor",
"Associate Professor",
"Lecturer",
"Lecturer",
"Lecturer",
"Lecturer",
"Lecturer",
"Senior Librarian",
"DPE",
"Assistant",
"Senior Clerk",
"Senior Clerk",
"Junior Clerk",
"Lab Assistant",
"Lab Attendant",
"Lab Attendant",
"Sanitary Worker",
"NA",
"NA",
"NA",
"NA",
"NA",
"NA",
"NA",
"NA",
"NA",
"NA",
],
"Subject/Details": [
"NA",
"NA",
"NA",
"NA",
"NA",
"NA",
"NA",
"NA",
"NA",
"Islamiat",
"Physics",
"Botany",
"Islamiat",
"Chemistry",
"Physics",
"Math",
"NA",
"NA",
"NA",
"NA",
"NA",
"NA",
"NA",
"NA",
"NA",
"NA",
"20+ Computers",
"Alquran Park and Botany Park with 50+ plats",
"Two-floor building with 24 rooms",
"Available",
"Available",
"Available",
"Available",
"Available",
"Available",
"Available",
],
}
# Print the data (optional)
#print(data)
# Step 5: Define a Question-Answering Model (Hugging Face)
qa_model = pipeline("question-answering", model="deepset/roberta-base-squad2")
# Helper function for answering dataset questions
def get_predefined_answer(question):
for q, ans in zip(data["Questions"], data["Answers"]):
if question.lower() in q.lower():
return ans
return "Sorry, I don't have an answer for that. Please ask a different question."
# Define answer query function with dataset context
def answer_query(question):
predefined_answer = get_predefined_answer(question)
if predefined_answer != "Sorry, I don't have an answer for that. Please ask a different question.":
return predefined_answer
else:
# Fallback to model-based answer if question is not predefined
context = f"{college_about}\n\n{faculty_data}\n\n{facilities}"
response = qa_model(question=question, context=context)
return response['answer']
# Step 6: Create Gradio Interface
with gr.Blocks(theme=gr.themes.Monochrome()) as app:
gr.Markdown("## Government Boys Degree College Daulatpur")
gr.Markdown("### Welcome to our College Information RAG App")
gr.Image("college_logo.png", label="College Logo") # Upload your logo as college_logo.png
with gr.Tabs():
with gr.Tab("About College"):
gr.Markdown(college_about)
with gr.Tab("Faculty and Staff"):
gr.Markdown(faculty_data)
with gr.Tab("Facilities"):
gr.Markdown(facilities)
with gr.Tab("Ask a Question"):
question = gr.Textbox(label="Ask about the college")
answer = gr.Textbox(label="Answer")
question.submit(answer_query, inputs=question, outputs=answer)
with gr.Tab("Predefined Data"):
predefined_data = "\n".join([f"{q} - Category: {cat}, Name: {name}, Designation: {desig}, Details: {details}"
for q, cat, name, desig, details in zip(data["Questions"], data["Category"], data["Name"], data["Designation"], data["Subject/Details"])])
gr.Markdown(predefined_data)
with gr.Tab("Contact Us"):
gr.Markdown("**Contact Details:**\n- Location: National Highway N6 bypass Daulatpur\n- Phone: +92 300 3003249\n- Email: [email protected]")
gr.Markdown("[Visit our Facebook Page](https://www.facebook.com/share/19j9Z1iEvz/)")
gr.Markdown("### Made by Musawir Manzoor")
# Step 7: Launch the App
app.launch()