UKURIKIYEYEZU commited on
Commit
acf09e2
·
verified ·
1 Parent(s): bdb5b69

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +112 -139
app.py CHANGED
@@ -488,176 +488,149 @@ def rag_memory_stream(message, history):
488
  # After generating the complete response, add it to history
489
  user_session.add_to_history("assistant", full_response)
490
 
491
- custom_css = """
492
- body, html {
493
- margin: 0;
494
- padding: 0;
495
- height: 100%;
496
- width: 100%;
497
- overflow: hidden;
498
- font-family: "Arial", serif;
499
- }
500
-
501
- .gradio-container {
502
- font-family: "Times New Roman", serif;
503
- width: 100vw;
504
- height: 100vh;
505
- max-width: 100% !important;
506
- max-height: 100% !important;
507
- margin: 0 !important;
508
- padding: 0 !important;
509
- display: flex;
510
- flex-direction: column;
511
- }
512
-
513
- .main {
514
- flex: 1;
515
- display: flex;
516
- flex-direction: column;
517
- height: 100%;
518
- width: 100%;
519
- max-width: 100% !important;
520
- padding: 0 !important;
521
- margin: 0 !important;
522
- }
523
-
524
- .gr-button {
525
- background-color: #007bff; /* Blue button */
526
- color: white;
527
- border: none;
528
- border-radius: 5px;
529
- font-size: 16px;
530
- padding: 10px 20px;
531
- cursor: pointer;
532
- }
533
-
534
- .gr-textbox:focus, .gr-button:focus {
535
- outline: none; /* Remove outline focus for a cleaner look */
536
- }
537
-
538
- /* Custom CSS for the examples section */
539
- .gr-examples {
540
- font-size: 30px; /* Increase font size of examples */
541
- background-color: #f9f9f9; /* Light background color */
542
- border-radius: 30px; /* Rounded corners */
543
- }
544
-
545
- .gr-examples .example {
546
- background-color: white; /* White background for each example */
547
- cursor: pointer; /* Change cursor to pointer on hover */
548
- transition: background-color 0.3s ease; /* Smooth hover effect */
549
- }
550
-
551
- .gr-examples .example:hover {
552
- background-color: #f1f1f1; /* Light gray background on hover */
553
- }
554
-
555
- /* Make chat interface fill available space */
556
- .chat-interface {
557
- height: 100% !important;
558
- display: flex;
559
- flex-direction: column;
560
- }
561
-
562
- .chat-panel {
563
- flex: 1;
564
- overflow-y: auto;
565
- min-height: 70vh;
566
- }
567
-
568
- .registration-container {
569
- display: flex;
570
- flex-direction: column;
571
- justify-content: center;
572
- align-items: center;
573
- height: 100vh;
574
- width: 100%;
575
- }
576
-
577
- footer {
578
- margin-top: auto;
579
- text-align: center;
580
- padding: 10px;
581
- }
582
-
583
- /* Make chatbot container fill the screen */
584
- .chatbot-container {
585
- height: 100vh;
586
- width: 100%;
587
- display: flex;
588
- flex-direction: column;
589
- }
590
-
591
- /* Center form elements */
592
- .form-row {
593
- display: flex;
594
- justify-content: center;
595
- margin: 10px 0;
596
- }
597
- """
598
 
599
  # Gradio Interface Setup with improved UX
600
  def chatbot_interface():
601
  # Get API key (in a real application, handle this more securely)
602
  api_key = api # This should be properly defined or imported elsewhere
603
-
604
  # Update the template to include conversation history
605
  global template
606
  template = """
607
  You are a compassionate and supportive AI assistant specializing in helping individuals affected by Gender-Based Violence (GBV).
608
-
609
  Previous conversation:
610
  {conversation_history}
611
-
612
  Context information:
613
  {context}
614
-
615
  User {first_name} asks: {question}
616
-
617
  Respond with empathy and provide support and resources based on the conversation and context. Always maintain a warm, supportive tone.
618
  """
619
 
620
  # Create the RAG chain with user context
621
  global rag_chain
622
  rag_chain = create_rag_chain(retriever, template, api_key)
623
-
624
- with gr.Blocks(css=custom_css, theme="soft") as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
625
  # User registration section
626
- registration_container = gr.Column(visible=True, elem_classes=["registration-container"])
627
  with registration_container:
628
- gr.Markdown(
629
- """
630
- <div style='font-size: 32px; text-align: center;'>
631
- Your privacy is our concern, please provide your nickname.
632
- </div>
633
- """,
634
- elem_id="welcome-title"
635
- )
636
 
637
- with gr.Row(elem_classes=["form-row"]):
638
  first_name = gr.Textbox(
639
  label="Nickname",
640
- placeholder="Enter your Nickname"
 
641
  )
642
-
643
- with gr.Row(elem_classes=["form-row"]):
644
- submit_btn = gr.Button("Start Chatting", variant="primary")
645
-
646
  response_message = gr.Markdown(elem_id="welcome-message")
647
-
648
  # Chatbot section (initially hidden)
649
- chatbot_container = gr.Column(visible=False, elem_classes=["chatbot-container"])
650
  with chatbot_container:
651
  chat_interface = gr.ChatInterface(
652
  fn=rag_memory_stream,
653
- title="Chat with GBVR",
654
  fill_height=True,
655
- elem_classes=["chat-interface"]
 
656
  )
657
-
658
  # Footer with version info
659
- gr.Markdown("Ijwi ry'Ubufasha v1.0.0 © 2025", elem_id="footer", elem_classes=["footer"])
660
-
661
  # Handle user registration
