import gradio as gr from transformers import pipeline # Define the path to your image (update it with the correct path) image_path = "path_to_your_logo_image.jpg" # 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": "othoirshad@gmail.com", "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("

Government Boys Degree College Daulatpur

") 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: [manzoormusawir7@gmail.com](mailto:manzoormusawir7@gmail.com)") # Launch the app app.launch()