Tonic commited on
Commit
cfcb504
·
1 Parent(s): 5dc0043

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -23
app.py CHANGED
@@ -139,6 +139,10 @@ def convert_text_to_speech(input_text, source_language, target_language):
139
  api_name="/run" # API name
140
  )
141
 
 
 
 
 
142
  # Check if result contains files
143
  if isinstance(result, list) and len(result) > 1:
144
  downloaded_files = []
@@ -155,37 +159,22 @@ def convert_text_to_speech(input_text, source_language, target_language):
155
  new_file_name = f"audio_output_{uuid.uuid4()}.wav"
156
  new_file_path = os.path.join(os.path.dirname(original_audio_file), new_file_name)
157
  os.rename(original_audio_file, new_file_path)
158
- return new_file_path
159
- else:
160
- return "No valid audio files were downloaded."
161
 
162
- else:
163
- return "No audio files received from the API."
164
-
165
- # Iterate over the result to find the last text item
166
- translated_text = ""
167
- for item in result:
168
- if isinstance(item, str):
169
- translated_text = item
170
-
171
- if original_audio_file:
172
- # Generate a new file name with a random UUID
173
- new_file_name = f"audio_output_{uuid.uuid4()}.wav"
174
- new_file_path = os.path.join(os.path.dirname(original_audio_file), new_file_name)
175
-
176
- # Rename the file
177
- os.rename(original_audio_file, new_file_path)
178
 
179
- return new_file_path, translated_text
180
- else:
181
- return "No audio file generated.", translated_text
182
  else:
183
- return "Unexpected result format or insufficient data received.", ""
184
 
185
  except Exception as e:
186
  # Return a concise error message
187
  return f"Error in text-to-speech conversion: {str(e)}", ""
188
 
 
189
 
190
  def process_image(image_input):
191
  # Initialize the Gradio client with the URL of the Gradio server
 
139
  api_name="/run" # API name
140
  )
141
 
142
+ # Initialize variables
143
+ original_audio_file = None
144
+ translated_text = ""
145
+
146
  # Check if result contains files
147
  if isinstance(result, list) and len(result) > 1:
148
  downloaded_files = []
 
159
  new_file_name = f"audio_output_{uuid.uuid4()}.wav"
160
  new_file_path = os.path.join(os.path.dirname(original_audio_file), new_file_name)
161
  os.rename(original_audio_file, new_file_path)
 
 
 
162
 
163
+ # Iterate over the result to find the last text item
164
+ for item in result:
165
+ if isinstance(item, str):
166
+ translated_text = item
 
 
 
 
 
 
 
 
 
 
 
 
167
 
168
+ if original_audio_file:
169
+ return new_file_path, translated_text
 
170
  else:
171
+ return "No valid audio file generated.", translated_text
172
 
173
  except Exception as e:
174
  # Return a concise error message
175
  return f"Error in text-to-speech conversion: {str(e)}", ""
176
 
177
+ return "Unexpected result format or insufficient data received.", ""
178
 
179
  def process_image(image_input):
180
  # Initialize the Gradio client with the URL of the Gradio server