Update app.py
Browse files
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 |
-
|
12 |
-
|
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 |
-
#
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
-
# Access the response
|
72 |
-
response_message = chat_completion
|
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
|