Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
# Your API endpoint (replace with your own)
|
| 5 |
+
API_URL = "http://8.213.40.255/transcribe"
|
| 6 |
+
|
| 7 |
+
def process_audio(audio_file):
|
| 8 |
+
try:
|
| 9 |
+
# Send the audio file to your API
|
| 10 |
+
with open(audio_file, "rb") as f:
|
| 11 |
+
files = {"file": f}
|
| 12 |
+
response = requests.post(API_URL, files=files)
|
| 13 |
+
|
| 14 |
+
if response.status_code == 200:
|
| 15 |
+
return f"✅ Result: {response.text}"
|
| 16 |
+
else:
|
| 17 |
+
return f"❌ Error: {response.status_code} - {response.text}"
|
| 18 |
+
|
| 19 |
+
except Exception as e:
|
| 20 |
+
return f"⚠️ Exception: {str(e)}"
|
| 21 |
+
|
| 22 |
+
# Gradio UI
|
| 23 |
+
with gr.Blocks() as demo:
|
| 24 |
+
gr.Markdown("## 🎤 Record Audio and Send to API")
|
| 25 |
+
|
| 26 |
+
with gr.Row():
|
| 27 |
+
audio_input = gr.Audio(sources=["microphone"], type="filepath")
|
| 28 |
+
output_text = gr.Textbox(label="API Response")
|
| 29 |
+
|
| 30 |
+
submit_btn = gr.Button("Send to API")
|
| 31 |
+
submit_btn.click(process_audio, inputs=audio_input, outputs=output_text)
|
| 32 |
+
|
| 33 |
+
if __name__ == "__main__":
|
| 34 |
+
demo.launch()
|