Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
223 |
-
"""Create
|
224 |
-
|
225 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
235 |
-
layout="bubble"
|
236 |
)
|
237 |
|
238 |
-
|
239 |
-
|
240 |
-
|
|
|
|
|
|
|
|
|
241 |
|
242 |
-
|
243 |
-
|
244 |
-
"
|
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 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
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()
|