Tonic commited on
Commit
dd7db97
·
verified ·
1 Parent(s): ae30651

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -7
app.py CHANGED
@@ -155,12 +155,13 @@ def process_audio_to_text(audio_path, inputlanguage="English", outputlanguage="E
155
  return result[0]
156
 
157
 
 
158
  def process_text_to_audio(text, translatefrom="English", translateto="English"):
159
  """
160
- Convert text input to audio using the Gradio client and return the local file path of the generated audio.
161
  """
162
  try:
163
- # Call the client's predict method with the text, source language, and target language
164
  result = audio_client.predict(
165
  text,
166
  translatefrom,
@@ -171,13 +172,22 @@ def process_text_to_audio(text, translatefrom="English", translateto="English"):
171
  if not isinstance(result, tuple) or len(result) < 2:
172
  raise ValueError("Unexpected result format from audio_client.predict")
173
 
174
- audio_file_path, _ = result # Ignore the translated text for this function's purpose
 
175
 
176
- # Assuming the audio file is stored in a publicly accessible location
177
- # Append the base URL to the audio file path
178
- base_url = "https://multitransformer-ayatonic.hf.space/"
179
- audio_url = os.path.join(base_url, file_name) # Use os.path.join to handle any path issues
180
 
 
 
 
 
 
 
 
 
 
181
  return audio_url
182
  except Exception as e:
183
  print(f"Error processing text to audio: {e}")
 
155
  return result[0]
156
 
157
 
158
+
159
  def process_text_to_audio(text, translatefrom="English", translateto="English"):
160
  """
161
+ Convert text input to audio using the Gradio client and return a URL to the generated audio.
162
  """
163
  try:
164
+ # Assuming audio_client.predict is correctly set up and returns a tuple (local_file_path, translated_text)
165
  result = audio_client.predict(
166
  text,
167
  translatefrom,
 
172
  if not isinstance(result, tuple) or len(result) < 2:
173
  raise ValueError("Unexpected result format from audio_client.predict")
174
 
175
+ # Extract the local file path from the result
176
+ local_file_path, _ = result
177
 
178
+ # Ensure that local_file_path points to a file, not a directory
179
+ if not os.path.isfile(local_file_path):
180
+ raise ValueError(f"The path does not point to a valid file: {local_file_path}")
 
181
 
182
+ # Extract the file name from the local_file_path
183
+ file_name = os.path.basename(local_file_path)
184
+
185
+ # Construct the URL by appending the file name to the base URL
186
+ base_url = "https://multitransformer-ayatonic.hf.space/"
187
+ audio_url = os.path.join(base_url, file_name) # This might need adjustment based on how your server serves files
188
+
189
+ audio_url = f"{base_url}{file_name}"
190
+
191
  return audio_url
192
  except Exception as e:
193
  print(f"Error processing text to audio: {e}")