Update app.py
Browse files
app.py
CHANGED
@@ -23,7 +23,6 @@ def query(api_url, payload=None, data=None):
|
|
23 |
return None
|
24 |
return response_json
|
25 |
|
26 |
-
|
27 |
# Define the function to translate speech
|
28 |
def translate_speech(audio_file):
|
29 |
print(f"Type of audio: {type(audio_file)}, Value of audio: {audio_file}") # Debug line
|
@@ -33,19 +32,21 @@ def translate_speech(audio_file):
|
|
33 |
output = query(ASR_API_URL, data=data)
|
34 |
print(f"Output: {output}") # Debug line
|
35 |
|
36 |
-
# Check if
|
37 |
-
if
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
47 |
else:
|
48 |
-
print("
|
49 |
return
|
50 |
|
51 |
# Use the translation pipeline to translate the transcription
|
@@ -58,31 +59,6 @@ def translate_speech(audio_file):
|
|
58 |
# Display the audio output
|
59 |
return Audio(audio_bytes)
|
60 |
|
61 |
-
# print(f"Type of audio: {type(audio_file)}, Value of audio: {audio_file}") # Debug line
|
62 |
-
|
63 |
-
# # Use the ASR pipeline to transcribe the audio
|
64 |
-
# data = audio_file.read()
|
65 |
-
# output = query(ASR_API_URL, data=data)
|
66 |
-
# print(f"Output: {output}") # Debug line
|
67 |
-
|
68 |
-
# # Check if 'text' key exists in the output
|
69 |
-
# if 'text' in output:
|
70 |
-
# transcription = output["text"]
|
71 |
-
# else:
|
72 |
-
# print("Key 'text' does not exist in the output.")
|
73 |
-
# return
|
74 |
-
|
75 |
-
# # Use the translation pipeline to translate the transcription
|
76 |
-
# translated_text = query(TRANSLATION_API_URL, {"inputs": transcription})
|
77 |
-
|
78 |
-
# # Use the TTS pipeline to synthesize the translated text
|
79 |
-
# response = requests.post(TTS_API_URL, headers=headers, json={"inputs": translated_text})
|
80 |
-
# audio_bytes = response.content
|
81 |
-
|
82 |
-
# # Display the audio output
|
83 |
-
# return Audio(audio_bytes)
|
84 |
-
|
85 |
-
|
86 |
# Define the Gradio interface
|
87 |
iface = gr.Interface(
|
88 |
fn=translate_speech,
|
|
|
23 |
return None
|
24 |
return response_json
|
25 |
|
|
|
26 |
# Define the function to translate speech
|
27 |
def translate_speech(audio_file):
|
28 |
print(f"Type of audio: {type(audio_file)}, Value of audio: {audio_file}") # Debug line
|
|
|
32 |
output = query(ASR_API_URL, data=data)
|
33 |
print(f"Output: {output}") # Debug line
|
34 |
|
35 |
+
# Check if output is not None
|
36 |
+
if output is not None:
|
37 |
+
# Check if 'error' key exists in the output
|
38 |
+
if 'error' in output:
|
39 |
+
print(f"Error: {output['error']}")
|
40 |
+
return
|
41 |
+
|
42 |
+
# Check if 'text' key exists in the output
|
43 |
+
if 'text' in output:
|
44 |
+
transcription = output["text"]
|
45 |
+
else:
|
46 |
+
print("Key 'text' does not exist in the output.")
|
47 |
+
return
|
48 |
else:
|
49 |
+
print("Output is None.")
|
50 |
return
|
51 |
|
52 |
# Use the translation pipeline to translate the transcription
|
|
|
59 |
# Display the audio output
|
60 |
return Audio(audio_bytes)
|
61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
# Define the Gradio interface
|
63 |
iface = gr.Interface(
|
64 |
fn=translate_speech,
|