File size: 1,758 Bytes
395f1d2
 
127b405
 
395f1d2
127b405
 
 
 
395f1d2
 
127b405
395f1d2
 
127b405
 
 
 
 
 
395f1d2
127b405
 
 
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
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()