File size: 1,000 Bytes
223e341
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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 open(audio_file, "rb") as f:
            files = {"file": f}
            response = requests.post(API_URL, files=files)

        if response.status_code == 200:
            return f"βœ… Result: {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()