AryanJh commited on
Commit
2816cdf
Β·
verified Β·
1 Parent(s): 297c085

Updated gradio version changes

Browse files

generated old gradio themes, needed to be updated to prevent runtime error

Files changed (1) hide show
  1. app.py +43 -50
app.py CHANGED
@@ -302,7 +302,7 @@ class BrockEventsRAG:
302
  return None
303
 
304
  def create_demo():
305
- """Create an improved Gradio interface for the Brock Events Assistant"""
306
  # Initialize the RAG system
307
  rag_system = BrockEventsRAG()
308
 
@@ -329,28 +329,11 @@ def create_demo():
329
  .gr-button-secondary:hover {
330
  background-color: #8b000010 !important;
331
  }
332
-
333
- .gr-input {
334
- border-radius: 8px !important;
335
- }
336
-
337
- .gr-padded {
338
- padding: 16px !important;
339
- }
340
-
341
- .gr-header {
342
- background-color: #8b0000 !important;
343
- color: white !important;
344
- }
345
-
346
- .gr-examples {
347
- gap: 8px !important;
348
- }
349
  """
350
 
351
- # Create the Gradio interface with enhanced styling
352
  with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
353
- # Header section
354
  gr.Markdown("""
355
  # πŸŽ“ Brock University Events Assistant
356
 
@@ -362,45 +345,46 @@ def create_demo():
362
  - And more!
363
  """)
364
 
365
- # Chat interface
366
  chatbot = gr.Chatbot(
367
  label="Chat History",
368
  height=500,
369
  bubble_full_width=False,
370
- type="messages",
371
  show_copy_button=True,
 
372
  layout="bubble"
373
  )
374
 
375
- # Input row with enhanced styling
376
- with gr.Row().style(equal_height=True):
377
- msg = gr.Textbox(
378
- label="Your Question",
379
- placeholder="e.g., What events are happening this week?",
380
- scale=4,
381
- container=False,
382
- autofocus=True
383
- )
384
- submit = gr.Button(
385
- "πŸ” Ask",
386
- scale=1,
387
- variant="primary"
388
- )
 
389
 
390
  # Control buttons
391
- with gr.Row(equal_height=True):
392
- clear = gr.Button("πŸ—‘οΈ Clear Chat", variant="secondary")
393
- refresh = gr.Button("πŸ”„ Refresh Events", variant="secondary")
 
394
 
395
- # Event handlers
396
  def respond(message, history):
397
  """Handle chat responses"""
398
  if not message.strip():
399
  return "", history
400
 
401
  bot_message = rag_system.generate_response(message, history)
402
- history.append({"role": "user", "content": message})
403
- history.append({"role": "assistant", "content": bot_message})
404
  return "", history
405
 
406
  def refresh_events():
@@ -414,7 +398,7 @@ def create_demo():
414
  clear.click(lambda: None, None, chatbot)
415
  refresh.click(refresh_events, None, msg)
416
 
417
- # Example questions with enhanced presentation
418
  with gr.Accordion("πŸ“ Example Questions", open=False):
419
  gr.Examples(
420
  examples=[
@@ -427,28 +411,26 @@ def create_demo():
427
  "What online workshops are available?",
428
  "Is there anything happening tomorrow?",
429
  ],
430
- inputs=msg,
431
- label="Try these questions:"
432
  )
433
 
434
  # Help section
435
  with gr.Accordion("πŸ’‘ Tips & Information", open=False):
436
  gr.Markdown("""
437
- ### How to Get the Most Out of RAG-gy:
438
-
439
  - πŸ“… **Ask about specific dates**: "What's happening next Tuesday?"
440
  - πŸ“ **Query by location**: "Events in the Student Center"
441
  - 🎯 **Search by type**: "Show me research seminars"
442
  - πŸ‘₯ **Find faculty events**: "Mathematics department events"
443
 
444
- ### Good to Know:
445
  - The events database refreshes automatically every 24 hours
446
  - Events are shown for the next 14 days
447
  - Click any event link to see full details on ExperienceBU
448
  - Use the refresh button if you need the latest updates
449
 
450
- ### Need Help?
451
- If you're not getting the results you expect (Still work in progress), try:
452
  - Being more specific about what you're looking for
