Spaces:
Runtime error
Runtime error
Update app.py
Browse files121 unmodified lines122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156266 unmodified lines423424425426427428429121 unmodified linesreturn f"{e}"def convert_text_to_speech(input_text, target_language):"""Convert text to speech in the specified language, rename the audio file with a unique identifier, and return both the new audio file path and the input text."""try:text_to_speech_result = seamless_client.predict("T2ST", # Task: Text to Speech Translation"text", # Input typeNone, # No file input for text to speechinput_text, # Input text"", # Empty string for audio name"", # Empty string for source language, as it's not needed heretarget_language, # Target languageapi_name="/run" # API name)original_audio_file = text_to_speech_result[1] # Assuming the audio file path is in the second position# Generate a new file name with a random UUIDnew_file_name = f"audio_output_{uuid.uuid4()}.wav"new_file_path = os.path.join(os.path.dirname(original_audio_file), new_file_name)# Rename the fileos.rename(original_audio_file, new_file_path)return new_file_path, 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):266 unmodified linesfinal_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(final_response, input_language)# Evaluate hallucinationhallucination_label = evaluate_hallucination(final_response, summary)121 unmodified lines122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162266 unmodified lines429430431432433434435436121 unmodified linesreturn f"{e}"def convert_text_to_speech(input_text, source_language, target_language):"""Convert text to speech in the specified language and return the new audio file path."""client = Client("https://facebook-seamless-m4t.hf.space/--replicas/8cllp/")try:result = client.predict("T2ST (Text to Speech translation)", # Task"text", # Input typeinput_text, # Input text"", # Empty string for audio namesource_language, # Source languagetarget_language, # Target languageapi_name="/run" # API name)# Assuming the audio file path is returned in the resultoriginal_audio_file = result[1] if len(result) > 1 else Noneif original_audio_file:# Generate a new file name with a random UUIDnew_file_name = f"audio_output_{uuid.uuid4()}.wav"new_file_path = os.path.join(os.path.dirname(original_audio_file), new_file_name)# Rename the fileos.rename(original_audio_file, new_file_path)return new_file_pathelse:return "No audio file generated."except Exception as e:# Return a concise error messagereturn f"Error in text-to-speech conversion: {str(e)}"def save_image(image_input, output_dir="saved_images"):if not os.path.exists(output_dir):266 unmodified linesfinal_response = process_summary_with_stablemed(summary)# Convert translated text to speech and get both audio file and texttarget_language = "English" # Set the target language for the speechaudio_file_path = convert_text_to_speech(final_response, target_language, input_language)# Evaluate hallucinationhallucination_label = evaluate_hallucination(final_response, summary)
app.py+23-16