File size: 1,310 Bytes
223e341
 
 
 
 
 
 
 
dd7eac8
223e341
2f4a269
223e341
 
 
2f4a269
 
 
 
 
 
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
36
37
38
39
40
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()