UKURIKIYEYEZU commited on
Commit
c3a5fcb
·
verified ·
1 Parent(s): 9ab35ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +88 -35
app.py CHANGED
@@ -489,12 +489,38 @@ def rag_memory_stream(message, history):
489
  user_session.add_to_history("assistant", full_response)
490
 
491
  custom_css = """
492
- body {
 
 
 
 
 
493
  font-family: "Arial", serif;
494
  }
 
495
  .gradio-container {
496
  font-family: "Times New Roman", serif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
497
  }
 
498
  .gr-button {
499
  background-color: #007bff; /* Blue button */
500
  color: white;
@@ -504,31 +530,70 @@ body {
504
  padding: 10px 20px;
505
  cursor: pointer;
506
  }
 
507
  .gr-textbox:focus, .gr-button:focus {
508
  outline: none; /* Remove outline focus for a cleaner look */
509
  }
 
510
  /* Custom CSS for the examples section */
511
  .gr-examples {
512
  font-size: 30px; /* Increase font size of examples */
513
  background-color: #f9f9f9; /* Light background color */
514
  border-radius: 30px; /* Rounded corners */
515
  }
 
516
  .gr-examples .example {
517
  background-color: white; /* White background for each example */
518
  cursor: pointer; /* Change cursor to pointer on hover */
519
  transition: background-color 0.3s ease; /* Smooth hover effect */
520
  }
 
521
  .gr-examples .example:hover {
522
  background-color: #f1f1f1; /* Light gray background on hover */
523
  }
524
- """
525
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
526
 
527
  # Gradio Interface Setup with improved UX
528
  def chatbot_interface():
529
  # Get API key (in a real application, handle this more securely)
530
  api_key = api # This should be properly defined or imported elsewhere
531
-
532
  # Update the template to include conversation history
533
  global template
534
  template = """
@@ -548,64 +613,52 @@ def chatbot_interface():
548
  # Create the RAG chain with user context
549
  global rag_chain
550
  rag_chain = create_rag_chain(retriever, template, api_key)
551
-
552
-
553
- with gr.Blocks(css="""
554
- .welcome-container {
555
- text-align: center;
556
- margin-bottom: 20px;
557
- padding: 20px;
558
- border-radius: 10px;
559
- background-color: #f0f4ff;
560
- }
561
- .feedback-btn { margin-top: 10px; }
562
- footer { margin-top: 30px; text-align: center; }
563
- """) as demo:
564
  # User registration section
565
- registration_container = gr.Column(visible=True)
566
  with registration_container:
567
  gr.Markdown(
568
- """
569
- <div style='font-size: 32px;'>
570
- Your privacy is our concern, please provide your nickname.
571
- </div>
572
- """
573
- )
574
-
575
 
576
- with gr.Row():
577
  first_name = gr.Textbox(
578
  label="Nickname",
579
  placeholder="Enter your Nickname",
580
  scale=1
581
  )
582
 
583
- with gr.Row():
584
  submit_btn = gr.Button("Start Chatting", variant="primary", scale=2)
585
-
586
  response_message = gr.Markdown(elem_id="welcome-message")
587
-
588
  # Chatbot section (initially hidden)
589
- chatbot_container = gr.Column(visible=False)
590
  with chatbot_container:
591
  chat_interface = gr.ChatInterface(
592
  fn=rag_memory_stream,
593
  title="Chat with GBVR",
594
  fill_height=True,
595
- css=custom_css,
596
- theme="soft",
597
  )
598
-
599
  # Footer with version info
600
- gr.Markdown("Ijwi ry'Ubufasha v1.0.0 © 2025", elem_id="footer")
601
-
602
  # Handle user registration
603
  submit_btn.click(
604
  collect_user_info,
605
  inputs=[first_name],
606
  outputs=[response_message, chatbot_container, registration_container, chat_interface.chatbot]
607
  )
608
-
609
  return demo
610
 
611
  # Launch the interface
 
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;
 
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
 
592
  # Gradio Interface Setup with improved UX
593
  def chatbot_interface():
594
  # Get API key (in a real application, handle this more securely)
595
  api_key = api # This should be properly defined or imported elsewhere
596
+
597
  # Update the template to include conversation history
598
  global template
599
  template = """
 
613
  # Create the RAG chain with user context
614
  global rag_chain
615
  rag_chain = create_rag_chain(retriever, template, api_key)
616
+
617
+ with gr.Blocks(css=custom_css, theme="soft") as demo:
 
 
 
 
 
 
 
 
 
 
 
618
  # User registration section
619
+ registration_container = gr.Column(visible=True, elem_classes=["registration-container"])
620
  with registration_container:
621
  gr.Markdown(
622
+ """
623
+ <div style='font-size: 32px; text-align: center;'>
624
+ Your privacy is our concern, please provide your nickname.
625
+ </div>
626
+ """,
627
+ elem_id="welcome-title"
628
+ )
629
 
630
+ with gr.Row(scale=0):
631
  first_name = gr.Textbox(
632
  label="Nickname",
633
  placeholder="Enter your Nickname",
634
  scale=1
635
  )
636
 
637
+ with gr.Row(scale=0):
638
  submit_btn = gr.Button("Start Chatting", variant="primary", scale=2)
639
+
640
  response_message = gr.Markdown(elem_id="welcome-message")
641
+
642
  # Chatbot section (initially hidden)
643
+ chatbot_container = gr.Column(visible=False, elem_classes=["chatbot-container"])
644
  with chatbot_container:
645
  chat_interface = gr.ChatInterface(
646
  fn=rag_memory_stream,
647
  title="Chat with GBVR",
648
  fill_height=True,
649
+ elem_classes=["chat-interface"]
 
650
  )
651
+
652
  # Footer with version info
653
+ gr.Markdown("Ijwi ry'Ubufasha v1.0.0 © 2025", elem_id="footer", elem_classes=["footer"])
654
+
655
  # Handle user registration
656
  submit_btn.click(
657
  collect_user_info,
658
  inputs=[first_name],
659
  outputs=[response_message, chatbot_container, registration_container, chat_interface.chatbot]
660
  )
661
+
662
  return demo
663
 
664
  # Launch the interface