elimuhub commited on
Commit
104553e
Β·
verified Β·
1 Parent(s): 287702c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +119 -64
app.py CHANGED
@@ -1,70 +1,125 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
3
-
4
-
5
- def respond(
6
- message,
7
- history: list[dict[str, str]],
8
- system_message,
9
- max_tokens,
10
- temperature,
11
- top_p,
12
- hf_token: gr.OAuthToken,
13
- ):
14
- """
15
- For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
16
- """
17
- client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
18
-
19
- messages = [{"role": "system", "content": system_message}]
20
-
21
- messages.extend(history)
22
-
23
- messages.append({"role": "user", "content": message})
24
-
25
- response = ""
26
-
27
- for message in client.chat_completion(
28
- messages,
29
- max_tokens=max_tokens,
30
- stream=True,
31
- temperature=temperature,
32
- top_p=top_p,
33
- ):
34
- choices = message.choices
35
- token = ""
36
- if len(choices) and choices[0].delta.content:
37
- token = choices[0].delta.content
38
-
39
- response += token
40
- yield response
41
-
42
-
43
- """
44
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
45
- """
46
- chatbot = gr.ChatInterface(
47
- respond,
48
- type="messages",
49
- additional_inputs=[
50
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
51
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
52
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
53
- gr.Slider(
54
- minimum=0.1,
55
- maximum=1.0,
56
- value=0.95,
57
- step=0.05,
58
- label="Top-p (nucleus sampling)",
59
- ),
60
  ],
61
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
- with gr.Blocks() as demo:
64
- with gr.Sidebar():
65
- gr.LoginButton()
66
- chatbot.render()
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
  if __name__ == "__main__":
70
- demo.launch()
 
1
  import gradio as gr
2
+ import random
3
+
4
+ # Knowledge base with all Elimuhub information
5
+ services = {
6
+ "greeting": [
7
+ "Hello! Welcome to Elimuhub Education Consultants! πŸŽ“ How can I assist you today?",
8
+ "Hi there! Welcome to Elimuhub. Ask me about homeschooling, subjects, curriculum, or fees!",
9
+ "Greetings! Thank you for contacting Elimuhub Education Consultants."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  ],
11
+
12
+ "homeschooling": """**Our Homeschooling Services** πŸ“š
13
+
14
+ We provide comprehensive support for families seeking alternative education:
15
+
16
+ β€’ **Customized Learning Plans**: Tailored to your child's needs and goals
17
+ β€’ **Flexible Scheduling**: Adapts to your family's routine
18
+ β€’ **Full-Time or Part-Time**: Complete education or supplementary support
19
+ β€’ **Experienced Tutors**: Qualified educators in their fields
20
+ β€’ **Exam Preparation**: KCPE, KCSE, IGCSE preparation
21
+
22
+ *Would you like details about any specific aspect?*""",
23
+
24
+ "subjects": """**Subjects We Offer** πŸ“–
25
+
26
+ **Primary & Secondary Level:**
27
+ - Mathematics, Sciences (Biology, Chemistry, Physics)
28
+ - English, Kiswahili, History, Geography
29
+ - CRE, Business Studies, Agriculture, Computer Studies
30
+
31
+ **International Curricula (IGCSE & IB):**
32
+ - Mathematics, Sciences, English, Business Studies
33
+ - Languages (French, German, Spanish, Italian, Chinese)
34
+ - Humanities (History, Geography)
35
+
36
+ **Other:** Adult Education and Professional Training""",
37
+
38
+ "curriculum": """**Curricula We Teach** 🌍
39
+
40
+ **Kenyan System:**
41
+ - Competency-Based Curriculum (CBC)
42
+ - 8-4-4 System (KCPE & KCSE)
43
+
44
+ **International Systems:**
45
+ - British Curriculum (IGCSE & A-Levels)
46
+ - International Baccalaureate (IB)
47
+ - American K-12 Curriculum
48
 
49
+ **Adult Education:** Lifelong learning and retake support""",
 
 
 
50
 
51
+ "fees": """**Our Fee Structure** πŸ’°
52
+
53
+ *Fees are negotiable with flexible payment options*
54
+
55
+ **Tuition Packages:**
56
+ - 1-on-1: KES 1,500 - 3,000/hour
57
+ - Group: KES 800 - 1,500/session (max 10 students)
58
+ - Monthly: KES 15,000 - 30,000/month
59
+ - Holiday: From KES 2,000/session
60
+ - Online: 20% discount on in-person rates
61
+
62
+ **Homeschooling:**
63
+ - Full-Time: KES 30,000 - 50,000+/month
64
+ - Part-Time: KES 700 - 900+/hour
65
+ - Sibling discounts available
66
+
67
+ *Free 15-minute consultation available!*""",
68
+
69
+ "contact": """**Contact Elimuhub** πŸ“ž
70
+
71
+ **WhatsApp:** +254 731 838 387
72
+
73
+ We offer a **FREE 15-minute consultation** to discuss your educational needs!
74
+
75
+ *Best time to reach us: 8:00 AM - 6:00 PM daily*"""
76
+ }
77
+
78
+ def respond(message, history):
79
+ message_lower = message.lower()
80
+
81
+ # Greeting
82
+ if any(word in message_lower for word in ["hi", "hello", "hey", "good morning", "good afternoon"]):
83
+ return random.choice(services["greeting"])
84
+
85
+ # Homeschooling
86
+ elif any(word in message_lower for word in ["homeschool", "home school", "home schooling"]):
87
+ return services["homeschooling"]
88
+
89
+ # Subjects
90
+ elif any(word in message_lower for word in ["subject", "teach", "course", "what do you offer"]):
91
+ return services["subjects"]
92
+
93
+ # Curriculum
94
+ elif any(word in message_lower for word in ["curriculum", "syllabus", "system", "what curriculum"]):
95
+ return services["curriculum"]
96
+
97
+ # Pricing
98
+ elif any(word in message_lower for word in ["price", "fee", "cost", "how much", "payment"]):
99
+ return services["fees"]
100
+
101
+ # Contact
102
+ elif any(word in message_lower for word in ["contact", "whatsapp", "phone", "number", "talk", "consultation"]):
103
+ return services["contact"]
104
+
105
+ # Default response
106
+ else:
107
+ return "I'm here to help with Elimuhub's educational services! You can ask me about:\n\nβ€’ Homeschooling programs\nβ€’ Subjects we teach\nβ€’ Curriculum information\nβ€’ Fee structures\nβ€’ Contact details\n\nWhat would you like to know?"
108
+
109
+ # Create the chatbot interface
110
+ demo = gr.ChatInterface(
111
+ respond,
112
+ title="πŸŽ“ Elimuhub Education Consultants",
113
+ description="Ask about our personalized tuition & homeschooling services!",
114
+ examples=[
115
+ ["Tell me about homeschooling"],
116
+ ["Which subjects do you offer?"],
117
+ ["What curriculum do you teach?"],
118
+ ["What are your fees?"],
119
+ ["How can I contact you?"]
120
+ ],
121
+ theme="soft"
122
+ )
123
 
124
  if __name__ == "__main__":
125
+ demo.launch()