Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -57,8 +57,7 @@ def chat_with_model(message, history, context):
|
|
| 57 |
"You help students learn subjects such as Math, Science, English, and IT. "
|
| 58 |
"EduAI runs on the model 'Qwen/Qwen3-VL-8B-Instruct', which was originally "
|
| 59 |
"trained by Alibaba. Always answer truthfully when asked about your creation."
|
| 60 |
-
)}]
|
| 61 |
-
|
| 62 |
|
| 63 |
for past_user, past_bot in history[-5:]:
|
| 64 |
conversation.append({"role": "user", "content": past_user})
|
|
@@ -113,6 +112,16 @@ def clear_memory():
|
|
| 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(
|
|
@@ -160,6 +169,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="violet")) as iface:
|
|
| 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,
|
|
@@ -170,21 +180,25 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="violet")) as iface:
|
|
| 170 |
{"left": "\\[", "right": "\\]", "display": True}
|
| 171 |
]
|
| 172 |
)
|
| 173 |
-
with gr.Row():
|
| 174 |
-
upload_file = gr.File(label="π", file_count="single", type="file")
|
| 175 |
-
msg = gr.Textbox(
|
| 176 |
-
label="π Type your question here...",
|
| 177 |
-
placeholder="Ask EduAI anything about your studies..."
|
| 178 |
-
)
|
| 179 |
-
send = gr.Button("β¨ Send")
|
| 180 |
-
pause_btn = gr.Button("βΈ Pause")
|
| 181 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
# πͺ Event handlers
|
| 184 |
subj.change(update_context, inputs=subj, outputs=context_display)
|
| 185 |
planner.change(update_context, inputs=planner, outputs=context_display)
|
| 186 |
lang.change(update_context, inputs=lang, outputs=context_display)
|
| 187 |
send.click(chat_with_model, inputs=[msg, chatbot, context_display], outputs=[chatbot, chatbot])
|
|
|
|
|
|
|
| 188 |
clear_btn.click(clear_memory, outputs=[chatbot, context_display])
|
| 189 |
|
| 190 |
iface.launch()
|
|
|
|
| 57 |
"You help students learn subjects such as Math, Science, English, and IT. "
|
| 58 |
"EduAI runs on the model 'Qwen/Qwen3-VL-8B-Instruct', which was originally "
|
| 59 |
"trained by Alibaba. Always answer truthfully when asked about your creation."
|
| 60 |
+
)}]
|
|
|
|
| 61 |
|
| 62 |
for past_user, past_bot in history[-5:]:
|
| 63 |
conversation.append({"role": "user", "content": past_user})
|
|
|
|
| 112 |
os.remove(MEMORY_FILE)
|
| 113 |
return [], "π§Ή Chat memory cleared! Start fresh."
|
| 114 |
|
| 115 |
+
# π Handle File Upload
|
| 116 |
+
def handle_file(file):
|
| 117 |
+
if file is None:
|
| 118 |
+
return []
|
| 119 |
+
return [(f"π File uploaded: {file.name}", "β
Received successfully!")]
|
| 120 |
+
|
| 121 |
+
# βΈ Pause Button
|
| 122 |
+
def pause_chat():
|
| 123 |
+
return [(None, "βΈοΈ Chat paused. Click 'Send' to continue.")]
|
| 124 |
+
|
| 125 |
# π¨ Gradio Interface (UI Improved)
|
| 126 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="violet")) as iface:
|
| 127 |
gr.Markdown(
|
|
|
|
| 169 |
|
| 170 |
with gr.Column(scale=4):
|
| 171 |
context_display = gr.Markdown("π **You are in General Mode.** Ask EduAI anything about your studies!")
|
| 172 |
+
|
| 173 |
chatbot = gr.Chatbot(
|
| 174 |
label="π¬ EduAI Chat Window",
|
| 175 |
height=450,
|
|
|
|
| 180 |
{"left": "\\[", "right": "\\]", "display": True}
|
| 181 |
]
|
| 182 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
|
| 184 |
+
# π --- Chat Input Section with Icons ---
|
| 185 |
+
with gr.Row():
|
| 186 |
+
upload_file = gr.File(label="π", file_count="single", type="file", scale=1)
|
| 187 |
+
msg = gr.Textbox(
|
| 188 |
+
placeholder="Ask EduAI anything about your studies...",
|
| 189 |
+
label="π Type your question here...",
|
| 190 |
+
scale=6
|
| 191 |
+
)
|
| 192 |
+
send = gr.Button("β¨", scale=1)
|
| 193 |
+
pause_btn = gr.Button("βΈ", scale=1)
|
| 194 |
|
| 195 |
# πͺ Event handlers
|
| 196 |
subj.change(update_context, inputs=subj, outputs=context_display)
|
| 197 |
planner.change(update_context, inputs=planner, outputs=context_display)
|
| 198 |
lang.change(update_context, inputs=lang, outputs=context_display)
|
| 199 |
send.click(chat_with_model, inputs=[msg, chatbot, context_display], outputs=[chatbot, chatbot])
|
| 200 |
+
upload_file.upload(handle_file, inputs=upload_file, outputs=chatbot)
|
| 201 |
+
pause_btn.click(pause_chat, outputs=chatbot)
|
| 202 |
clear_btn.click(clear_memory, outputs=[chatbot, context_display])
|
| 203 |
|
| 204 |
iface.launch()
|