Spaces:
Sleeping
Sleeping
File size: 4,010 Bytes
395f1d2 127b405 395f1d2 127b405 395f1d2 eda8825 395f1d2 eda8825 127b405 eda8825 127b405 eda8825 395f1d2 127b405 eda8825 395f1d2 eda8825 395f1d2 eda8825 395f1d2 eda8825 395f1d2 eda8825 395f1d2 eda8825 395f1d2 eda8825 395f1d2 eda8825 395f1d2 eda8825 395f1d2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
import gradio as gr
import os
from groq import Groq
from deep_translator import GoogleTranslator
# Set up Groq API client
client = Groq(
api_key=os.getenv("GROQ_API_KEY"), # Ensure you add this key to your environment variables
)
# Function to fetch team and player list from LLM (using Groq API)
def get_team_and_players():
chat_completion = client.chat.completions.create(
messages=[
{"role": "user", "content": "List all MLB teams and their top players."}
],
model="llama-3.3-70b-versatile", # You can adjust the model here
)
return chat_completion.choices[0].message.content.strip()
# Function to generate team overview
def get_team_overview(team):
chat_completion = client.chat.completions.create(
messages=[
{"role": "user", "content": f"Provide an overview of the {team} MLB team, including recent performance and standings."}
],
model="llama-3.3-70b-versatile",
)
return chat_completion.choices[0].message.content.strip()
# Function for season predictions
def predict_season_outcomes(team):
chat_completion = client.chat.completions.create(
messages=[
{"role": "user", "content": f"Predict the potential season outcomes for the {team} based on their current performance."}
],
model="llama-3.3-70b-versatile",
)
return chat_completion.choices[0].message.content.strip()
# Function for real-time strategy insights
def real_time_tooltips(game_event):
chat_completion = client.chat.completions.create(
messages=[
{"role": "user", "content": f"Explain the strategy behind the following baseball play: {game_event}"}
],
model="llama-3.3-70b-versatile",
)
return chat_completion.choices[0].message.content.strip()
# Gradio app interface
def create_gradio_interface():
with gr.Blocks() as demo:
gr.Markdown("# MLB Fan Engagement App")
with gr.Tab("Team and Player Selection"):
team_dropdown = gr.Dropdown(choices=[], label="Select Team")
player_dropdown = gr.Dropdown(choices=[], label="Select Player")
# Update teams and players dynamically using LLM
def update_teams_and_players():
team_and_players = get_team_and_players()
teams = team_and_players.split("\n") # Assuming each team is on a new line
team_dropdown.update(choices=teams)
return team_dropdown, player_dropdown
# Load teams and players when app starts
update_teams_and_players_button = gr.Button("Load Teams and Players")
update_teams_and_players_button.click(update_teams_and_players, inputs=[], outputs=[team_dropdown, player_dropdown])
with gr.Tab("Team Overview"):
team_dropdown_overview = gr.Dropdown(choices=[], label="Select Team")
overview_output = gr.Textbox(label="Team Overview")
team_dropdown_overview.change(
get_team_overview, inputs=team_dropdown_overview, outputs=overview_output
)
with gr.Tab("Season Predictions"):
team_dropdown_predictions = gr.Dropdown(choices=[], label="Select Team")
predictions_output = gr.Textbox(label="Season Predictions")
team_dropdown_predictions.change(
predict_season_outcomes, inputs=team_dropdown_predictions, outputs=predictions_output
)
with gr.Tab("Real-Time Strategy Insights"):
game_event_input = gr.Textbox(
label="Describe the game event (e.g., 'Why did the batter bunt in the 8th inning?')"
)
strategy_output = gr.Textbox(label="Strategy Explanation")
game_event_input.submit(real_time_tooltips, inputs=game_event_input, outputs=strategy_output)
demo.launch()
# Run the app
create_gradio_interface()
|