Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,44 +1,40 @@
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
from groq import Groq
|
4 |
-
from deep_translator import GoogleTranslator
|
5 |
|
6 |
# Set up Groq API client
|
7 |
client = Groq(
|
8 |
api_key=os.getenv("GROQ_API_KEY"), # Ensure you add this key to your environment variables
|
9 |
)
|
10 |
|
11 |
-
# Function to fetch team
|
12 |
-
def
|
13 |
chat_completion = client.chat.completions.create(
|
14 |
messages=[
|
15 |
-
{"role": "user", "content": "
|
16 |
],
|
17 |
-
model="llama-3.3-70b-versatile",
|
18 |
)
|
19 |
-
|
20 |
return chat_completion.choices[0].message.content.strip()
|
21 |
|
22 |
-
# Function to
|
23 |
-
def
|
24 |
chat_completion = client.chat.completions.create(
|
25 |
messages=[
|
26 |
-
{"role": "user", "content": f"
|
27 |
],
|
28 |
model="llama-3.3-70b-versatile",
|
29 |
)
|
30 |
-
|
31 |
return chat_completion.choices[0].message.content.strip()
|
32 |
|
33 |
-
# Function for
|
34 |
-
def
|
35 |
chat_completion = client.chat.completions.create(
|
36 |
messages=[
|
37 |
-
{"role": "user", "content": f"
|
38 |
],
|
39 |
model="llama-3.3-70b-versatile",
|
40 |
)
|
41 |
-
|
42 |
return chat_completion.choices[0].message.content.strip()
|
43 |
|
44 |
# Function for real-time strategy insights
|
@@ -49,42 +45,27 @@ def real_time_tooltips(game_event):
|
|
49 |
],
|
50 |
model="llama-3.3-70b-versatile",
|
51 |
)
|
52 |
-
|
53 |
return chat_completion.choices[0].message.content.strip()
|
54 |
|
55 |
# Gradio app interface
|
56 |
def create_gradio_interface():
|
57 |
with gr.Blocks() as demo:
|
58 |
-
gr.Markdown("# MLB Fan Engagement App")
|
59 |
-
|
60 |
-
with gr.Tab("Team and Player Selection"):
|
61 |
-
team_dropdown = gr.Dropdown(choices=[], label="Select Team")
|
62 |
-
player_dropdown = gr.Dropdown(choices=[], label="Select Player")
|
63 |
-
|
64 |
-
# Update teams and players dynamically using LLM
|
65 |
-
def update_teams_and_players():
|
66 |
-
team_and_players = get_team_and_players()
|
67 |
-
teams = team_and_players.split("\n") # Assuming each team is on a new line
|
68 |
-
team_dropdown.update(choices=teams)
|
69 |
-
return team_dropdown, player_dropdown
|
70 |
-
|
71 |
-
# Load teams and players when app starts
|
72 |
-
update_teams_and_players_button = gr.Button("Load Teams and Players")
|
73 |
-
update_teams_and_players_button.click(update_teams_and_players, inputs=[], outputs=[team_dropdown, player_dropdown])
|
74 |
|
75 |
with gr.Tab("Team Overview"):
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
get_team_overview, inputs=team_dropdown_overview, outputs=overview_output
|
80 |
-
)
|
81 |
|
82 |
with gr.Tab("Season Predictions"):
|
83 |
-
|
84 |
predictions_output = gr.Textbox(label="Season Predictions")
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
|
|
|
|
88 |
|
89 |
with gr.Tab("Real-Time Strategy Insights"):
|
90 |
game_event_input = gr.Textbox(
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
from groq import Groq
|
|
|
4 |
|
5 |
# Set up Groq API client
|
6 |
client = Groq(
|
7 |
api_key=os.getenv("GROQ_API_KEY"), # Ensure you add this key to your environment variables
|
8 |
)
|
9 |
|
10 |
+
# Function to fetch team overview
|
11 |
+
def get_team_overview(team):
|
12 |
chat_completion = client.chat.completions.create(
|
13 |
messages=[
|
14 |
+
{"role": "user", "content": f"Provide an overview of the {team} MLB team, including recent performance and standings."}
|
15 |
],
|
16 |
+
model="llama-3.3-70b-versatile",
|
17 |
)
|
|
|
18 |
return chat_completion.choices[0].message.content.strip()
|
19 |
|
20 |
+
# Function to predict season outcomes
|
21 |
+
def predict_season_outcomes(team):
|
22 |
chat_completion = client.chat.completions.create(
|
23 |
messages=[
|
24 |
+
{"role": "user", "content": f"Predict the potential season outcomes for the {team} based on their current performance."}
|
25 |
],
|
26 |
model="llama-3.3-70b-versatile",
|
27 |
)
|
|
|
28 |
return chat_completion.choices[0].message.content.strip()
|
29 |
|
30 |
+
# Function for player wildcards
|
31 |
+
def get_player_wildcards(player):
|
32 |
chat_completion = client.chat.completions.create(
|
33 |
messages=[
|
34 |
+
{"role": "user", "content": f"Describe any standout performances or recent achievements for the player {player} in MLB."}
|
35 |
],
|
36 |
model="llama-3.3-70b-versatile",
|
37 |
)
|
|
|
38 |
return chat_completion.choices[0].message.content.strip()
|
39 |
|
40 |
# Function for real-time strategy insights
|
|
|
45 |
],
|
46 |
model="llama-3.3-70b-versatile",
|
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(
|