AryanJh commited on
Commit
7a7223a
Β·
verified Β·
1 Parent(s): 73a4a35

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -25
app.py CHANGED
@@ -219,41 +219,68 @@ class BrockEventsApp:
219
  print(f"Error refreshing events: {e}")
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()
 
219
  print(f"Error refreshing events: {e}")
220
  return "❌ Error refreshing events. Please try again later."
221
 
222
+ ef create_demo():
223
+ """Create Gradio interface"""
224
+ app = BrockEventsApp()
225
+
226
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
227
+ gr.Markdown("""
228
+ # πŸŽ“ Brock Events Assistant
229
+
230
+ Ask me about upcoming events at Brock University:
231
+ - πŸ“š Academic events and workshops
232
+ - 🎯 Faculty-specific events
233
+ - 🏫 Campus activities
234
+ - πŸ‘₯ Student club meetings
235
  """)
236
 
 
237
  chatbot = gr.Chatbot(
 
238
  height=500,
239
  bubble_full_width=False,
240
  show_copy_button=True,
241
+ type="messages" # Using messages type to avoid deprecation warning
 
242
  )
243
 
244
+ with gr.Row():
245
+ msg = gr.Textbox(
246
+ label="Your Question",
247
+ placeholder="e.g., What events are happening this week?",
248
+ scale=4
249
+ )
250
+ submit = gr.Button("πŸ” Ask", scale=1)
251
 
252
+ with gr.Row():
253
+ clear = gr.Button("πŸ—‘οΈ Clear Chat")
254
+ refresh = gr.Button("πŸ”„ Refresh Events")
 
 
 
 
 
 
255
 
256
+ # Example queries
257
+ gr.Examples(
258
+ examples=[
259
+ "What events are happening this week?",
260
+ "Are there any workshops in the library?",
261
+ "Show me Faculty of Mathematics events",
262
+ "What's happening in the MakerSpace?",
263
+ "Any online workshops available?"
264
+ ],
265
+ inputs=msg
266
+ )
267
+
268
+ # Connect event handlers
269
+ msg.submit(app.process_query, [msg, chatbot], [msg, chatbot])
270
+ submit.click(app.process_query, [msg, chatbot], [msg, chatbot])
271
+ clear.click(lambda: None, None, chatbot)
272
+ refresh.click(app.refresh_events, None, msg)
273
+
274
+ # Help section
275
+ with gr.Accordion("πŸ’‘ Tips", open=False):
276
+ gr.Markdown("""
277
+ - Ask about specific dates: "What's happening next Tuesday?"
278
+ - Search by location: "Events in the Student Center"
279
+ - Find faculty events: "Show me Mathematics department events"
280
+ - Look for online events: "What virtual workshops are available?"
281
+ """)
282
+
283
+ return demo
284
 
285
  if __name__ == "__main__":
286
  demo = create_demo()