Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -125,39 +125,43 @@ def translate_text(input_text, source_language, target_language):
|
|
| 125 |
Translate text from one language to another.
|
| 126 |
"""
|
| 127 |
try:
|
| 128 |
-
# Adjusting the parameters according to the successful API call
|
| 129 |
text_translation_result = seamless_client.predict(
|
| 130 |
-
"T2TT
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
input_text
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
)
|
| 135 |
|
| 136 |
-
# Assuming the
|
| 137 |
-
translated_text = text_translation_result
|
| 138 |
return translated_text
|
| 139 |
except Exception as e:
|
| 140 |
return f"An error occurred during translation: {e}"
|
| 141 |
|
| 142 |
-
def convert_text_to_speech(input_text,
|
| 143 |
"""
|
| 144 |
Convert text to speech in the specified language.
|
| 145 |
"""
|
| 146 |
try:
|
| 147 |
-
# Adjusting the parameters according to the successful API call
|
| 148 |
text_to_speech_result = seamless_client.predict(
|
| 149 |
-
"T2ST
|
| 150 |
-
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
)
|
| 153 |
|
| 154 |
-
# Assuming the
|
| 155 |
-
audio_file = text_to_speech_result
|
| 156 |
return audio_file
|
| 157 |
except Exception as e:
|
| 158 |
return f"An error occurred during text-to-speech conversion: {e}"
|
| 159 |
|
| 160 |
-
|
| 161 |
def save_image(image_input, output_dir="saved_images"):
|
| 162 |
if not os.path.exists(output_dir):
|
| 163 |
os.makedirs(output_dir)
|
|
|
|
| 125 |
Translate text from one language to another.
|
| 126 |
"""
|
| 127 |
try:
|
|
|
|
| 128 |
text_translation_result = seamless_client.predict(
|
| 129 |
+
"T2TT", # Task: Text to Text Translation
|
| 130 |
+
"text", # Input type
|
| 131 |
+
None, # No file input for text translation
|
| 132 |
+
input_text, # Input text
|
| 133 |
+
"", # Empty string for audio name
|
| 134 |
+
source_language, # Source language
|
| 135 |
+
target_language, # Target language
|
| 136 |
+
api_name="/run" # API name
|
| 137 |
)
|
| 138 |
|
| 139 |
+
translated_text = text_translation_result[1] # Assuming the result is in the second position
|
|
|
|
| 140 |
return translated_text
|
| 141 |
except Exception as e:
|
| 142 |
return f"An error occurred during translation: {e}"
|
| 143 |
|
| 144 |
+
def convert_text_to_speech(input_text, target_language):
|
| 145 |
"""
|
| 146 |
Convert text to speech in the specified language.
|
| 147 |
"""
|
| 148 |
try:
|
|
|
|
| 149 |
text_to_speech_result = seamless_client.predict(
|
| 150 |
+
"T2ST", # Task: Text to Speech Translation
|
| 151 |
+
"text", # Input type
|
| 152 |
+
None, # No file input for text to speech
|
| 153 |
+
input_text, # Input text
|
| 154 |
+
"", # Empty string for audio name
|
| 155 |
+
"", # Empty string for source language, as it's not needed here
|
| 156 |
+
target_language, # Target language
|
| 157 |
+
api_name="/run" # API name
|
| 158 |
)
|
| 159 |
|
| 160 |
+
audio_file = text_to_speech_result[1] # Assuming the audio file path is in the second position
|
|
|
|
| 161 |
return audio_file
|
| 162 |
except Exception as e:
|
| 163 |
return f"An error occurred during text-to-speech conversion: {e}"
|
| 164 |
|
|
|
|
| 165 |
def save_image(image_input, output_dir="saved_images"):
|
| 166 |
if not os.path.exists(output_dir):
|
| 167 |
os.makedirs(output_dir)
|