Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import requests | |
| # Your API endpoint (replace with your own) | |
| API_URL = "http://8.213.40.255/transcribe" | |
| def process_audio(audio_file): | |
| try: | |
| # Send the audio file to your API with the correct field name | |
| with open(audio_file, "rb") as f: | |
| files = {"audio_file": f} # <-- match API spec | |
| response = requests.post(API_URL, files=files) | |
| if response.status_code == 200: | |
| try: | |
| data = response.json() | |
| transcription = data.get("transcription", "No transcription found") | |
| return f"π Transcription: {transcription}" | |
| except ValueError: | |
| return f"β οΈ Could not parse JSON: {response.text}" | |
| else: | |
| return f"β Error: {response.status_code} - {response.text}" | |
| except Exception as e: | |
| return f"β οΈ Exception: {str(e)}" | |
| # Gradio UI | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## π€ Record Audio and Send to API") | |
| with gr.Row(): | |
| audio_input = gr.Audio(sources=["microphone"], type="filepath") | |
| output_text = gr.Textbox(label="API Response") | |
| submit_btn = gr.Button("Send to API") | |
| submit_btn.click(process_audio, inputs=audio_input, outputs=output_text) | |
| if __name__ == "__main__": | |
| demo.launch() | |