Spaces:
Running
Running
Updated UI
Browse files- .gitignore +2 -0
- .gradio/certificate.pem +31 -0
- Gradio_UI.py +84 -31
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
# Ignore Python cache directories
|
2 |
+
**/__pycache__/
|
.gradio/certificate.pem
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
-----BEGIN CERTIFICATE-----
|
2 |
+
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
|
3 |
+
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
|
4 |
+
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
|
5 |
+
WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
|
6 |
+
ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
|
7 |
+
MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc
|
8 |
+
h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+
|
9 |
+
0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U
|
10 |
+
A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW
|
11 |
+
T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm/ELNK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agEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc
|
27 |
+
oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq
|
28 |
+
4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA
|
29 |
+
mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
|
30 |
+
emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
|
31 |
+
-----END CERTIFICATE-----
|
Gradio_UI.py
CHANGED
@@ -22,7 +22,9 @@ from smolagents.agent_types import AgentAudio, AgentImage, AgentText, handle_age
|
|
22 |
from smolagents.agents import ActionStep, MultiStepAgent
|
23 |
from smolagents.memory import MemoryStep
|
24 |
from smolagents.utils import _is_package_available
|
25 |
-
|
|
|
|
|
26 |
|
27 |
def pull_messages_from_step(
|
28 |
step_log: MemoryStep,
|
@@ -257,38 +259,89 @@ class GradioUI:
|
|
257 |
"",
|
258 |
)
|
259 |
|
260 |
-
def launch(self, **kwargs):
|
261 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
286 |
text_input.submit(
|
287 |
-
self.
|
288 |
-
[text_input,
|
289 |
-
|
290 |
-
)
|
291 |
-
|
|
|
|
|
|
|
292 |
demo.launch(debug=True, share=True, **kwargs)
|
293 |
|
294 |
|
|
|
22 |
from smolagents.agents import ActionStep, MultiStepAgent
|
23 |
from smolagents.memory import MemoryStep
|
24 |
from smolagents.utils import _is_package_available
|
25 |
+
import gradio as gr
|
26 |
+
from gradio.components import Markdown
|
27 |
+
from gradio.components import Chatbot, Textbox, State, Button
|
28 |
|
29 |
def pull_messages_from_step(
|
30 |
step_log: MemoryStep,
|
|
|
259 |
"",
|
260 |
)
|
261 |
|
262 |
+
def launch(self, **kwargs): # <-- Moved inside the class and added self
|
263 |
+
with gr.Blocks("base") as demo:
|
264 |
+
# State to store chat messages and prompt strings
|
265 |
+
stored_messages = State([])
|
266 |
+
prompt_state = State("")
|
267 |
+
|
268 |
+
with gr.Row():
|
269 |
+
|
270 |
+
# Markdown Introduction
|
271 |
+
gr.Markdown("""
|
272 |
+
# NBAi - NBA Stats Chatbot 🏀
|
273 |
+
|
274 |
+
Welcome to **NBAi**, your personal NBA statistics assistant! This app fetches and presents NBA box scores from last night's games, giving you insights on player performance, team stats, and more.
|
275 |
+
|
276 |
+
## Features
|
277 |
+
- Ask questions like:
|
278 |
+
- Who had the most points last night?
|
279 |
+
- Who grabbed the most rebounds?
|
280 |
+
- Who had the highest assist-to-turnover ratio?
|
281 |
+
|
282 |
+
## Tools Used
|
283 |
+
- **[smolagents](https://github.com/huggingface/smolagents)** for building multi-step agents.
|
284 |
+
- **[Gradio](https://www.gradio.app/docs)** for the user interface.
|
285 |
+
- **[BeautifulSoup](https://www.crummy.com/software/BeautifulSoup/bs4/doc/)** and **[Pandas](https://pandas.pydata.org/docs/index.html)** for web scraping and data processing.
|
286 |
+
|
287 |
+
## How to Use
|
288 |
+
- Click one of the quick prompt buttons below or type your own question.
|
289 |
+
- The chatbot will respond with detailed NBA statistics from last night's games.
|
290 |
+
|
291 |
+
---
|
292 |
+
""")
|
293 |
+
with gr.Column():
|
294 |
+
# Chatbot Interface
|
295 |
+
chatbot = Chatbot(
|
296 |
+
label="NBAi Chatbot",
|
297 |
+
type="messages",
|
298 |
+
avatar_images=(
|
299 |
+
None,
|
300 |
+
"https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/communication/Alfred.png",
|
301 |
+
),
|
302 |
+
resizeable=True,
|
303 |
+
scale=1,
|
304 |
+
)
|
305 |
|
306 |
+
# Textbox for Custom User Input
|
307 |
+
text_input = Textbox(lines=1, label="Your Question")
|
308 |
+
# Quick Prompt Buttons
|
309 |
+
with gr.Row():
|
310 |
+
btn_points = Button(value="Most Points", variant="primary")
|
311 |
+
btn_rebounds = Button(value="Most Rebounds", variant="primary")
|
312 |
+
btn_assist_to_turnover = Button(value="Best Assist-to-Turnover Ratio", variant="primary")
|
313 |
+
|
314 |
+
|
315 |
+
|
316 |
+
# Bindings for Buttons using prompt_state
|
317 |
+
btn_points.click(
|
318 |
+
lambda: "Who had the most points in last night's NBA games?",
|
319 |
+
[],
|
320 |
+
prompt_state
|
321 |
+
).then(self.interact_with_agent, [prompt_state, stored_messages], chatbot)
|
322 |
+
|
323 |
+
btn_rebounds.click(
|
324 |
+
lambda: "Who had the most rebounds in last night's NBA games?",
|
325 |
+
[],
|
326 |
+
prompt_state
|
327 |
+
).then(self.interact_with_agent, [prompt_state, stored_messages], chatbot)
|
328 |
+
|
329 |
+
btn_assist_to_turnover.click(
|
330 |
+
lambda: "Who had the highest ratio of assists to turnovers in last night's NBA games?",
|
331 |
+
[],
|
332 |
+
prompt_state
|
333 |
+
).then(self.interact_with_agent, [prompt_state, stored_messages], chatbot)
|
334 |
+
|
335 |
+
# Custom Input Submission
|
336 |
text_input.submit(
|
337 |
+
self.interact_with_agent,
|
338 |
+
[text_input, stored_messages],
|
339 |
+
chatbot
|
340 |
+
)
|
341 |
+
|
342 |
+
|
343 |
+
|
344 |
+
|
345 |
demo.launch(debug=True, share=True, **kwargs)
|
346 |
|
347 |
|