jdesiree commited on
Commit
541dda9
ยท
verified ยท
1 Parent(s): 29ce07f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +141 -59
app.py CHANGED
@@ -165,69 +165,151 @@ def respond_with_enhanced_streaming(
165
  logger.exception("Error in LangChain response generation")
166
  yield f"Sorry, I encountered an error: {str(e)[:150]}"
167
 
168
- # Create enhanced Gradio interface
169
- demo = gr.ChatInterface(
170
- respond_with_enhanced_streaming,
171
- title="๐ŸŽ“ EduBot | AI Learning Assistant",
172
- description="""
173
- **Your comprehensive AI tutor powered by LangChain!**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
174
 
175
- ๐Ÿ”ง **Technical Features:**
176
- โ€ข Dynamic prompt templates based on question type
177
- โ€ข LangChain chain composition with `|` operator
178
- โ€ข Smart response truncation at sentence boundaries
179
- โ€ข Enhanced error handling and logging
 
180
 
181
- ๐Ÿ“š **Educational Modes:**
182
- โ€ข ๐Ÿงฎ **Math Mode** - Step-by-step problem solving with detailed explanations
183
- โ€ข ๐Ÿ” **Research Mode** - Source finding, evaluation, and citation guidance
184
- โ€ข ๐Ÿ“š **Study Mode** - Learning strategies and exam preparation techniques
185
- โ€ข ๐ŸŽ“ **General Mode** - Comprehensive educational support
 
 
 
 
 
 
186
 
187
- ๐Ÿ’ก **Tip:** Try asking detailed questions for thorough explanations!
188
- """,
189
- examples=[
190
- ["Solve the quadratic equation xยฒ + 5x + 6 = 0 with complete step-by-step explanations"],
191
- ["How do I conduct a comprehensive literature review for my psychology research paper?"],
192
- ["Create a detailed study schedule for my calculus and chemistry final exams"],
193
- ["Explain derivatives in calculus with real-world applications and examples"],
194
- ["How do I properly format citations in APA style with detailed guidelines?"]
195
- ],
196
- additional_inputs=[
197
- gr.Textbox(
198
- value="You are EduBot, an expert AI learning assistant. Provide comprehensive, educational responses that help students truly understand concepts.",
199
- label="Custom System Message",
200
- placeholder="Customize how EduBot behaves...",
201
- lines=2
202
- ),
203
- gr.Slider(
204
- minimum=1,
205
- maximum=1024,
206
- value=600,
207
- step=1,
208
- label="Max Tokens"
209
- ),
210
- gr.Slider(
211
- minimum=0.1,
212
- maximum=2.0,
213
- value=0.7,
214
- step=0.1,
215
- label="Temperature"
216
- ),
217
- gr.Slider(
218
- minimum=0.1,
219
- maximum=1.0,
220
- value=0.9,
221
- step=0.05,
222
- label="Top-p"
223
- ),
224
- ],
225
- theme=gr.themes.Soft(
226
- primary_hue="blue",
227
- secondary_hue="green"
228
  )
229
- )
230
 
231
  if __name__ == "__main__":
232
- logger.info("Starting EduBot application...")
233
  demo.launch()
 
165
  logger.exception("Error in LangChain response generation")
166
  yield f"Sorry, I encountered an error: {str(e)[:150]}"
167
 
168
+ # Your custom Glass theme with amber accent
169
+ theme = gr.themes.Glass(
170
+ primary_hue="amber",
171
+ text_size="md",
172
+ radius_size="md",
173
+ ).set(
174
+ shadow_drop='*shadow_drop_lg',
175
+ shadow_drop_lg='*shadow_drop',
176
+ shadow_spread='*shadow_drop_lg',
177
+ block_info_text_weight='500',
178
+ button_border_width='*block_border_width'
179
+ )
180
+
181
+ # Create enhanced Gradio interface with your custom theme
182
+ with gr.Blocks(theme=theme) as demo:
183
+
184
+ gr.HTML("""
185
+ <div style='text-align: center; margin-bottom: 2rem;'>
186
+ <h1 style='font-size: 2.5rem; font-weight: bold; color: #d97706; margin-bottom: 0.5rem;'>
187
+ ๐ŸŽ“ EduBot | AI Learning Assistant
188
+ </h1>
189
+ <p style='font-size: 1.2rem; color: #6b7280; margin-bottom: 1rem;'>
190
+ Your comprehensive AI tutor powered by LangChain!
191
+ </p>
192
+ <div style='background: rgba(217, 119, 6, 0.1); padding: 1rem; border-radius: 10px; margin: 1rem auto; max-width: 800px;'>
193
+ <p style='margin: 0; font-weight: 500;'>
194
+ ๐Ÿ”ง <strong>LangChain Features:</strong> Dynamic prompt templates โ€ข Chain composition โ€ข Smart truncation โ€ข Enhanced error handling
195
+ </p>
196
+ </div>
197
+ </div>
198
+ """)
199
+
200
+ with gr.Row():
201
+ with gr.Column(scale=3):
202
+ # Main chat interface
203
+ chatbot = gr.Chatbot(
204
+ height=500,
205
+ show_copy_button=True,
206
+ avatar_images=["๐Ÿ‘ค", "๐ŸŽ“"],
207
+ placeholder="Hi! I'm EduBot. What would you like to learn today? ๐Ÿ“š"
208
+ )
209
+
210
+ msg = gr.Textbox(
211
+ placeholder="Ask me about math, research, study strategies, or any educational topic...",
212
+ container=False,
213
+ scale=7,
214
+ show_label=False
215
+ )
216
+
217
+ with gr.Row():
218
+ clear_btn = gr.Button("๐Ÿ—‘๏ธ Clear Chat", variant="secondary", size="sm")
219
+ send_btn = gr.Button("๐Ÿ“ค Send Message", variant="primary", size="sm")
220
+
221
+ with gr.Column(scale=1):
222
+ gr.HTML("""
223
+ <div style='background: rgba(217, 119, 6, 0.1); padding: 1rem; border-radius: 10px; margin-bottom: 1rem;'>
224
+ <h3 style='margin-top: 0; color: #d97706;'>๐Ÿ“š Educational Modes</h3>
225
+ <ul style='margin: 0; padding-left: 1.2rem;'>
226
+ <li><strong>๐Ÿงฎ Math Mode</strong> - Step-by-step solutions</li>
227
+ <li><strong>๐Ÿ” Research Mode</strong> - Source finding & citations</li>
228
+ <li><strong>๐Ÿ“š Study Mode</strong> - Learning strategies</li>
229
+ <li><strong>๐ŸŽ“ General Mode</strong> - Comprehensive support</li>
230
+ </ul>
231
+ </div>
232
+ """)
233
+
234
+ system_message = gr.Textbox(
235
+ value="You are EduBot, an expert AI learning assistant. Provide comprehensive, educational responses that help students truly understand concepts.",
236
+ label="Custom System Message",
237
+ placeholder="Customize how EduBot behaves...",
238
+ lines=3
239
+ )
240
+
241
+ with gr.Accordion("Advanced Settings", open=False):
242
+ max_tokens = gr.Slider(
243
+ minimum=1,
244
+ maximum=1024,
245
+ value=600,
246
+ step=1,
247
+ label="Max Tokens",
248
+ info="Higher = longer responses"
249
+ )
250
+
251
+ temperature = gr.Slider(
252
+ minimum=0.1,
253
+ maximum=2.0,
254
+ value=0.7,
255
+ step=0.1,
256
+ label="Temperature",
257
+ info="Higher = more creative"
258
+ )
259
+
260
+ top_p = gr.Slider(
261
+ minimum=0.1,
262
+ maximum=1.0,
263
+ value=0.9,
264
+ step=0.05,
265
+ label="Top-p",
266
+ info="Controls diversity"
267
+ )
268
 
269
+ # Example questions section
270
+ gr.HTML("""
271
+ <div style='background: rgba(217, 119, 6, 0.05); padding: 1.5rem; border-radius: 10px; margin-top: 1rem;'>
272
+ <h3 style='margin-top: 0; color: #d97706; text-align: center;'>๐Ÿ’ก Try These Example Questions</h3>
273
+ </div>
274
+ """)
275
 
276
+ examples = gr.Examples(
277
+ examples=[
278
+ ["Solve the quadratic equation xยฒ + 5x + 6 = 0 with complete step-by-step explanations"],
279
+ ["How do I conduct a comprehensive literature review for my psychology research paper?"],
280
+ ["Create a detailed study schedule for my calculus and chemistry final exams"],
281
+ ["Explain derivatives in calculus with real-world applications and examples"],
282
+ ["How do I properly format citations in APA style with detailed guidelines?"]
283
+ ],
284
+ inputs=msg,
285
+ examples_per_page=5
286
+ )
287
 
288
+ # Enhanced response function for Blocks
289
+ def respond_and_update(message, history, system_msg, max_tok, temp, top_p):
290
+ # Get the streaming response
291
+ for response in respond_with_enhanced_streaming(message, history, system_msg, max_tok, temp, top_p):
292
+ history.append([message, response])
293
+ yield history, ""
294
+
295
+ # Event handlers
296
+ msg.submit(
297
+ respond_and_update,
298
+ [msg, chatbot, system_message, max_tokens, temperature, top_p],
299
+ [chatbot, msg]
300
+ )
301
+
302
+ send_btn.click(
303
+ respond_and_update,
304
+ [msg, chatbot, system_message, max_tokens, temperature, top_p],
305
+ [chatbot, msg]
306
+ )
307
+
308
+ clear_btn.click(
309
+ lambda: ([], ""),
310
+ outputs=[chatbot, msg]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
311
  )
 
312
 
313
  if __name__ == "__main__":
314
+ logger.info("Starting EduBot application with custom Glass theme...")
315
  demo.launch()