662
  submit_btn.click(
663
  collect_user_info,
@@ -669,6 +642,6 @@ def chatbot_interface():
669
 
670
  # Launch the interface
671
  if __name__ == "__main__":
672
- # Launch the interface
673
- chatbot_interface().launch(share=True, inbrowser=True, debug=True)
674
-
 
488
  # After generating the complete response, add it to history
489
  user_session.add_to_history("assistant", full_response)
490
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
491
 
492
  # Gradio Interface Setup with improved UX
493
  def chatbot_interface():
494
  # Get API key (in a real application, handle this more securely)
495
  api_key = api # This should be properly defined or imported elsewhere
496
+
497
  # Update the template to include conversation history
498
  global template
499
  template = """
500
  You are a compassionate and supportive AI assistant specializing in helping individuals affected by Gender-Based Violence (GBV).
501
+
502
  Previous conversation:
503
  {conversation_history}
504
+
505
  Context information:
506
  {context}
507
+
508
  User {first_name} asks: {question}
509
+
510
  Respond with empathy and provide support and resources based on the conversation and context. Always maintain a warm, supportive tone.
511
  """
512
 
513
  # Create the RAG chain with user context
514
  global rag_chain
515
  rag_chain = create_rag_chain(retriever, template, api_key)
516
+
517
+ with gr.Blocks(css="""
518
+ :root {
519
+ --background: #343541;
520
+ --primary-text: #ececf1;
521
+ --input-bg: #40414f;
522
+ --border: #555766;
523
+ --button-bg: #19c37d;
524
+ --button-hover: #15a46a;
525
+ --user-bubble: #343541;
526
+ --bot-bubble: #444654;
527
+ }
528
+
529
+ body {
530
+ background: var(--background) !important;
531
+ font-family: 'Segoe UI', system-ui, sans-serif !important;
532
+ color: var(--primary-text) !important;
533
+ }
534
+
535
+ .welcome-container {
536
+ max-width: 500px;
537
+ margin: 2rem auto;
538
+ padding: 2rem;
539
+ background: var(--input-bg);
540
+ border-radius: 8px;
541
+ box-shadow: 0 4px 6px rgba(0,0,0,0.1);
542
+ }
543
+
544
+ .chatbot {
545
+ border: none !important;
546
+ background: transparent !important;
547
+ box-shadow: none !important;
548
+ min-height: 70vh;
549
+ }
550
+
551
+ .user, .bot {
552
+ padding: 12px 16px !important;
553
+ margin: 8px 0 !important;
554
+ border-radius: 8px !important;
555
+ max-width: 80%;
556
+ }
557
+
558
+ .user {
559
+ background: var(--user-bubble) !important;
560
+ margin-left: auto !important;
561
+ border: 1px solid var(--border);
562
+ }
563
+
564
+ .bot {
565
+ background: var(--bot-bubble) !important;
566
+ margin-right: auto !important;
567
+ }
568
+
569
+ .textbox {
570
+ background: var(--input-bg) !important;
571
+ border: 1px solid var(--border) !important;
572
+ border-radius: 8px !important;
573
+ color: var(--primary-text) !important;
574
+ padding: 12px !important;
575
+ }
576
+
577
+ .feedback-btn {
578
+ background: var(--button-bg) !important;
579
+ color: white !important;
580
+ border: none !important;
581
+ border-radius: 6px !important;
582
+ padding: 8px 16px !important;
583
+ transition: background 0.3s ease;
584
+ }
585
+
586
+ .feedback-btn:hover {
587
+ background: var(--button-hover) !important;
588
+ }
589
+
590
+ footer {
591
+ color: #888 !important;
592
+ font-size: 0.9em;
593
+ padding: 1rem;
594
+ }
595
+
596
+ #component-0 {
597
+ max-width: 1200px;
598
+ margin: 0 auto;
599
+ padding: 20px;
600
+ }
601
+ """) as demo:
602
+
603
  # User registration section
604
+ registration_container = gr.Column(visible=True)
605
  with registration_container:
606
+ gr.Markdown("### To prioritize your privacy, please provide your nickname. ")
 
 
 
 
 
 
 
607
 
608
+ with gr.Row():
609
  first_name = gr.Textbox(
610
  label="Nickname",
611
+ placeholder="Enter your Nickname",
612
+ scale=1
613
  )
614
+
615
+ with gr.Row():
616
+ submit_btn = gr.Button("Start Chatting", variant="primary", scale=2)
617
+
618
  response_message = gr.Markdown(elem_id="welcome-message")
619
+
620
  # Chatbot section (initially hidden)
621
+ chatbot_container = gr.Column(visible=False)
622
  with chatbot_container:
623
  chat_interface = gr.ChatInterface(
624
  fn=rag_memory_stream,
625
+ title=gr.Markdown("# Ijwi ry'Ubufasha", elem_classes="chat-title"),
626
  fill_height=True,
627
+ textbox=gr.Textbox(placeholder="Type your message here...", show_label=False),
628
+ submit_btn=gr.Button("Send", variant="primary")
629
  )
630
+
631
  # Footer with version info
632
+ gr.Markdown("Ijwi ry'Ubufasha v1.0.0 © 2025", elem_id="footer")
633
+
634
  # Handle user registration
635
  submit_btn.click(
636
  collect_user_info,
 
642
 
643
  # Launch the interface
644
  if __name__ == "__main__":
645
+
646
+ chatbot_interface().launch(share=True, inbrowser=True)
647
+