Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
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 |
-
|
246 |
-
|
247 |
-
|
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 |
-
#
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
|
|
|
|
|
|
|
|
274 |
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
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 |
+
)
|