Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -19,6 +19,7 @@ def query(api_url, payload=None, data=None):
|
|
19 |
response = requests.post(api_url, headers=headers, json=payload)
|
20 |
return response.json()
|
21 |
|
|
|
22 |
# Define the function to translate speech
|
23 |
def translate_speech(audio_file):
|
24 |
print(f"Type of audio: {type(audio_file)}, Value of audio: {audio_file}") # Debug line
|
@@ -26,7 +27,14 @@ def translate_speech(audio_file):
|
|
26 |
# Use the ASR pipeline to transcribe the audio
|
27 |
data = audio_file.read()
|
28 |
output = query(ASR_API_URL, data=data)
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
# Use the translation pipeline to translate the transcription
|
32 |
translated_text = query(TRANSLATION_API_URL, {"inputs": transcription})
|
@@ -38,6 +46,7 @@ def translate_speech(audio_file):
|
|
38 |
# Display the audio output
|
39 |
return Audio(audio_bytes)
|
40 |
|
|
|
41 |
# Define the Gradio interface
|
42 |
iface = gr.Interface(
|
43 |
fn=translate_speech,
|
|
|
19 |
response = requests.post(api_url, headers=headers, json=payload)
|
20 |
return response.json()
|
21 |
|
22 |
+
# Define the function to translate speech
|
23 |
# Define the function to translate speech
|
24 |
def translate_speech(audio_file):
|
25 |
print(f"Type of audio: {type(audio_file)}, Value of audio: {audio_file}") # Debug line
|
|
|
27 |
# Use the ASR pipeline to transcribe the audio
|
28 |
data = audio_file.read()
|
29 |
output = query(ASR_API_URL, data=data)
|
30 |
+
print(f"Output: {output}") # Debug line
|
31 |
+
|
32 |
+
# Check if 'text' key exists in the output
|
33 |
+
if 'text' in output:
|
34 |
+
transcription = output["text"]
|
35 |
+
else:
|
36 |
+
print("Key 'text' does not exist in the output.")
|
37 |
+
return
|
38 |
|
39 |
# Use the translation pipeline to translate the transcription
|
40 |
translated_text = query(TRANSLATION_API_URL, {"inputs": transcription})
|
|
|
46 |
# Display the audio output
|
47 |
return Audio(audio_bytes)
|
48 |
|
49 |
+
|
50 |
# Define the Gradio interface
|
51 |
iface = gr.Interface(
|
52 |
fn=translate_speech,
|