Update app.py
Browse files
app.py
CHANGED
@@ -18,6 +18,10 @@ image_pipeline.to(device)
|
|
18 |
|
19 |
# --- Step 1: Transcribe Tamil Audio using Groq's whisper-large-v3 ---
|
20 |
def transcribe_tamil_audio(audio):
|
|
|
|
|
|
|
|
|
21 |
filename = "temp_audio.m4a"
|
22 |
|
23 |
try:
|
@@ -27,14 +31,18 @@ def transcribe_tamil_audio(audio):
|
|
27 |
print("Audio loading error:", str(e))
|
28 |
return "⚠️ Failed to process audio. Please try uploading a different file."
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
38 |
|
39 |
# --- Step 2: Translate using gemma2-9b-it ---
|
40 |
def translate_tamil_to_english(tamil_text):
|
|
|
18 |
|
19 |
# --- Step 1: Transcribe Tamil Audio using Groq's whisper-large-v3 ---
|
20 |
def transcribe_tamil_audio(audio):
|
21 |
+
if not audio or not os.path.exists(audio):
|
22 |
+
print("Audio path is invalid or file does not exist.")
|
23 |
+
return "⚠️ Failed to process audio. Please try uploading a different file."
|
24 |
+
|
25 |
filename = "temp_audio.m4a"
|
26 |
|
27 |
try:
|
|
|
31 |
print("Audio loading error:", str(e))
|
32 |
return "⚠️ Failed to process audio. Please try uploading a different file."
|
33 |
|
34 |
+
try:
|
35 |
+
with open(filename, "rb") as file:
|
36 |
+
transcription = client.audio.transcriptions.create(
|
37 |
+
file=(filename, file.read()),
|
38 |
+
model="whisper-large-v3",
|
39 |
+
language="ta",
|
40 |
+
response_format="verbose_json",
|
41 |
+
)
|
42 |
+
return transcription.text
|
43 |
+
except Exception as e:
|
44 |
+
print("Transcription error:", str(e))
|
45 |
+
return "⚠️ Failed to transcribe audio."
|
46 |
|
47 |
# --- Step 2: Translate using gemma2-9b-it ---
|
48 |
def translate_tamil_to_english(tamil_text):
|