Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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
|
161 |
"""
|
162 |
try:
|
163 |
-
#
|
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 |
-
|
|
|
175 |
|
176 |
-
#
|
177 |
-
|
178 |
-
|
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}")
|