ans123 commited on
Commit
0e6321c
·
verified ·
1 Parent(s): 1e4c863

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -1
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import gradio as gr
2
  import os
 
3
  from groq import Groq
4
 
5
  # Set up Groq API client
@@ -47,25 +48,68 @@ def real_time_tooltips(game_event):
47
  )
48
  return chat_completion.choices[0].message.content.strip()
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  # Gradio app interface
51
  def create_gradio_interface():
52
  with gr.Blocks() as demo:
53
- gr.Markdown("# Simplified MLB Fan Engagement App")
54
 
55
  with gr.Tab("Team Overview"):
56
  team_input = gr.Textbox(label="Enter Team Name")
57
  team_output = gr.Textbox(label="Team Overview")
 
 
58
  team_input.submit(get_team_overview, inputs=team_input, outputs=team_output)
 
 
 
 
 
59
 
60
  with gr.Tab("Season Predictions"):
61
  team_input_pred = gr.Textbox(label="Enter Team Name")
62
  predictions_output = gr.Textbox(label="Season Predictions")
 
 
63
  team_input_pred.submit(predict_season_outcomes, inputs=team_input_pred, outputs=predictions_output)
 
 
 
 
 
64
 
65
  with gr.Tab("Player Wildcards"):
66
  player_input = gr.Textbox(label="Enter Player Name")
67
  player_output = gr.Textbox(label="Player Highlights")
 
 
68
  player_input.submit(get_player_wildcards, inputs=player_input, outputs=player_output)
 
 
 
 
 
69
 
70
  with gr.Tab("Real-Time Strategy Insights"):
71
  game_event_input = gr.Textbox(
 
1
  import gradio as gr
2
  import os
3
+ import requests
4
  from groq import Groq
5
 
6
  # Set up Groq API client
 
48
  )
49
  return chat_completion.choices[0].message.content.strip()
50
 
51
+ # Function to fetch images and news for a team or player
52
+ def fetch_news(query):
53
+ url = "https://www.searchapi.io/api/v1/search"
54
+ params = {
55
+ "engine": "google",
56
+ "q": query,
57
+ "api_key": "PMjgK27a8Lyb6uMXP2jnSNnB", # Replace with your API key
58
+ }
59
+ try:
60
+ response = requests.get(url, params=params)
61
+ data = response.json()
62
+
63
+ # Extract news articles
64
+ news = "\n".join([f"{item['title']}: {item['link']}" for item in data.get("items", [])[:5]])
65
+
66
+ # Extract image URLs
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 with News and Images")
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(