elimuhub commited on
Commit
1418428
Β·
verified Β·
1 Parent(s): e3f5ac5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -29
app.py CHANGED
@@ -9,7 +9,7 @@ CONTACTS = """
9
  🌐 Website: [elimuhub.simdif.com](https://elimuhub.simdif.com)
10
  """
11
 
12
- # --- Tuition & Homeschooling Packages (as DataFrame for table display) ---
13
  fees_data = [
14
  ["Homeschooling - Standard (3 days/wk, 2 hrs/day, 24 hrs)", "KES 12,000"],
15
  ["Homeschooling - Intensive (5 days/wk, 4 hrs/day, 80 hrs)", "KES 20,000"],
@@ -57,40 +57,34 @@ FAQS = {
57
  def chatbot(user_input):
58
  text = user_input.lower()
59
 
60
- # Fees (return table separately)
61
  if "fee" in text or "price" in text or "package" in text:
62
- return ("Here are our tuition & homeschooling packages:", fees_df)
63
-
64
- # FAQs
65
  elif "subject" in text:
66
- return (FAQS["subjects"], None)
67
  elif "curriculum" in text or "syllabus" in text:
68
- return (FAQS["curriculum"], None)
69
  elif "homeschool" in text:
70
- return (FAQS["homeschool"], None)
71
  elif "tutor" in text or "teacher" in text:
72
- return (FAQS["tutor"], None)
73
  elif "location" in text or "where" in text:
74
- return (FAQS["location"], None)
75
  elif "contact" in text or "phone" in text or "email" in text or "website" in text:
76
- return (FAQS["contact"], None)
77
-
78
- # Greeting
79
  elif "hello" in text or "hi" in text:
80
- return (f"πŸ‘‹ Hello, welcome to {ORG_NAME}!\nAsk about *fees*, *subjects*, *curriculum*, *homeschooling*, or *contacts*.", None)
81
-
82
- # Fallback
83
  else:
84
- return ("I can help with tuition, homeschooling, packages, and curricula. Try asking: 'What are your fees?' or use the quick menu below ⬇️", None)
85
 
86
  # --- Gradio UI ---
87
  with gr.Blocks() as demo:
88
  gr.Markdown(f"## 🀝 Welcome to {ORG_NAME}\nAsk us about our tuition & homeschooling services!")
89
 
90
- chatbot_ui = gr.ChatInterface(
91
- fn=chatbot,
92
- additional_outputs=[gr.DataFrame(label="Fee Packages", visible=True)]
93
- )
 
94
 
95
  with gr.Row():
96
  gr.Markdown("### πŸ“Œ Quick Menu")
@@ -103,14 +97,25 @@ with gr.Blocks() as demo:
103
  btn_location = gr.Button("πŸ“ Locations")
104
  btn_contact = gr.Button("☎️ Contact Info")
105
 
106
- # Button actions
107
- btn_fees.click(lambda: chatbot("fees"), outputs=[chatbot_ui, chatbot_ui.additional_outputs[0]])
108
- btn_subjects.click(lambda: chatbot("subjects"), outputs=[chatbot_ui, chatbot_ui.additional_outputs[0]])
109
- btn_curriculum.click(lambda: chatbot("curriculum"), outputs=[chatbot_ui, chatbot_ui.additional_outputs[0]])
110
- btn_homeschool.click(lambda: chatbot("homeschool"), outputs=[chatbot_ui, chatbot_ui.additional_outputs[0]])
111
- btn_tutors.click(lambda: chatbot("tutor"), outputs=[chatbot_ui, chatbot_ui.additional_outputs[0]])
112
- btn_location.click(lambda: chatbot("location"), outputs=[chatbot_ui, chatbot_ui.additional_outputs[0]])
113
- btn_contact.click(lambda: chatbot("contact"), outputs=[chatbot_ui, chatbot_ui.additional_outputs[0]])
 
 
 
 
 
 
 
 
 
 
 
114
 
115
  # Launch app
116
  if __name__ == "__main__":
 
9
  🌐 Website: [elimuhub.simdif.com](https://elimuhub.simdif.com)
10
  """
11
 
12
+ # --- Tuition & Homeschooling Packages (DataFrame for display) ---
13
  fees_data = [
14
  ["Homeschooling - Standard (3 days/wk, 2 hrs/day, 24 hrs)", "KES 12,000"],
15
  ["Homeschooling - Intensive (5 days/wk, 4 hrs/day, 80 hrs)", "KES 20,000"],
 
57
  def chatbot(user_input):
58
  text = user_input.lower()
59
 
 
60
  if "fee" in text or "price" in text or "package" in text:
61
+ return "Here are our tuition & homeschooling packages πŸ‘‡ (see the table below).", fees_df
 
 
62
  elif "subject" in text:
63
+ return FAQS["subjects"], None
64
  elif "curriculum" in text or "syllabus" in text:
65
+ return FAQS["curriculum"], None
66
  elif "homeschool" in text:
67
+ return FAQS["homeschool"], None
68
  elif "tutor" in text or "teacher" in text:
69
+ return FAQS["tutor"], None
70
  elif "location" in text or "where" in text:
71
+ return FAQS["location"], None
72
  elif "contact" in text or "phone" in text or "email" in text or "website" in text:
73
+ return FAQS["contact"], None
 
 
74
  elif "hello" in text or "hi" in text:
75
+ return f"πŸ‘‹ Hello, welcome to {ORG_NAME}!\nAsk about *fees*, *subjects*, *curriculum*, *homeschooling*, or *contacts*.", None
 
 
76
  else:
77
+ return "I can help with tuition, homeschooling, packages, and curricula. Try asking: 'What are your fees?' or use the quick menu below ⬇️", None
78
 
79
  # --- Gradio UI ---
80
  with gr.Blocks() as demo:
81
  gr.Markdown(f"## 🀝 Welcome to {ORG_NAME}\nAsk us about our tuition & homeschooling services!")
82
 
83
+ chatbox = gr.Chatbot(label="Chat with Elimuhub")
84
+ msg = gr.Textbox(placeholder="Type your question here...")
85
+
86
+ fees_table = gr.DataFrame(value=pd.DataFrame([], columns=["Package / Service", "Price"]),
87
+ label="Fee Packages", visible=False)
88
 
89
  with gr.Row():
90
  gr.Markdown("### πŸ“Œ Quick Menu")
 
97
  btn_location = gr.Button("πŸ“ Locations")
98
  btn_contact = gr.Button("☎️ Contact Info")
99
 
100
+ # Handle text input
101
+ def respond(message, history):
102
+ response, table = chatbot(message)
103
+ history.append((message, response))
104
+ if table is not None:
105
+ return history, table, gr.update(visible=True)
106
+ else:
107
+ return history, pd.DataFrame([], columns=["Package / Service", "Price"]), gr.update(visible=False)
108
+
109
+ msg.submit(respond, [msg, chatbox], [chatbox, fees_table, fees_table])
110
+
111
+ # Button actions (simulate user queries)
112
+ btn_fees.click(lambda: respond("fees", []), outputs=[chatbox, fees_table, fees_table])
113
+ btn_subjects.click(lambda: respond("subjects", []), outputs=[chatbox, fees_table, fees_table])
114
+ btn_curriculum.click(lambda: respond("curriculum", []), outputs=[chatbox, fees_table, fees_table])
115
+ btn_homeschool.click(lambda: respond("homeschool", []), outputs=[chatbox, fees_table, fees_table])
116
+ btn_tutors.click(lambda: respond("tutor", []), outputs=[chatbox, fees_table, fees_table])
117
+ btn_location.click(lambda: respond("location", []), outputs=[chatbox, fees_table, fees_table])
118
+ btn_contact.click(lambda: respond("contact", []), outputs=[chatbox, fees_table, fees_table])
119
 
120
  # Launch app
121
  if __name__ == "__main__":