Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -120,30 +120,9 @@ def process_speech(input_language, audio_input):
|
|
120 |
except Exception as e :
|
121 |
return f"{e}"
|
122 |
|
123 |
-
def translate_text(input_text, source_language, target_language):
|
124 |
-
"""
|
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(
|
@@ -158,9 +137,10 @@ def convert_text_to_speech(input_text, target_language):
|
|
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):
|
@@ -419,8 +399,7 @@ def process_and_query(input_language=None, audio_input=None, image_input=None, t
|
|
419 |
sources_info = vectara_response.get('sources', [])
|
420 |
|
421 |
|
422 |
-
|
423 |
-
audio_file_path = convert_text_to_speech(translated_response, input_language)
|
424 |
|
425 |
|
426 |
# Format Vectara response in Markdown
|
@@ -428,17 +407,14 @@ def process_and_query(input_language=None, audio_input=None, image_input=None, t
|
|
428 |
markdown_output += f"* **Summary**: {summary}\n"
|
429 |
markdown_output += "### Sources Information\n"
|
430 |
for source in sources_info:
|
431 |
-
markdown_output += f"* {source}\n"
|
432 |
|
433 |
# Process the summary with Stablemed
|
434 |
final_response = process_summary_with_stablemed(summary)
|
435 |
|
436 |
-
#
|
437 |
-
|
438 |
-
|
439 |
-
# Convert translated text to speech
|
440 |
-
audio_file_path = convert_text_to_speech(translated_response, input_language)
|
441 |
-
|
442 |
# Evaluate hallucination
|
443 |
hallucination_label = evaluate_hallucination(final_response, summary)
|
444 |
|
@@ -447,6 +423,8 @@ def process_and_query(input_language=None, audio_input=None, image_input=None, t
|
|
447 |
markdown_output += final_response + "\n"
|
448 |
markdown_output += "\n### Hallucination Evaluation\n"
|
449 |
markdown_output += f"* **Label**: {hallucination_label}\n"
|
|
|
|
|
450 |
|
451 |
return markdown_output, audio_file_path
|
452 |
|
|
|
120 |
except Exception as e :
|
121 |
return f"{e}"
|
122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
def convert_text_to_speech(input_text, target_language):
|
124 |
"""
|
125 |
+
Convert text to speech in the specified language and return both the audio file path and the input text.
|
126 |
"""
|
127 |
try:
|
128 |
text_to_speech_result = seamless_client.predict(
|
|
|
137 |
)
|
138 |
|
139 |
audio_file = text_to_speech_result[1] # Assuming the audio file path is in the second position
|
140 |
+
return audio_file, input_text
|
141 |
except Exception as e:
|
142 |
+
return f"An error occurred during text-to-speech conversion: {e}", input_text
|
143 |
+
|
144 |
|
145 |
def save_image(image_input, output_dir="saved_images"):
|
146 |
if not os.path.exists(output_dir):
|
|
|
399 |
sources_info = vectara_response.get('sources', [])
|
400 |
|
401 |
|
402 |
+
|
|
|
403 |
|
404 |
|
405 |
# Format Vectara response in Markdown
|
|
|
407 |
markdown_output += f"* **Summary**: {summary}\n"
|
408 |
markdown_output += "### Sources Information\n"
|
409 |
for source in sources_info:
|
410 |
+
markdown_output += f"* {source}\n""
|
411 |
|
412 |
# Process the summary with Stablemed
|
413 |
final_response = process_summary_with_stablemed(summary)
|
414 |
|
415 |
+
# Convert translated text to speech and get both audio file and text
|
416 |
+
audio_output, translated_text = convert_text_to_speech(translated_response, input_language)
|
417 |
+
|
|
|
|
|
|
|
418 |
# Evaluate hallucination
|
419 |
hallucination_label = evaluate_hallucination(final_response, summary)
|
420 |
|
|
|
423 |
markdown_output += final_response + "\n"
|
424 |
markdown_output += "\n### Hallucination Evaluation\n"
|
425 |
markdown_output += f"* **Label**: {hallucination_label}\n"
|
426 |
+
markdown_output += "\n### Translated Text\n"
|
427 |
+
markdown_output += translated_text + "\n
|
428 |
|
429 |
return markdown_output, audio_file_path
|
430 |
|