Spaces:
Runtime error
Runtime error
Update app.py
Browse files119 unmodified lines1201211221231241251261271281291301311321331341351361371381391401411421431441451461471481498 unmodified lines158159160161162163164165166252 unmodified lines4194204214224234244254261 unmodified line4284294304314324334344354364374384394404414424434442 unmodified lines447448449450451452119 unmodified linesexcept Exception as e :return f"{e}"def translate_text(input_text, source_language, target_language):"""Translate text from one language to another."""try:text_translation_result = seamless_client.predict("T2TT", # Task: Text to Text Translation"text", # Input typeNone, # No file input for text translationinput_text, # Input text"", # Empty string for audio namesource_language, # Source languagetarget_language, # Target languageapi_name="/run" # API name)translated_text = text_translation_result[1] # Assuming the result is in the second positionreturn translated_textexcept Exception as e:return f"An error occurred during translation: {e}"def convert_text_to_speech(input_text, target_language):"""Convert text to speech in the specified language."""try:text_to_speech_result = seamless_client.predict(8 unmodified lines)audio_file = text_to_speech_result[1] # Assuming the audio file path is in the second positionreturn audio_fileexcept Exception as e:return f"An error occurred during text-to-speech conversion: {e}"def save_image(image_input, output_dir="saved_images"):if not os.path.exists(output_dir):252 unmodified linessources_info = vectara_response.get('sources', [])# Convert translated text to speechaudio_file_path = convert_text_to_speech(translated_response, input_language)# Format Vectara response in Markdown1 unmodified linemarkdown_output += f"* **Summary**: {summary}\n"markdown_output += "### Sources Information\n"for source in sources_info:markdown_output += f"* {source}\n"# Process the summary with Stablemedfinal_response = process_summary_with_stablemed(summary)# Translate the final responsetranslated_response = translate_text(final_response, input_language, input_language)# Convert translated text to speechaudio_file_path = convert_text_to_speech(translated_response, input_language)# Evaluate hallucinationhallucination_label = evaluate_hallucination(final_response, summary)2 unmodified linesmarkdown_output += final_response + "\n"markdown_output += "\n### Hallucination Evaluation\n"markdown_output += f"* **Label**: {hallucination_label}\n"return markdown_output, audio_file_path119 unmodified lines1201211221231241251261271288 unmodified lines137138139140141142143144145146252 unmodified lines3994004014024034044051 unmodified line4074084094104114124134144154164174184194202 unmodified lines423424425426427428429430119 unmodified linesexcept Exception as e :return f"{e}"def convert_text_to_speech(input_text, target_language):"""Convert text to speech in the specified language and return both the audio file path and the input text."""try:text_to_speech_result = seamless_client.predict(8 unmodified lines)audio_file = text_to_speech_result[1] # Assuming the audio file path is in the second positionreturn audio_file, input_textexcept Exception as e:return f"An error occurred during text-to-speech conversion: {e}", input_textdef save_image(image_input, output_dir="saved_images"):if not os.path.exists(output_dir):252 unmodified linessources_info = vectara_response.get('sources', [])# Format Vectara response in Markdown1 unmodified linemarkdown_output += f"* **Summary**: {summary}\n"markdown_output += "### Sources Information\n"for source in sources_info:markdown_output += f"* {source}\n""# Process the summary with Stablemedfinal_response = process_summary_with_stablemed(summary)# Convert translated text to speech and get both audio file and textaudio_output, translated_text = convert_text_to_speech(translated_response, input_language)# Evaluate hallucinationhallucination_label = evaluate_hallucination(final_response, summary)2 unmodified linesmarkdown_output += final_response + "\n"markdown_output += "\n### Hallucination Evaluation\n"markdown_output += f"* **Label**: {hallucination_label}\n"markdown_output += "\n### Translated Text\n"markdown_output += translated_text + "\nreturn markdown_output, audio_file_path
app.py+11-33