AryanJh commited on
Commit
73a4a35
Β·
verified Β·
1 Parent(s): 2364ef3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -52
app.py CHANGED
@@ -220,67 +220,49 @@ class BrockEventsApp:
220
  return "❌ Error refreshing events. Please try again later."
221
 
222
  def create_demo():
223
- """Create Gradio interface"""
224
- app = BrockEventsApp()
225
-
226
- demo = gr.Blocks(theme=gr.themes.Soft())
227
-
228
- with demo:
229
- gr.Markdown("""
230
- # πŸŽ“ Brock Events Assistant
231
-
232
- Ask me about upcoming events at Brock University:
233
- - πŸ“š Academic events and workshops
234
- - 🎯 Faculty-specific events
235
- - 🏫 Campus activities
236
- - πŸ‘₯ Student club meetings
237
  """)
238
 
 
239
  chatbot = gr.Chatbot(
 
240
  height=500,
241
  bubble_full_width=False,
242
- show_copy_button=True
 
 
243
  )
244
 
245
- with gr.Row():
246
- msg = gr.Textbox(
247
- label="Your Question",
248
- placeholder="e.g., What events are happening this week?",
249
- scale=4
250
- )
251
- submit = gr.Button("πŸ” Ask", scale=1)
252
-
253
- with gr.Row():
254
- clear = gr.Button("πŸ—‘οΈ Clear Chat")
255
- refresh = gr.Button("πŸ”„ Refresh Events")
256
-
257
- # Example queries
258
- gr.Examples(
259
- examples=[
260
- "What events are happening this week?",
261
- "Are there any workshops in the library?",
262
- "Show me Faculty of Mathematics events",
263
- "What's happening in the MakerSpace?",
264
- "Any online workshops available?"
265
- ],
266
- inputs=msg
267
- )
268
 
269
- # Connect event handlers
270
- msg.submit(app.process_query, [msg, chatbot], [msg, chatbot])
271
- submit.click(app.process_query, [msg, chatbot], [msg, chatbot])
272
- clear.click(lambda: None, None, chatbot)
273
- refresh.click(app.refresh_events, None, msg)
 
 
 
 
274
 
275
- # Help section
276
- with gr.Accordion("πŸ’‘ Tips", open=False):
277
- gr.Markdown("""
278
- - Ask about specific dates: "What's happening next Tuesday?"
279
- - Search by location: "Events in the Student Center"
280
- - Find faculty events: "Show me Mathematics department events"
281
- - Look for online events: "What virtual workshops are available?"
282
- """)
283
 
284
  if __name__ == "__main__":
285
  demo = create_demo()
286
- demo.launch()
 
 
 
 
 
 
 
 
 
220
  return "❌ Error refreshing events. Please try again later."
221
 
222
  def create_demo():
223
+ """Create an improved Gradio 5 interface for the Brock Events Assistant"""
224
+ # Initialize the RAG system
225
+ - And more!
 
 
 
 
 
 
 
 
 
 
 
226
  """)
227
 
228
+ # Chat interface with new Gradio 5 features
229
  chatbot = gr.Chatbot(
230
+ label="Chat History",
231
  height=500,
232
  bubble_full_width=False,
233
+ show_copy_button=True,
234
+ likeable=False, # Only bot messages are likeable by default in v5
235
+ layout="bubble"
236
  )
237
 
238
+ # Input row
239
+ clear = gr.Button("πŸ—‘οΈ Clear Chat", variant="secondary")
240
+ refresh = gr.Button("πŸ”„ Refresh Events", variant="secondary")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
 
242
+ # Event handlers updated for Gradio 5
243
+ def respond(message, history):
244
+ """Handle chat responses"""
245
+ if not message.strip():
246
+ return "", history
247
+
248
+ bot_message = rag_system.generate_response(message, history)
249
+ history.append([message, bot_message]) # New list format for v5
250
+ return "", history
251
 
252
+ def refresh_events():
253
+ max_threads=40,
254
+ show_error=True,
255
+ ssr_mode=True # Enable SSR for better performance
256
+ )
 
 
 
257
 
258
  if __name__ == "__main__":
259
  demo = create_demo()
260
+ demo.launch(
261
+ server_name="0.0.0.0",
262
+ server_port=7860,
263
+ share=False,
264
+ max_threads=40,
265
+ debug=False,
266
+ show_error=True,
267
+ favicon_path="./favicon.ico"
268
+ )