elimuhub commited on
Commit
9618ff9
Β·
verified Β·
1 Parent(s): 689d7b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +113 -53
app.py CHANGED
@@ -1,66 +1,126 @@
1
- # app.py
2
  import gradio as gr
3
 
4
- SUBJECTS = ["Mathematics", "English", "Kiswahili", "Physics", "Chemistry", "Biology", "Islamic Studies"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- WELCOME_MD = """
7
- # Elimuhub Tutor 🀝
8
- **Elimuhub Education Consultants** β€” Quick demo tutor (mobile friendly).
9
- Contact: +254 731-838-387β€’ elimuhubconsultant@gmail.com
10
 
11
- Type your question below or try quick commands:
12
- - Say "generate quiz: subject, level, n" e.g., `generate quiz: math, KCSE, 3`
13
- - Ask: "How do I solve quadratic equations?"
 
14
  """
15
 
16
- def generate_quiz(subject="General", level="Any", n=3):
17
- qlist = []
18
- for i in range(1, n+1):
19
- qlist.append(f"{i}. Sample {level} {subject} question #{i}?")
20
- return "\n".join(qlist)
21
-
22
- def respond(user_message, history):
23
- if history is None:
24
- history = []
25
- msg = (user_message or "").strip()
26
- if not msg:
27
- return history, ""
28
- low = msg.lower()
29
-
30
- if any(greet in low for greet in ["hi", "hello", "hey", "salaam", "assalamu"]):
31
- bot = "Hello! πŸ‘‹ I'm Elimuhub's demo tutor. Tell me the subject and topic (e.g., 'math algebra')."
32
- elif low.startswith("generate quiz:"):
33
- try:
34
- rest = low.split("generate quiz:",1)[1].strip()
35
- parts = [p.strip() for p in rest.split(",")]
36
- subj = parts[0].title() if len(parts) > 0 and parts[0] else "General"
37
- level = parts[1].upper() if len(parts) > 1 and parts[1] else "Any"
38
- num = int(parts[2]) if len(parts) > 2 and parts[2].isdigit() else 3
39
- except Exception:
40
- subj, level, num = "General", "Any", 3
41
- bot = generate_quiz(subj, level, num)
42
- elif any(s.lower() in low for s in SUBJECTS):
43
- bot = ("Great β€” you asked about a subject I recognize. "
44
- "Please give the specific topic (e.g., algebra, verb tenses), and I'll give step-by-step help.")
45
- elif "kcse" in low or "kcpe" in low or "igcse" in low or "ib" in low:
46
- bot = "I can give exam-style tips and sample questions. Tell me the subject and the topic."
47
- else:
48
- # simple demo answer: echo plus tips
49
- bot = ("Thanks β€” here's a quick answer guide:\n\n"
50
- f"> You asked: {user_message}\n\n"
51
- "I'm a demo assistant. For clearer help, say the subject and topic (e.g., 'math: quadratic formula').")
52
 
53
- history.append((user_message, bot))
54
- return history, ""
 
 
 
 
 
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  with gr.Blocks() as demo:
57
- gr.Markdown(WELCOME_MD)
58
- chatbot = gr.Chatbot(elem_id="chatbot", label="Elimuhub Tutor")
59
  with gr.Row():
60
- txt = gr.Textbox(show_label=False, placeholder="Type your question here and press Enter...")
61
- send = gr.Button("Send")
62
- send.click(respond, inputs=[txt, chatbot], outputs=[chatbot, txt])
63
- txt.submit(respond, inputs=[txt, chatbot], outputs=[chatbot, txt])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
 
65
  if __name__ == "__main__":
66
  demo.launch()
 
 
1
  import gradio as gr
2
 
3
+ # --- Elimuhub Branding & Info ---
4
+ ORG_NAME = "Elimuhub Education Consultants"
5
+ LOGO_URL = "https://i.imgur.com/aoK6jCgundefined.png"
6
+ CONTACTS = """
7
+ πŸ“ž Tel: +254 731 838 387
8
+ πŸ“§ Email: elimuhubconsultant@gmail.com
9
+ 🌐 Website: [elimuhub.simdif.com](https://elimuhub.simdif.com)
10
+ """
11
+
12
+ # --- Tuition & Homeschooling Packages ---
13
+ FEES = """
14
+ ### πŸ“š Elimuhub Tuition & Homeschooling Fees
15
+
16
+ **Homeschooling Packages (4-week programmes)**
17
+ - Standard (3 days/week, 2 hrs/day, 24 hrs total): **KES 12,000**
18
+ - Intensive (5 days/week, 4 hrs/day, 80 hrs total): **KES 20,000**
19
+ - Comprehensive (7 days/week, 6 hrs/day, 168 hrs total): **KES 30,000**
20
+
21
+ **Individual Tutoring (Hourly)**
22
+ - One-on-one tutor, per subject: **KES 1,500 – 3,000 / hour**
23
+
24
+ **Group Classes**
25
+ - Per student, per session: **KES 800 – 1,500**
26
 
27
+ **Monthly Packages (Tuition)**
28
+ - Range: **KES 15,000 – 30,000** depending on subjects & hours
 
 
29
 
30
+ **Holiday Programmes**
31
+ - Duration dependent: **KES 12,000 – 30,000**
32
+
33
+ ---
34
  """
35
 
36
+ # --- FAQ Responses ---
37
+ FAQS = {
38
+ "subjects": """We offer **all subjects** across major levels:
39
+ - Primary & Secondary (CBC, 8-4-4, KCPE, KCSE)
40
+ - International Curricula (IGCSE, IB, American K-12, British National)
41
+ - Adult Education & catch-up tutoring
42
+ """,
43
+ "curriculum": """We cover the following curricula:
44
+ - **Kenya**: CBC, 8-4-4, KCPE, KCSE
45
+ - **International**: IGCSE, IB, American K-12, British National Curriculum
46
+ """,
47
+ "homeschool": """Homeschooling services include:
48
+ - Full-time or part-time homeschooling (structured 4-week packages)
49
+ - Personalized schedules
50
+ - All subjects from Kindergarten to High School
51
+ - Materials & assessments included
52
+ """,
53
+ "tutor": """Tutors are available:
54
+ - One-on-one private tuition (home or online)
55
+ - Group classes
56
+ - Flexible hourly, weekly, or monthly rates
57
+ - Free educational assessment before placement
58
+ """,
59
+ "location": """We provide **in-home and online tutoring** across all Nairobi estates and other towns in Kenya.
60
+ No registration fees. Tutors come to you or teach online.
61
+ """
62
+ }
63
+
64
+ # --- Chatbot Logic ---
65
+ def chatbot(user_input):
66
+ text = user_input.lower()
 
 
 
 
 
67
 
68
+ # Fees/packages
69
+ if "fee" in text or "price" in text or "package" in text:
70
+ return FEES + "\nWould you like me to recommend the right package?"
71
+
72
+ # Contact info
73
+ elif "contact" in text or "phone" in text or "email" in text or "website" in text:
74
+ return f"Here are our contacts:\n{CONTACTS}"
75
 
76
+ # FAQs
77
+ elif "subject" in text:
78
+ return FAQS["subjects"]
79
+ elif "curriculum" in text or "syllabus" in text:
80
+ return FAQS["curriculum"]
81
+ elif "homeschool" in text:
82
+ return FAQS["homeschool"]
83
+ elif "tutor" in text or "teacher" in text:
84
+ return FAQS["tutor"]
85
+ elif "location" in text or "where" in text:
86
+ return FAQS["location"]
87
+
88
+ # Greeting
89
+ elif "hello" in text or "hi" in text:
90
+ return f"Hello πŸ‘‹, welcome to {ORG_NAME}! How can we help you today?\n\nYou can ask about *fees*, *subjects*, *curriculum*, *homeschooling*, or *contacts*."
91
+
92
+ # Fallback
93
+ else:
94
+ return "I can help with tuition, homeschooling, packages, and curricula. Try asking: 'What are your fees?' or click a menu button below ⬇️"
95
+
96
+ # --- Gradio UI with Menu Buttons ---
97
  with gr.Blocks() as demo:
 
 
98
  with gr.Row():
99
+ gr.Image(value=LOGO_URL, elem_id="logo", show_label=False, height=100)
100
+ gr.Markdown(f"## 🀝 Welcome to {ORG_NAME}\nAsk us about our tuition & homeschooling services!")
101
+
102
+ chatbot_ui = gr.ChatInterface(fn=chatbot)
103
+
104
+ with gr.Row():
105
+ gr.Markdown("### πŸ“Œ Quick Menu")
106
+ with gr.Row():
107
+ btn_fees = gr.Button("πŸ’° Fees & Packages")
108
+ btn_subjects = gr.Button("πŸ“š Subjects")
109
+ btn_curriculum = gr.Button("πŸ“– Curriculum")
110
+ btn_homeschool = gr.Button("🏠 Homeschooling")
111
+ btn_tutors = gr.Button("πŸ‘©β€πŸ« Tutors")
112
+ btn_location = gr.Button("πŸ“ Locations")
113
+ btn_contact = gr.Button("☎️ Contact Info")
114
+
115
+ # Button actions send text to chatbot
116
+ btn_fees.click(fn=chatbot, inputs=gr.Textbox(value="fees", visible=False), outputs=chatbot_ui)
117
+ btn_subjects.click(fn=chatbot, inputs=gr.Textbox(value="subjects", visible=False), outputs=chatbot_ui)
118
+ btn_curriculum.click(fn=chatbot, inputs=gr.Textbox(value="curriculum", visible=False), outputs=chatbot_ui)
119
+ btn_homeschool.click(fn=chatbot, inputs=gr.Textbox(value="homeschool", visible=False), outputs=chatbot_ui)
120
+ btn_tutors.click(fn=chatbot, inputs=gr.Textbox(value="tutor", visible=False), outputs=chatbot_ui)
121
+ btn_location.click(fn=chatbot, inputs=gr.Textbox(value="location", visible=False), outputs=chatbot_ui)
122
+ btn_contact.click(fn=chatbot, inputs=gr.Textbox(value="contact", visible=False), outputs=chatbot_ui)
123
 
124
+ # Launch app
125
  if __name__ == "__main__":
126
  demo.launch()