Adeenakk commited on
Commit
493b233
1 Parent(s): cd18061

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -14
app.py CHANGED
@@ -6,13 +6,10 @@ import requests
6
  from gtts import gTTS
7
  from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq
8
  from pydub import AudioSegment
9
- from groq import Groq
10
 
11
- RAPIDAPI_KEY = "0875969c18mshea4b5d106303222p197cb2jsnd47e91b7da30"
12
- GROQ_API_KEY = "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"
13
-
14
- # Initialize the Groq client
15
- client = Groq(api_key=GROQ_API_KEY)
16
 
17
  # Load the Whisper model
18
  processor = AutoProcessor.from_pretrained("ihanif/whisper-medium-urdu")
@@ -61,15 +58,22 @@ def process_audio(file_path):
61
  urdu_to_eng = translate("en", text)
62
  print(f"Translated Text (English): {urdu_to_eng}") # Debugging step
63
 
64
- # Generate a response using Groq
65
- chat_completion = client.chat.completions.create(
66
- messages=[{"role": "user", "content": urdu_to_eng}],
67
- model="llama3-8b-8192", # Ensure the model supports Urdu if possible
68
- max_tokens=50
69
- )
 
 
 
 
 
 
 
70
 
71
- # Access the response using dot notation
72
- response_message = chat_completion.choices[0].message.content.strip()
73
  print(f"Groq Response (English): {response_message}") # Debugging step
74
 
75
  # Translate the response text back to Urdu
 
6
  from gtts import gTTS
7
  from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq
8
  from pydub import AudioSegment
 
9
 
10
+ # Load environment variables for API keys
11
+ RAPIDAPI_KEY = os.getenv('RAPIDAPI_LANG_TRANS')
12
+ GROQ_API_KEY = os.getenv('GROQ_API_KEY')
 
 
13
 
14
  # Load the Whisper model
15
  processor = AutoProcessor.from_pretrained("ihanif/whisper-medium-urdu")
 
58
  urdu_to_eng = translate("en", text)
59
  print(f"Translated Text (English): {urdu_to_eng}") # Debugging step
60
 
61
+ # Make API call to Groq
62
+ groq_url = "https://api.groq.com/your-endpoint" # Replace with actual Groq API endpoint
63
+ groq_headers = {
64
+ "Authorization": f"Bearer {GROQ_API_KEY}",
65
+ "Content-Type": "application/json"
66
+ }
67
+ groq_payload = {
68
+ "messages": [{"role": "user", "content": urdu_to_eng}],
69
+ "model": "llama3-8b-8192", # Adjust model if needed
70
+ "max_tokens": 50
71
+ }
72
+ response = requests.post(groq_url, json=groq_payload, headers=groq_headers)
73
+ chat_completion = response.json()
74
 
75
+ # Access the response
76
+ response_message = chat_completion["choices"][0]["message"]["content"].strip()
77
  print(f"Groq Response (English): {response_message}") # Debugging step
78
 
79
  # Translate the response text back to Urdu