Bwrite commited on
Commit
df9da25
Β·
verified Β·
1 Parent(s): 16e2d38

Update app.py

Browse files

Admission ChatBot

Files changed (1) hide show
  1. app.py +15 -22
app.py CHANGED
@@ -506,30 +506,22 @@ class BOUESTIChatbot:
506
 
507
  def create_gradio_interface(self):
508
  """Create Gradio interface"""
509
- with gr.Blocks(
510
- title="BOUESTI Virtual Assistant",
511
- theme=gr.themes.Soft()
512
- ) as interface:
513
  gr.HTML("""
514
  <div class="gradio-header">
515
  <h1 style="text-align: center;">
516
- <span style="font-size: 2.2em;">πŸŽ“</span> BOUESTI ChatBot
517
  </h1>
518
  <h3 style="text-align: center;">Bamidele Olumilua University of Education, Science, and Technology</h3>
519
  <p style="text-align: center;">Get instant answers about admissions, programs, fees, and more!</p>
520
  </div>
521
- """)
522
 
 
523
  with gr.Row():
524
  with gr.Column(scale=4):
525
- chatbot = gr.Chatbot(
526
- [],
527
- elem_id="chatbot",
528
- bubble_full_width=False,
529
- height=400,
530
- show_label=False
531
- )
532
-
533
  with gr.Row():
534
  msg = gr.Textbox(
535
  placeholder="Ask me about BOUESTI admissions, programs, fees, or any other questions...",
@@ -542,13 +534,14 @@ class BOUESTIChatbot:
542
  clear_btn = gr.Button("Clear Chat", variant="secondary", size="sm")
543
 
544
  with gr.Column(scale=2):
 
545
  gr.HTML("""
546
- <div style="border: 1px solid #e0e0e0; padding: 10px; border-radius: 5px; margin-bottom: 10px; background-color: #f9f9f9;">
547
- <p style="margin: 0;">Whenever you are stuck, enter the magic word: <strong style="color: #591305;">Guide me</strong></p>
548
- </div>
549
  """)
550
 
551
- # Define handlers
552
  def respond(message, history):
553
  if not message.strip():
554
  return history, ""
@@ -559,14 +552,14 @@ class BOUESTIChatbot:
559
  def clear_chat():
560
  return [], ""
561
 
562
- # Event wiring
563
- submit_btn.click(respond, [msg, chatbot], [chatbot, msg])
564
- msg.submit(respond, [msg, chatbot], [chatbot, msg])
565
- clear_btn.click(clear_chat, [], [chatbot, msg])
566
 
567
  return interface
568
 
569
 
 
570
  # Initialize and expose the chatbot interface for Hugging Face Spaces
571
  chatbot = BOUESTIChatbot()
572
  demo = chatbot.create_gradio_interface()
 
506
 
507
  def create_gradio_interface(self):
508
  """Create Gradio interface"""
509
+ with gr.Blocks(title="BOUESTI Virtual Assistant", theme=gr.themes.Soft()) as interface:
510
+ # Header
 
 
511
  gr.HTML("""
512
  <div class="gradio-header">
513
  <h1 style="text-align: center;">
514
+ <span style="font-size: 2.2em;">πŸŽ“</span> BOUESTI ChatBot
515
  </h1>
516
  <h3 style="text-align: center;">Bamidele Olumilua University of Education, Science, and Technology</h3>
517
  <p style="text-align: center;">Get instant answers about admissions, programs, fees, and more!</p>
518
  </div>
519
+ """)
520
 
521
+ # Chat interface
522
  with gr.Row():
523
  with gr.Column(scale=4):
524
+ chatbot_window = gr.Chatbot([], elem_id="chatbot", bubble_full_width=False, height=400, show_label=False)
 
 
 
 
 
 
 
525
  with gr.Row():
526
  msg = gr.Textbox(
527
  placeholder="Ask me about BOUESTI admissions, programs, fees, or any other questions...",
 
534
  clear_btn = gr.Button("Clear Chat", variant="secondary", size="sm")
535
 
536
  with gr.Column(scale=2):
537
+ # Instruction box
538
  gr.HTML("""
539
+ <div style="border: 1px solid #e0e0e0; padding: 10px; border-radius: 5px; margin-bottom: 10px; background-color: #f9f9f9;">
540
+ <p style="margin: 0;">Whenever you are stuck, enter the magic word: <strong style="color: #591305;">Guide me</strong></p>
541
+ </div>
542
  """)
543
 
544
+ # Handlers must be here inside the Blocks context
545
  def respond(message, history):
546
  if not message.strip():
547
  return history, ""
 
552
  def clear_chat():
553
  return [], ""
554
 
555
+ submit_btn.click(respond, [msg, chatbot_window], [chatbot_window, msg])
556
+ msg.submit(respond, [msg, chatbot_window], [chatbot_window, msg])
557
+ clear_btn.click(clear_chat, [], [chatbot_window, msg])
 
558
 
559
  return interface
560
 
561
 
562
+
563
  # Initialize and expose the chatbot interface for Hugging Face Spaces
564
  chatbot = BOUESTIChatbot()
565
  demo = chatbot.create_gradio_interface()