453
  - Using different keywords
454
  - Checking the example questions above
@@ -456,6 +438,17 @@ def create_demo():
456
 
457
  return demo
458
 
 
 
 
 
 
 
 
 
 
 
 
459
  if __name__ == "__main__":
460
  demo = create_demo()
461
  demo.launch(
 
302
  return None
303
 
304
  def create_demo():
305
+ """Create an improved Gradio 5 interface for the Brock Events Assistant"""
306
  # Initialize the RAG system
307
  rag_system = BrockEventsRAG()
308
 
 
329
  .gr-button-secondary:hover {
330
  background-color: #8b000010 !important;
331
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
332
  """
333
 
334
+ # Create the Gradio interface with enhanced styling and new theme
335
  with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
336
+ # Header section with Markdown
337
  gr.Markdown("""
338
  # πŸŽ“ Brock University Events Assistant
339
 
 
345
  - And more!
346
  """)
347
 
348
+ # Chat interface with new Gradio 5 features
349
  chatbot = gr.Chatbot(
350
  label="Chat History",
351
  height=500,
352
  bubble_full_width=False,
 
353
  show_copy_button=True,
354
+ likeable=False, # Only bot messages are likeable by default in v5
355
  layout="bubble"
356
  )
357
 
358
+ # Input row
359
+ with gr.Group():
360
+ with gr.Row():
361
+ msg = gr.Textbox(
362
+ label="Your Question",
363
+ placeholder="e.g., What events are happening this week?",
364
+ scale=4,
365
+ container=False,
366
+ autofocus=True
367
+ )
368
+ submit = gr.Button(
369
+ "πŸ” Ask",
370
+ scale=1,
371
+ variant="primary"
372
+ )
373
 
374
  # Control buttons
375
+ with gr.Group():
376
+ with gr.Row():
377
+ clear = gr.Button("πŸ—‘οΈ Clear Chat", variant="secondary")
378
+ refresh = gr.Button("πŸ”„ Refresh Events", variant="secondary")
379
 
380
+ # Event handlers updated for Gradio 5
381
  def respond(message, history):
382
  """Handle chat responses"""
383
  if not message.strip():
384
  return "", history
385
 
386
  bot_message = rag_system.generate_response(message, history)
387
+ history.append([message, bot_message]) # New list format for v5
 
388
  return "", history
389
 
390
  def refresh_events():
 
398
  clear.click(lambda: None, None, chatbot)
399
  refresh.click(refresh_events, None, msg)
400
 
401
+ # Example questions
402
  with gr.Accordion("πŸ“ Example Questions", open=False):
403
  gr.Examples(
404
  examples=[
 
411
  "What online workshops are available?",
412
  "Is there anything happening tomorrow?",
413
  ],
414
+ inputs=msg
 
415
  )
416
 
417
  # Help section
418
  with gr.Accordion("πŸ’‘ Tips & Information", open=False):
419
  gr.Markdown("""
420
+ #### How to Get the Most Out of RAG-gy:
 
421
  - πŸ“… **Ask about specific dates**: "What's happening next Tuesday?"
422
  - πŸ“ **Query by location**: "Events in the Student Center"
423
  - 🎯 **Search by type**: "Show me research seminars"
424
  - πŸ‘₯ **Find faculty events**: "Mathematics department events"
425
 
426
+ #### Good to Know:
427
  - The events database refreshes automatically every 24 hours
428
  - Events are shown for the next 14 days
429
  - Click any event link to see full details on ExperienceBU
430
  - Use the refresh button if you need the latest updates
431
 
432
+ #### Need Help?
433
+ If you're not getting the results you expect, try:
434
  - Being more specific about what you're looking for
435
  - Using different keywords
436
  - Checking the example questions above
 
438
 
439
  return demo
440
 
441
+ if __name__ == "__main__":
442
+ demo = create_demo()
443
+ demo.launch(
444
+ server_name="0.0.0.0",
445
+ server_port=7860,
446
+ share=False,
447
+ max_threads=40,
448
+ show_error=True,
449
+ ssr_mode=True # Enable SSR for better performance
450
+ )
451
+
452
  if __name__ == "__main__":
453
  demo = create_demo()
454
  demo.launch(