Spaces:
Runtime error
Runtime error
Update app.py
Browse files119 unmodified lines1201211221231241251261271281291301311321331341351361371381391401411421431231241461251261271288 unmodified lines137138139161140141163142143144145146252 unmodified lines3994004014224234024034044051 unmodified line4074084094314104114124134144364374384394404414154164174184194202 unmodified lines423424425426427428429430119 unmodified lines except 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 type None, # No file input for text translation input_text, # Input text "", # Empty string for audio name source_language, # Source language target_language, # Target language api_name="/run" # API name )
translated_text = text_translation_result[1] # Assuming the result is in the second position return translated_text except 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. 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 position return audio_file return audio_file, input_text except Exception as e: return f"An error occurred during text-to-speech conversion: {e}" return f"An error occurred during text-to-speech conversion: {e}", input_text
def save_image(image_input, output_dir="saved_images"): if not os.path.exists(output_dir):252 unmodified lines sources_info = vectara_response.get('sources', [])
# Convert translated text to speech audio_file_path = convert_text_to_speech(translated_response, input_language)
# Format Vectara response in Markdown1 unmodified line markdown_output += f"* **Summary**: {summary}\n" markdown_output += "### Sources Information\n" for source in sources_info: markdown_output += f"* {source}\n" markdown_output += f"* {source}\n""
# Process the summary with Stablemed final_response = process_summary_with_stablemed(summary)
# Translate the final response translated_response = translate_text(final_response, input_language, input_language)
# Convert translated text to speech audio_file_path = convert_text_to_speech(translated_response, input_language) # Convert translated text to speech and get both audio file and text audio_output, translated_text = convert_text_to_speech(translated_response, input_language) # Evaluate hallucination hallucination_label = evaluate_hallucination(final_response, summary)
2 unmodified lines markdown_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 + "\n
return markdown_output, audio_file_path app.py+11-33