import gradio as gr import re from datetime import datetime import random # Chatbot knowledge base ELIMUHUB_KNOWLEDGE = { "greeting": { "patterns": ["hello", "hi", "hey", "good morning", "good afternoon", "good evening"], "responses": [ "Hello! Welcome to Elimuhub Education Consultants! š How can I assist you today?", "Hi there! Welcome to Elimuhub Education Consultants. How can I help with your educational needs?", "Greetings! Thank you for contacting Elimuhub Education Consultants." ] }, "homeschooling": { "patterns": ["homeschool", "home school", "home schooling", "homeschooling"], "responses": ["""**Our Homeschooling Services:** š We provide comprehensive support for families seeking an alternative education path: ⢠**Customized Learning Plans**: Tailored to your child's individual needs and academic goals ⢠**Flexible Scheduling**: Adapt to your family's busy schedule ⢠**Full-Time or Part-Time**: Options for complete education or supplementary support ⢠**Experienced Tutors**: Highly qualified educators in their fields ⢠**Exam Preparation**: KCPE, KCSE, IGCSE, and other national/international exams Would you like more specific information about any of these aspects?"""] }, "subjects": { "patterns": ["subjects", "courses", "what do you teach", "which subjects"], "responses": ["""**Subjects We Offer:** š **Primary & Secondary Level:** - Mathematics, Science (Biology, Chemistry, Physics) - English, Kiswahili, History, Geography - CRE, Business Studies, Agriculture, Computer Studies **International Curricula (IGCSE & IB):** - Mathematics, Sciences, English, Business Studies - Languages (French, German, Spanish, Italian, Chinese) - Humanities (History, Geography) **Other:** - Adult Education and Professional Training Which subject are you particularly interested in?"""] }, "curriculum": { "patterns": ["curriculum", "syllabus", "what curriculum", "which system"], "responses": ["""**Curricula We Teach:** š **Kenyan System:** - Competency-Based Curriculum (CBC) - 8-4-4 System (KCPE & KCSE) **International Systems:** - British National Curriculum (IGCSE & A-Levels) - International Baccalaureate (IB) - American K-12 Curriculum **Adult Education:** Support for lifelong learners and retake students Which curriculum are you interested in?"""] }, "fees": { "patterns": ["fees", "price", "cost", "how much", "payment", "packages"], "responses": ["""**Our Fee Structure:** š° *Fees are negotiable with flexible payment options (hourly, weekly, monthly)* **Tuition Packages:** - Personalized 1-on-1: KES 1,500 - 3,000/hour - Weekly Group: KES 800 - 1,500/session (max 10 students) - Monthly Plan: KES 15,000 - 30,000/month - Holiday Program: From KES 2,000/session - Online Classes: 20% discount on in-person rates **Homeschooling Packages:** - Full-Time: KES 30,000 - 50,000+/month - Part-Time: KES 700 - 900+/hour - Sibling discounts available We offer a **FREE 15-minute consultation** to discuss the best package!"""] }, "contact": { "patterns": ["contact", "whatsapp", "phone", "number", "reach", "talk to person", "consultation"], "responses": ["""**Contact Us:** š You can reach us on **WhatsApp: +254 731 838 387** We offer a **FREE 15-minute consultation** to help you find the best educational plan for your child! Feel free to ask any specific questions you may have about our services."""] }, "thanks": { "patterns": ["thank", "thanks", "appreciate"], "responses": ["You're welcome! š Let me know if you have any other questions about Elimuhub's services.", "Happy to help! Feel free to ask anything else about our educational programs."] }, "default": { "responses": [ "I'm here to help you with Elimuhub's educational services! You can ask me about:\n⢠Homeschooling\n⢠Subjects offered\n⢠Curriculum\n⢠Fees & packages\n⢠Contact information", "That's a great question! At Elimuhub, we specialize in personalized tuition and homeschooling. How can I assist you specifically?", "I'd be happy to help! You can ask me about our tuition services, homeschooling programs, subjects offered, or fee structures." ] } } def classify_intent(user_input): """Classify user intent based on input patterns""" user_input = user_input.lower().strip() for intent, data in ELIMUHUB_KNOWLEDGE.items(): if intent == "default": continue for pattern in data["patterns"]: if re.search(r'\b' + re.escape(pattern) + r'\b', user_input): return intent return "default" def get_chatbot_response(user_input, chat_history): """Generate appropriate response based on user input""" intent = classify_intent(user_input) responses = ELIMUHUB_KNOWLEDGE[intent]["responses"] # Select a random response from available options response = random.choice(responses) # Add timestamp and branding timestamp = datetime.now().strftime("%H:%M") branded_response = f"**Elimuhub Assistant** ({timestamp}): {response}" return branded_response def chat_interface(message, chat_history): """Main chat interface function""" chat_history = chat_history or [] if not message.strip(): return chat_history, "Please type a message to start chatting!" # Get bot response bot_response = get_chatbot_response(message, chat_history) # Update chat history chat_history.append((message, bot_response)) return chat_history, "" # Custom CSS for better styling custom_css = """ .gradio-container { font-family: 'Arial', sans-serif; max-width: 800px; margin: 0 auto; } .elimuhub-header { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); padding: 25px; border-radius: 15px; color: white; text-align: center; margin-bottom: 20px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); } .elimuhub-header h1 { margin: 0; font-size: 2.5em; } .elimuhub-header p { margin: 10px 0 0 0; font-size: 1.2em; } .chatbot { min-height: 400px; border: 2px solid #e0e0e0; border-radius: 10px; } .quick-questions { background: #f8f9fa; padding: 15px; border-radius: 10px; border-left: 4px solid #667eea; } """ # Create the Gradio interface with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo: with gr.Column(): # Header gr.HTML("""
Personalized Tuition & Homeschooling Services
"Helping students achieve their academic goals"
⢠"Tell me about homeschooling"
⢠"Which subjects do you offer?"
⢠"What curriculum do you teach?"
⢠"What are your fees and packages?"
⢠"How can I contact you?"