Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ CONTACTS = """
|
|
| 9 |
π Website: [elimuhub.simdif.com](https://elimuhub.simdif.com)
|
| 10 |
"""
|
| 11 |
|
| 12 |
-
# --- Tuition & Homeschooling Packages (
|
| 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
|
| 63 |
-
|
| 64 |
-
# FAQs
|
| 65 |
elif "subject" in text:
|
| 66 |
-
return
|
| 67 |
elif "curriculum" in text or "syllabus" in text:
|
| 68 |
-
return
|
| 69 |
elif "homeschool" in text:
|
| 70 |
-
return
|
| 71 |
elif "tutor" in text or "teacher" in text:
|
| 72 |
-
return
|
| 73 |
elif "location" in text or "where" in text:
|
| 74 |
-
return
|
| 75 |
elif "contact" in text or "phone" in text or "email" in text or "website" in text:
|
| 76 |
-
return
|
| 77 |
-
|
| 78 |
-
# Greeting
|
| 79 |
elif "hello" in text or "hi" in text:
|
| 80 |
-
return
|
| 81 |
-
|
| 82 |
-
# Fallback
|
| 83 |
else:
|
| 84 |
-
return
|
| 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 |
-
|
| 91 |
-
|
| 92 |
-
|
| 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 |
-
#
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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__":
|