Baghdad99 commited on
Commit
cf0c6ae
1 Parent(s): a927d1d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -38
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 'error' key exists in the output
37
- if 'error' in output:
38
- print(f"Error: {output['error']}")
39
- estimated_time = output.get('estimated_time')
40
- if estimated_time:
41
- print(f"Estimated time for the model to load: {estimated_time} seconds")
42
- return
43
-
44
- # Check if 'text' key exists in the output
45
- if 'text' in output:
46
- transcription = output["text"]
 
 
47
  else:
48
- print("Key 'text' does not exist in the output.")
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,