Update app.py
Browse files
app.py
CHANGED
@@ -504,10 +504,17 @@ class BOUESTIChatbot:
|
|
504 |
|
505 |
return history, ""
|
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;">
|
@@ -517,50 +524,65 @@ class BOUESTIChatbot:
|
|
517 |
<p style="text-align: center;">Get instant answers about admissions, programs, fees, and more!</p>
|
518 |
</div>
|
519 |
""")
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
|
|
|
|
|
|
|
|
|
|
526 |
msg = gr.Textbox(
|
527 |
placeholder="Ask me about BOUESTI admissions, programs, fees, or any other questions...",
|
528 |
container=False,
|
529 |
scale=7,
|
530 |
show_label=False
|
531 |
)
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
|
|
|
|
|
|
558 |
return interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
559 |
|
560 |
|
561 |
-
|
562 |
-
# Initialize and expose the chatbot interface for Hugging Face Spaces
|
563 |
-
chatbot = BOUESTIChatbot()
|
564 |
-
demo = chatbot.create_gradio_interface()
|
565 |
-
demo.launch(debug=True, share=True)
|
566 |
-
|
|
|
504 |
|
505 |
return history, ""
|
506 |
|
507 |
+
def gradio_chat(self, message, history):
|
508 |
+
"""Gradio chat interface function"""
|
509 |
+
if not message.strip():
|
510 |
+
return history, ""
|
511 |
+
response = self.generate_response(message)
|
512 |
+
return history + [[message, response]], ""
|
513 |
+
|
514 |
def create_gradio_interface(self):
|
515 |
+
"""Create Gradio interface with proper event binding"""
|
516 |
with gr.Blocks(title="BOUESTI Virtual Assistant", theme=gr.themes.Soft()) as interface:
|
517 |
+
# Header section
|
518 |
gr.HTML("""
|
519 |
<div class="gradio-header">
|
520 |
<h1 style="text-align: center;">
|
|
|
524 |
<p style="text-align: center;">Get instant answers about admissions, programs, fees, and more!</p>
|
525 |
</div>
|
526 |
""")
|
527 |
+
|
528 |
+
# Chat interface layout
|
529 |
+
with gr.Row():
|
530 |
+
with gr.Column(scale=4):
|
531 |
+
chatbot_window = gr.Chatbot(
|
532 |
+
value=[],
|
533 |
+
elem_id="chatbot",
|
534 |
+
bubble_full_width=False,
|
535 |
+
height=400,
|
536 |
+
show_label=False
|
537 |
+
)
|
538 |
msg = gr.Textbox(
|
539 |
placeholder="Ask me about BOUESTI admissions, programs, fees, or any other questions...",
|
540 |
container=False,
|
541 |
scale=7,
|
542 |
show_label=False
|
543 |
)
|
544 |
+
with gr.Row():
|
545 |
+
submit_btn = gr.Button("Send", variant="primary")
|
546 |
+
clear_btn = gr.Button("Clear", variant="secondary")
|
547 |
+
|
548 |
+
# Instruction panel
|
549 |
+
with gr.Column(scale=2):
|
550 |
+
gr.HTML("""
|
551 |
+
<div style="border: 1px solid #e0e0e0; padding: 10px; border-radius: 5px; margin-bottom: 10px; background-color: #f9f9f9;">
|
552 |
+
<p style="margin: 0;">Whenever you are stuck, enter the magic word: <strong style="color: #591305;">Guide me</strong></p>
|
553 |
+
</div>
|
554 |
+
""")
|
555 |
+
|
556 |
+
# Event handlers
|
557 |
+
submit_btn.click(
|
558 |
+
fn=self.gradio_chat,
|
559 |
+
inputs=[msg, chatbot_window],
|
560 |
+
outputs=[chatbot_window, msg]
|
561 |
+
)
|
562 |
+
msg.submit(
|
563 |
+
fn=self.gradio_chat,
|
564 |
+
inputs=[msg, chatbot_window],
|
565 |
+
outputs=[chatbot_window, msg]
|
566 |
+
)
|
567 |
+
clear_btn.click(
|
568 |
+
fn=lambda: ([], ""),
|
569 |
+
inputs=[],
|
570 |
+
outputs=[chatbot_window, msg]
|
571 |
+
)
|
572 |
+
|
573 |
return interface
|
574 |
+
|
575 |
+
# Hugging Face Spaces configuration
|
576 |
+
if __name__ == "__main__":
|
577 |
+
chatbot = BOUESTIChatbot()
|
578 |
+
demo = chatbot.create_gradio_interface()
|
579 |
+
demo.launch(
|
580 |
+
server_name="0.0.0.0",
|
581 |
+
server_port=7860,
|
582 |
+
enable_queue=True,
|
583 |
+
share=False,
|
584 |
+
show_error=True
|
585 |
+
)
|
586 |
+
a few seconds ago
|
587 |
|
588 |
|
|
|
|
|
|
|
|
|
|
|
|