Spaces:
Runtime error
Runtime error
Update app.py
Browse files194 unmodified lines1951961971981992001981992002012022032042052062072082092102072112122132141 unmodified line216217218215216219218220221222223224225226227228229230231232225226233234235236237229230238232233239240235236237238239240241242243244245246247248249250251252241242243244245246194 unmodified lines return f"{e}"
def convert_text_to_speech(input_text: str, source_language: str, target_language: str) -> tuple[str, str]: if not input_text or not source_language or not target_language: return None, "Invalid input parameters."def is_base64(s): try: return base64.b64encode(base64.b64decode(s)) == s.encode() except Exception: return False
def convert_text_to_speech(input_text: str, source_language: str, target_language: str) -> tuple[str, str]: client = Client("https://facebook-seamless-m4t.hf.space/--replicas/8cllp/")
try: # Make a prediction request to the client result = client.predict( "T2ST", "text", "text", # Since we are doing text-to-speech None, None, input_text,1 unmodified line target_language, api_name="/run" ) except Exception as e: return None, f"Error during prediction: {str(e)}"
try: # Print or log the raw API response for inspection print("Raw API Response:", result)
# Initialize variables translated_text = "" audio_file_path = ""
# Process the result if result: for item in result: if isinstance(item, str): # Check if the item is a URL pointing to an audio file or a base64 encoded string if any(ext in item.lower() for ext in ['.mp3', '.wav', '.ogg']) or is_base64(item): if item.endswith('.mp3') and not audio_file_path: audio_file_path = item if not audio_file_path: # Store only the first audio file path or base64 string audio_file_path = item else: # Concatenate the translated text translated_text += item + " " except Exception as e: return None, f"Error processing result: {str(e)}"
if not audio_file_path: return None, "No audio file path found in the result." return audio_file_path, translated_text.strip()
return audio_file_path, translated_text.strip()
def process_image(image_input): # Initialize the Gradio client with the URL of the Gradio server client = Client("https://adept-fuyu-8b-demo.hf.space/--replicas/pqjvl/")
# Assuming image_input is a URL path to the image image_path = image_input
# Call the predict method of the client result = client.predict( image_path, # URL of the image True, # Additional parameter for the server (e.g., enable detailed captioning) fn_index=2 )
return result except Exception as e: print(f"Error in text-to-speech conversion: {str(e)}") return None, f"Error in text-to-speech conversion: {str(e)}"
def query_vectara(text):app.py+22-31