ans123 commited on
Commit
127b405
·
verified ·
1 Parent(s): ef2a8f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -15
app.py CHANGED
@@ -1,26 +1,27 @@
1
  import gradio as gr
2
- import openai
3
- import requests
4
- from deep_translator import GoogleTranslator
5
  import os
 
 
6
 
7
- # Set up OpenAI API key from environment variables
8
- openai.api_key = os.getenv("OPENAI_API_KEY")
9
-
10
- # MLB API endpoint (mocked, replace with actual MLB API endpoint)
11
- MLB_API_URL = "https://api.mlb.com/v1/games/" # Example; replace with actual URL
12
 
13
  def get_highlight_summary(team, player, lang='en'):
14
- # Fetch game data from MLB API (this is a mockup)
15
  highlight = f"Highlight of {player} from {team} in the latest game..."
16
 
17
- # Generate a summary with OpenAI API
18
- response = openai.Completion.create(
19
- engine="text-davinci-003",
20
- prompt=f"Generate a highlight summary for: {highlight}",
21
- max_tokens=100
 
22
  )
23
- summary = response.choices[0].text.strip()
 
 
24
 
25
  # Translate summary if necessary
26
  if lang != 'en':
 
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
  def get_highlight_summary(team, player, lang='en'):
12
+ # Generate the highlight content
13
  highlight = f"Highlight of {player} from {team} in the latest game..."
14
 
15
+ # Call Groq API for chat completions
16
+ chat_completion = client.chat.completions.create(
17
+ messages=[
18
+ {"role": "user", "content": f"Generate a highlight summary for: {highlight}"}
19
+ ],
20
+ model="llama-3.3-70b-versatile", # Specify the model to use
21
  )
22
+
23
+ # Extract the generated summary
24
+ summary = chat_completion.choices[0].message.content.strip()
25
 
26
  # Translate summary if necessary
27
  if lang != 'en':