Spaces:
Runtime error
Runtime error
Update app.py
Browse files194 unmodified lines1951961971981992002012022032042052062072082092101 unmodified line212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255194 unmodified linesreturn 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."client = Client("https://facebook-seamless-m4t.hf.space/--replicas/8cllp/")try:result = client.predict("T2ST","text",None,None,input_text,1 unmodified linetarget_language,api_name="/run")except Exception as e:return None, f"Error during prediction: {str(e)}"try:translated_text = ""audio_file_path = ""if result:for item in result:if isinstance(item, str):if item.endswith('.mp3') and not audio_file_path:audio_file_path = itemelse: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()def process_image(image_input):# Initialize the Gradio client with the URL of the Gradio serverclient = Client("https://adept-fuyu-8b-demo.hf.space/--replicas/pqjvl/")# Assuming image_input is a URL path to the imageimage_path = image_input# Call the predict method of the clientresult = client.predict(image_path, # URL of the imageTrue, # Additional parameter for the server (e.g., enable detailed captioning)fn_index=2)return resultdef query_vectara(text):194 unmodified lines1951961971981992002012022032042052062072082092102112122132141 unmodified line216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246194 unmodified linesreturn f"{e}"def is_base64(s):try:return base64.b64encode(base64.b64decode(s)) == s.encode()except Exception:return Falsedef 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 clientresult = client.predict("T2ST","text", # Since we are doing text-to-speechNone,None,input_text,1 unmodified linetarget_language,api_name="/run")# Print or log the raw API response for inspectionprint("Raw API Response:", result)# Initialize variablestranslated_text = ""audio_file_path = ""# Process the resultif 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 stringif any(ext in item.lower() for ext in ['.mp3', '.wav', '.ogg']) or is_base64(item):if not audio_file_path: # Store only the first audio file path or base64 stringaudio_file_path = itemelse:# Concatenate the translated texttranslated_text += item + " "return audio_file_path, translated_text.strip()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