Wfafa commited on
Commit
fa9fe00
ยท
verified ยท
1 Parent(s): 5242ed2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -78
app.py CHANGED
@@ -43,7 +43,7 @@ memory = load_memory()
43
  # ----------------
44
  # Chat function
45
  # ----------------
46
- def chat_with_model(message, history, context, file_input=None):
47
  if not isinstance(history, list):
48
  history = []
49
 
@@ -55,9 +55,6 @@ def chat_with_model(message, history, context, file_input=None):
55
  save_memory(history)
56
  return history, history
57
 
58
- if file_input:
59
- message += f"\n\n๐Ÿ“Ž Uploaded file: {file_input.name}"
60
-
61
  conversation = [
62
  {"role": "system", "content": (
63
  "You are EduAI, a multilingual educational AI assistant created by a Sri Lankan student named Wafa Fazly. "
@@ -79,77 +76,4 @@ def chat_with_model(message, history, context, file_input=None):
79
  data = response.json()
80
  reply = data["choices"][0]["message"]["content"]
81
 
82
- reply = reply.replace("Step", "\n\n**Step").replace(":", ":**")
83
- history.append({"role": "user", "content": message})
84
- history.append({"role": "assistant", "content": reply})
85
- save_memory(history)
86
- return history, history
87
-
88
- except Exception as e:
89
- history.append({"role": "user", "content": message})
90
- history.append({"role": "assistant", "content": "๐Ÿ˜… EduAI is having trouble connecting."})
91
- return history, history
92
-
93
- # ----------------
94
- # Sidebar helpers
95
- # ----------------
96
- def update_context(choice):
97
- if not choice:
98
- return "๐Ÿ“˜ **General Mode.** Ask EduAI anything!"
99
- return f"๐Ÿ“˜ **{choice} mode selected.**"
100
-
101
- def clear_memory():
102
- if os.path.exists(MEMORY_FILE):
103
- os.remove(MEMORY_FILE)
104
- return [], "๐Ÿงน Chat memory cleared."
105
-
106
- # ----------------
107
- # Gradio UI
108
- # ----------------
109
- with gr.Blocks(theme=gr.themes.Soft(primary_hue="violet")) as iface:
110
- gr.Markdown("# ๐ŸŽ“ EduAI โ€” Professional Study Companion")
111
-
112
- with gr.Row():
113
- # Sidebar
114
- with gr.Column(scale=1, min_width=250):
115
- gr.Markdown("### ๐Ÿงญ Main Menu")
116
-
117
- with gr.Accordion("๐Ÿ“š Subject Tutor", open=False):
118
- subj = gr.Radio(["Science ๐Ÿงช", "ICT ๐Ÿ’ป", "English ๐Ÿ“˜", "Math โž—"], label="Subject")
119
-
120
- with gr.Accordion("๐Ÿ—“ Study Planner", open=False):
121
- planner = gr.Radio(["View Plan ๐Ÿ“…", "Add Task โœ๏ธ", "Study Tips ๐Ÿ’ก"], label="Planner")
122
-
123
- with gr.Accordion("๐ŸŒ Languages", open=False):
124
- lang = gr.Radio(["Sinhala ๐Ÿ‡ฑ๐Ÿ‡ฐ", "Tamil ๐Ÿ‡ฎ๐Ÿ‡ณ", "English ๐Ÿ‡ฌ๐Ÿ‡ง", "Spanish ๐Ÿ‡ช๐Ÿ‡ธ"], label="Language")
125
-
126
- with gr.Accordion("โš™๏ธ Settings", open=False):
127
- clear_btn = gr.Button("๐Ÿงน Clear Memory")
128
-
129
- # Chat area
130
- with gr.Column(scale=4):
131
- context_display = gr.Markdown("๐Ÿ“˜ **General Mode.** Ask EduAI anything!")
132
-
133
- chatbot = gr.Chatbot(
134
- label="EduAI Chat",
135
- height=450,
136
- type="messages",
137
- render_markdown=True,
138
- latex_delimiters=[{"left": "$$", "right": "$$", "display": True},
139
- {"left": "\\[", "right": "\\]", "display": True}]
140
- )
141
-
142
- with gr.Row():
143
- msg = gr.Textbox(placeholder="Type your question here...", show_label=False)
144
- file_input = gr.File(file_types=[".pdf", ".docx", ".png", ".jpg"], show_label=False)
145
- send_btn = gr.Button("โœˆ๏ธ")
146
-
147
- # Events
148
- subj.change(update_context, inputs=subj, outputs=context_display)
149
- planner.change(update_context, inputs=planner, outputs=context_display)
150
- lang.change(update_context, inputs=lang, outputs=context_display)
151
- send_btn.click(chat_with_model, inputs=[msg, chatbot, context_display, file_input], outputs=[chatbot, chatbot])
152
- msg.submit(chat_with_model, inputs=[msg, chatbot, context_display, file_input], outputs=[chatbot, chatbot])
153
- clear_btn.click(clear_memory, outputs=[chatbot, context_display])
154
-
155
- iface.launch()
 
43
  # ----------------
44
  # Chat function
45
  # ----------------
46
+ def chat_with_model(message, history, context):
47
  if not isinstance(history, list):
48
  history = []
49
 
 
55
  save_memory(history)
56
  return history, history
57
 
 
 
 
58
  conversation = [
59
  {"role": "system", "content": (
60
  "You are EduAI, a multilingual educational AI assistant created by a Sri Lankan student named Wafa Fazly. "
 
76
  data = response.json()
77
  reply = data["choices"][0]["message"]["content"]
78
 
79
+ reply = reply.replace("Step