IW2025 commited on
Commit
0fbf85b
·
verified ·
1 Parent(s): 17a982d

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -5
app.py CHANGED
@@ -470,10 +470,18 @@ Answer:"""
470
  return answer, recommended_slide, recommended_label, relevant_slides
471
 
472
  # --- Gradio UI ---
473
- chatbot = CurriculumChatbot(fast_mode=True) # Enable fast mode for better performance
474
 
475
- def gradio_chat(query):
476
- answer, recommended_slide, recommended_label, relevant_slides = chatbot.chat(query)
 
 
 
 
 
 
 
 
477
 
478
  # Use the relevant slides (specific PDF with neighboring pages)
479
  gallery_items = relevant_slides if relevant_slides else []
@@ -488,6 +496,15 @@ with gr.Blocks(title="Inclusive World Curriculum Assistant", theme=gr.themes.Sof
488
  with gr.Column(scale=1):
489
  gr.Markdown("### 💬 Chatbot")
490
  gr.Markdown("**What questions do you have?**")
 
 
 
 
 
 
 
 
 
491
  question = gr.Textbox(
492
  label="Question Input",
493
  placeholder="e.g., What are for loops? How do variables work? Explain functions...",
@@ -509,8 +526,8 @@ with gr.Blocks(title="Inclusive World Curriculum Assistant", theme=gr.themes.Sof
509
  )
510
 
511
  # Event handlers
512
- submit.click(fn=gradio_chat, inputs=question, outputs=[answer, gallery])
513
- question.submit(fn=gradio_chat, inputs=question, outputs=[answer, gallery])
514
 
515
  if __name__ == "__main__":
516
  demo.launch()
 
470
  return answer, recommended_slide, recommended_label, relevant_slides
471
 
472
  # --- Gradio UI ---
473
+ chatbot = CurriculumChatbot(fast_mode=False) # Enable AI mode by default
474
 
475
+ def gradio_chat(query, use_ai=True):
476
+ # Temporarily switch modes based on user preference
477
+ original_fast_mode = chatbot.fast_mode
478
+ chatbot.fast_mode = not use_ai
479
+
480
+ try:
481
+ answer, recommended_slide, recommended_label, relevant_slides = chatbot.chat(query)
482
+ finally:
483
+ # Restore original mode
484
+ chatbot.fast_mode = original_fast_mode
485
 
486
  # Use the relevant slides (specific PDF with neighboring pages)
487
  gallery_items = relevant_slides if relevant_slides else []
 
496
  with gr.Column(scale=1):
497
  gr.Markdown("### 💬 Chatbot")
498
  gr.Markdown("**What questions do you have?**")
499
+
500
+ # AI Mode Toggle
501
+ with gr.Row():
502
+ use_ai = gr.Checkbox(
503
+ label="🤖 Enable AI Responses",
504
+ value=True,
505
+ info="Toggle AI-generated answers on/off"
506
+ )
507
+
508
  question = gr.Textbox(
509
  label="Question Input",
510
  placeholder="e.g., What are for loops? How do variables work? Explain functions...",
 
526
  )
527
 
528
  # Event handlers
529
+ submit.click(fn=gradio_chat, inputs=[question, use_ai], outputs=[answer, gallery])
530
+ question.submit(fn=gradio_chat, inputs=[question, use_ai], outputs=[answer, gallery])
531
 
532
  if __name__ == "__main__":
533
  demo.launch()