Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -48,7 +48,7 @@ def real_time_tooltips(game_event):
|
|
48 |
)
|
49 |
return chat_completion.choices[0].message.content.strip()
|
50 |
|
51 |
-
# Function to fetch images
|
52 |
def fetch_news_images(query):
|
53 |
url = "https://www.searchapi.io/api/v1/search"
|
54 |
params = {
|
@@ -59,57 +59,39 @@ def fetch_news_images(query):
|
|
59 |
try:
|
60 |
response = requests.get(url, params=params)
|
61 |
data = response.json()
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
images = [item["image"] for item in data.get("items", []) if "image" in item][:5]
|
68 |
-
|
69 |
-
return news, images
|
70 |
except Exception as e:
|
71 |
-
return f"Error fetching data: {e}"
|
72 |
|
73 |
# Gradio app interface
|
74 |
def create_gradio_interface():
|
75 |
with gr.Blocks() as demo:
|
76 |
-
gr.Markdown("# Enhanced MLB Fan Engagement App
|
77 |
|
78 |
with gr.Tab("Team Overview"):
|
79 |
team_input = gr.Textbox(label="Enter Team Name")
|
80 |
team_output = gr.Textbox(label="Team Overview")
|
81 |
-
team_news_output = gr.Textbox(label="Team News")
|
82 |
-
team_image_output = gr.Gallery(label="Team Images")
|
83 |
team_input.submit(get_team_overview, inputs=team_input, outputs=team_output)
|
84 |
-
team_input.submit(
|
85 |
-
fetch_news_images,
|
86 |
-
inputs=team_input,
|
87 |
-
outputs=[team_news_output, team_image_output],
|
88 |
-
)
|
89 |
|
90 |
with gr.Tab("Season Predictions"):
|
91 |
team_input_pred = gr.Textbox(label="Enter Team Name")
|
92 |
predictions_output = gr.Textbox(label="Season Predictions")
|
93 |
-
team_news_output_pred = gr.Textbox(label="Team News")
|
94 |
-
team_image_output_pred = gr.Gallery(label="Team gallery")
|
95 |
team_input_pred.submit(predict_season_outcomes, inputs=team_input_pred, outputs=predictions_output)
|
96 |
-
team_input_pred.submit(
|
97 |
-
fetch_news_images,
|
98 |
-
inputs=team_input_pred,
|
99 |
-
outputs=[team_news_output_pred, team_image_output_pred],
|
100 |
-
)
|
101 |
|
102 |
with gr.Tab("Player Wildcards"):
|
103 |
player_input = gr.Textbox(label="Enter Player Name")
|
104 |
player_output = gr.Textbox(label="Player Highlights")
|
105 |
-
player_news_output = gr.Textbox(label="Player News")
|
106 |
-
player_image_output = gr.Gallery(label="Player Gallery")
|
107 |
player_input.submit(get_player_wildcards, inputs=player_input, outputs=player_output)
|
108 |
-
player_input.submit(
|
109 |
-
fetch_news_images,
|
110 |
-
inputs=player_input,
|
111 |
-
outputs=[player_news_output, player_image_output],
|
112 |
-
)
|
113 |
|
114 |
with gr.Tab("Real-Time Strategy Insights"):
|
115 |
game_event_input = gr.Textbox(
|
|
|
48 |
)
|
49 |
return chat_completion.choices[0].message.content.strip()
|
50 |
|
51 |
+
# Function to fetch images or news for a team/player
|
52 |
def fetch_news_images(query):
|
53 |
url = "https://www.searchapi.io/api/v1/search"
|
54 |
params = {
|
|
|
59 |
try:
|
60 |
response = requests.get(url, params=params)
|
61 |
data = response.json()
|
62 |
+
if "items" in data:
|
63 |
+
news = "\n".join([f"{item['title']}: {item['link']}" for item in data["items"][:5]])
|
64 |
+
return news
|
65 |
+
else:
|
66 |
+
return "No news or images found for this query."
|
|
|
|
|
|
|
67 |
except Exception as e:
|
68 |
+
return f"Error fetching data: {e}"
|
69 |
|
70 |
# Gradio app interface
|
71 |
def create_gradio_interface():
|
72 |
with gr.Blocks() as demo:
|
73 |
+
gr.Markdown("# Enhanced MLB Fan Engagement App")
|
74 |
|
75 |
with gr.Tab("Team Overview"):
|
76 |
team_input = gr.Textbox(label="Enter Team Name")
|
77 |
team_output = gr.Textbox(label="Team Overview")
|
78 |
+
team_news_output = gr.Textbox(label="Team News and Images")
|
|
|
79 |
team_input.submit(get_team_overview, inputs=team_input, outputs=team_output)
|
80 |
+
team_input.submit(fetch_news_images, inputs=team_input, outputs=team_news_output)
|
|
|
|
|
|
|
|
|
81 |
|
82 |
with gr.Tab("Season Predictions"):
|
83 |
team_input_pred = gr.Textbox(label="Enter Team Name")
|
84 |
predictions_output = gr.Textbox(label="Season Predictions")
|
85 |
+
team_news_output_pred = gr.Textbox(label="Team News and Images")
|
|
|
86 |
team_input_pred.submit(predict_season_outcomes, inputs=team_input_pred, outputs=predictions_output)
|
87 |
+
team_input_pred.submit(fetch_news_images, inputs=team_input_pred, outputs=team_news_output_pred)
|
|
|
|
|
|
|
|
|
88 |
|
89 |
with gr.Tab("Player Wildcards"):
|
90 |
player_input = gr.Textbox(label="Enter Player Name")
|
91 |
player_output = gr.Textbox(label="Player Highlights")
|
92 |
+
player_news_output = gr.Textbox(label="Player News and Images")
|
|
|
93 |
player_input.submit(get_player_wildcards, inputs=player_input, outputs=player_output)
|
94 |
+
player_input.submit(fetch_news_images, inputs=player_input, outputs=player_news_output)
|
|
|
|
|
|
|
|
|
95 |
|
96 |
with gr.Tab("Real-Time Strategy Insights"):
|
97 |
game_event_input = gr.Textbox(
|