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 ) def get_highlight_summary(team, player, lang='en'): # Generate the highlight content highlight = f"Highlight of {player} from {team} in the latest game..." # Call Groq API for chat completions chat_completion = client.chat.completions.create( messages=[ {"role": "user", "content": f"Generate a highlight summary for: {highlight}"} ], model="llama-3.3-70b-versatile", # Specify the model to use ) # Extract the generated summary summary = chat_completion.choices[0].message.content.strip() # Translate summary if necessary if lang != 'en': summary = GoogleTranslator(source='auto', target=lang).translate(summary) return summary # Create Gradio Interface def create_gradio_interface(): with gr.Blocks() as demo: gr.Markdown("### Personalized MLB Highlights System") team_input = gr.Textbox(label="Enter your favorite team", placeholder="e.g., New York Yankees") player_input = gr.Textbox(label="Enter your favorite player", placeholder="e.g., Aaron Judge") lang_input = gr.Dropdown(choices=["en", "es", "ja"], label="Select language", value="en") output = gr.Textbox(label="Your Highlight Summary") submit_button = gr.Button("Generate Highlight") submit_button.click(get_highlight_summary, inputs=[team_input, player_input, lang_input], outputs=output) demo.launch() # Start the Gradio interface create_gradio_interface()