Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,7 +15,7 @@ def search_web(query):
|
|
| 15 |
return data["AbstractText"]
|
| 16 |
elif data.get("RelatedTopics"):
|
| 17 |
topics = [t.get("Text", "") for t in data["RelatedTopics"] if "Text" in t]
|
| 18 |
-
return " ".join(topics[:3])
|
| 19 |
else:
|
| 20 |
return "No useful information found."
|
| 21 |
except Exception as e:
|
|
@@ -89,7 +89,6 @@ def chat_with_model(message, history, context):
|
|
| 89 |
reply = reply.replace("\\[", "\n\n\\[")
|
| 90 |
reply = reply.replace("\\]", "\\]\n\n")
|
| 91 |
|
| 92 |
-
# β
Add Markdown + LaTeX support
|
| 93 |
if "\\" in reply or "log_" in reply or "^" in reply:
|
| 94 |
reply = f"{reply}"
|
| 95 |
|
|
@@ -114,9 +113,15 @@ def clear_memory():
|
|
| 114 |
os.remove(MEMORY_FILE)
|
| 115 |
return [], "π§Ή Chat memory cleared! Start fresh."
|
| 116 |
|
| 117 |
-
# π¨ Gradio Interface
|
| 118 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="violet")) as iface:
|
| 119 |
-
gr.Markdown(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
with gr.Row():
|
| 122 |
with gr.Column(scale=1, min_width=230):
|
|
@@ -144,22 +149,32 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="violet")) as iface:
|
|
| 144 |
clear_btn = gr.Button("π§Ή Clear Memory")
|
| 145 |
|
| 146 |
with gr.Accordion("π©βπ About", open=False):
|
| 147 |
-
gr.Markdown(
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
with gr.Column(scale=4):
|
| 154 |
context_display = gr.Markdown("π **You are in General Mode.** Ask EduAI anything about your studies!")
|
| 155 |
chatbot = gr.Chatbot(
|
| 156 |
-
label="EduAI Chat",
|
| 157 |
height=450,
|
| 158 |
render_markdown=True,
|
| 159 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
)
|
| 161 |
-
|
| 162 |
-
send = gr.Button("Send βοΈ")
|
| 163 |
|
| 164 |
# πͺ Event handlers
|
| 165 |
subj.change(update_context, inputs=subj, outputs=context_display)
|
|
|
|
| 15 |
return data["AbstractText"]
|
| 16 |
elif data.get("RelatedTopics"):
|
| 17 |
topics = [t.get("Text", "") for t in data["RelatedTopics"] if "Text" in t]
|
| 18 |
+
return " ".join(topics[:3])
|
| 19 |
else:
|
| 20 |
return "No useful information found."
|
| 21 |
except Exception as e:
|
|
|
|
| 89 |
reply = reply.replace("\\[", "\n\n\\[")
|
| 90 |
reply = reply.replace("\\]", "\\]\n\n")
|
| 91 |
|
|
|
|
| 92 |
if "\\" in reply or "log_" in reply or "^" in reply:
|
| 93 |
reply = f"{reply}"
|
| 94 |
|
|
|
|
| 113 |
os.remove(MEMORY_FILE)
|
| 114 |
return [], "π§Ή Chat memory cleared! Start fresh."
|
| 115 |
|
| 116 |
+
# π¨ Gradio Interface (UI Improved)
|
| 117 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="violet")) as iface:
|
| 118 |
+
gr.Markdown(
|
| 119 |
+
"""
|
| 120 |
+
# π **EduAI β Your Smart Study Companion**
|
| 121 |
+
Welcome to **EduAI**, your friendly study assistant! π¬
|
| 122 |
+
Get help in **Science, ICT, English, Mathematics**, and more.
|
| 123 |
+
"""
|
| 124 |
+
)
|
| 125 |
|
| 126 |
with gr.Row():
|
| 127 |
with gr.Column(scale=1, min_width=230):
|
|
|
|
| 149 |
clear_btn = gr.Button("π§Ή Clear Memory")
|
| 150 |
|
| 151 |
with gr.Accordion("π©βπ About", open=False):
|
| 152 |
+
gr.Markdown(
|
| 153 |
+
"""
|
| 154 |
+
EduAI was designed and fine-tuned by **Wafa Fazly**,
|
| 155 |
+
a passionate Sri Lankan student π©βπ»
|
| 156 |
+
to help learners explore **Science, ICT, English, and more** β
|
| 157 |
+
in a smart and friendly way! π
|
| 158 |
+
"""
|
| 159 |
+
)
|
| 160 |
|
| 161 |
with gr.Column(scale=4):
|
| 162 |
context_display = gr.Markdown("π **You are in General Mode.** Ask EduAI anything about your studies!")
|
| 163 |
chatbot = gr.Chatbot(
|
| 164 |
+
label="π¬ EduAI Chat Window",
|
| 165 |
height=450,
|
| 166 |
render_markdown=True,
|
| 167 |
+
bubble_full_width=False,
|
| 168 |
+
latex_delimiters=[
|
| 169 |
+
{"left": "$$", "right": "$$", "display": True},
|
| 170 |
+
{"left": "\\[", "right": "\\]", "display": True}
|
| 171 |
+
]
|
| 172 |
+
)
|
| 173 |
+
msg = gr.Textbox(
|
| 174 |
+
label="π Type your question here...",
|
| 175 |
+
placeholder="Ask EduAI anything about your studies..."
|
| 176 |
)
|
| 177 |
+
send = gr.Button("β¨ Send Message")
|
|
|
|
| 178 |
|
| 179 |
# πͺ Event handlers
|
| 180 |
subj.change(update_context, inputs=subj, outputs=context_display)
|