import gradio as gr import requests import os def send_audio_to_laravel(audio): if audio is None: return "No audio recorded. Please try again." url = os.getenv("TRANSLATION_URL") if not url: return "BASE_URL environment variable is not set." # audio is a tuple (file_path, sampling_rate) or None audio_path, sampling_rate = audio # Prepare form data for request try: with open(audio_path, 'rb') as audio_file: files = {'file': audio_file} data = {'lang': 'english-twi'} response = requests.post(url, files=files, data=data) return response.json() except Exception as e: return f"An error occurred: {str(e)}" # Gradio interface for recording speech iface = gr.Interface( fn=send_audio_to_laravel, inputs=gr.Audio(type="filepath"), outputs="text", title="Speech Translation", description="Record speech and send it for processing.", ) iface.launch()