Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import pandas as pd | |
| # --- Branding & Info --- | |
| ORG_NAME = "Elimuhub Education Consultants" | |
| CONTACTS = """ | |
| π Tel: +254 731 838 387 | |
| π§ Email: elimuhubconsultant@gmail.com | |
| π Website: [elimuhub.simdif.com](https://elimuhub.simdif.com) | |
| """ | |
| # --- Tuition & Homeschooling Packages (DataFrame for display) --- | |
| fees_data = [ | |
| ["Homeschooling - Standard (3 days/wk, 2 hrs/day, 24 hrs)", "KES 12,000"], | |
| ["Homeschooling - Intensive (5 days/wk, 4 hrs/day, 80 hrs)", "KES 20,000"], | |
| ["Homeschooling - Comprehensive (7 days/wk, 6 hrs/day, 168 hrs)", "KES 30,000"], | |
| ["Individual Tutoring (Hourly, 1 subject)", "KES 1,500 β 3,000 / hr"], | |
| ["Group Classes (per student, per session)", "KES 800 β 1,500"], | |
| ["Monthly Tuition Packages (varies by subject & hours)", "KES 15,000 β 30,000"], | |
| ["Holiday Programmes (duration dependent)", "KES 12,000 β 30,000"], | |
| ] | |
| fees_df = pd.DataFrame(fees_data, columns=["Package / Service", "Price"]) | |
| # --- FAQ Responses --- | |
| FAQS = { | |
| "subjects": """π **Subjects Offered** | |
| - Maths, Sciences, Languages, Humanities | |
| - Primary, Junior Secondary, Senior Secondary | |
| - IGCSE, IB, American K-12, British National | |
| - Adult Education & catch-up tutoring | |
| """, | |
| "curriculum": """π **Curricula Covered** | |
| - Kenya: CBC, 8-4-4, KCPE, KCSE | |
| - International: IGCSE, IB, American K-12, British National Curriculum | |
| """, | |
| "homeschool": """π **Homeschooling Services** | |
| - Full-time or part-time homeschooling (structured 4-week packages) | |
| - Personalized schedules & materials included | |
| - Assessments & progress tracking | |
| - Parent guidance available | |
| """, | |
| "tutor": """π©βπ« **Tutor Services** | |
| - One-on-one tuition (home or online) | |
| - Group classes available | |
| - Hourly, weekly, or monthly plans | |
| - Free educational assessment included | |
| """, | |
| "location": """π **Service Locations** | |
| - In-home tutoring across all Nairobi estates | |
| - Online tutoring across Kenya | |
| - No registration/booking fee required | |
| """, | |
| "contact": f"""βοΈ **Contact Us**\n{CONTACTS}""" | |
| } | |
| # --- Chatbot Logic --- | |
| def chatbot(user_input): | |
| text = user_input.lower() | |
| if "fee" in text or "price" in text or "package" in text: | |
| return "Here are our tuition & homeschooling packages π (see the table below).", fees_df | |
| elif "subject" in text: | |
| return FAQS["subjects"], None | |
| elif "curriculum" in text or "syllabus" in text: | |
| return FAQS["curriculum"], None | |
| elif "homeschool" in text: | |
| return FAQS["homeschool"], None | |
| elif "tutor" in text or "teacher" in text: | |
| return FAQS["tutor"], None | |
| elif "location" in text or "where" in text: | |
| return FAQS["location"], None | |
| elif "contact" in text or "phone" in text or "email" in text or "website" in text: | |
| return FAQS["contact"], None | |
| elif "hello" in text or "hi" in text: | |
| return f"π Hello, welcome to {ORG_NAME}!\nAsk about *fees*, *subjects*, *curriculum*, *homeschooling*, or *contacts*.", None | |
| else: | |
| return "I can help with tuition, homeschooling, packages, and curricula. Try asking: 'What are your fees?' or use the quick menu below β¬οΈ", None | |
| # --- Gradio UI --- | |
| with gr.Blocks() as demo: | |
| gr.Markdown(f"## π€ Welcome to {ORG_NAME}\nAsk us about our tuition & homeschooling services!") | |
| chatbox = gr.Chatbot(label="Chat with Elimuhub") | |
| msg = gr.Textbox(placeholder="Type your question here...") | |
| fees_table = gr.DataFrame(value=pd.DataFrame([], columns=["Package / Service", "Price"]), | |
| label="Fee Packages", visible=False) | |
| with gr.Row(): | |
| gr.Markdown("### π Quick Menu") | |
| with gr.Row(): | |
| btn_fees = gr.Button("π° Fees & Packages") | |
| btn_subjects = gr.Button("π Subjects") | |
| btn_curriculum = gr.Button("π Curriculum") | |
| btn_homeschool = gr.Button("π Homeschooling") | |
| btn_tutors = gr.Button("π©βπ« Tutors") | |
| btn_location = gr.Button("π Locations") | |
| btn_contact = gr.Button("βοΈ Contact Info") | |
| # Handle text input | |
| def respond(message, history): | |
| response, table = chatbot(message) | |
| history.append((message, response)) | |
| if table is not None: | |
| return history, table, gr.update(visible=True) | |
| else: | |
| return history, pd.DataFrame([], columns=["Package / Service", "Price"]), gr.update(visible=False) | |
| msg.submit(respond, [msg, chatbox], [chatbox, fees_table, fees_table]) | |
| # Button actions (simulate user queries) | |
| btn_fees.click(lambda: respond("fees", []), outputs=[chatbox, fees_table, fees_table]) | |
| btn_subjects.click(lambda: respond("subjects", []), outputs=[chatbox, fees_table, fees_table]) | |
| btn_curriculum.click(lambda: respond("curriculum", []), outputs=[chatbox, fees_table, fees_table]) | |
| btn_homeschool.click(lambda: respond("homeschool", []), outputs=[chatbox, fees_table, fees_table]) | |
| btn_tutors.click(lambda: respond("tutor", []), outputs=[chatbox, fees_table, fees_table]) | |
| btn_location.click(lambda: respond("location", []), outputs=[chatbox, fees_table, fees_table]) | |
| btn_contact.click(lambda: respond("contact", []), outputs=[chatbox, fees_table, fees_table]) | |
| # Launch app | |
| if __name__ == "__main__": | |
| demo.launch() |