Spaces:
Sleeping
Sleeping
voice_ui.py
Browse files- voice_ui.py +0 -27
voice_ui.py
DELETED
|
@@ -1,27 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import requests
|
| 3 |
-
from pydub import AudioSegment
|
| 4 |
-
|
| 5 |
-
def record_audio(audio):
|
| 6 |
-
if audio is None:
|
| 7 |
-
return "No audio recorded. Please try again."
|
| 8 |
-
|
| 9 |
-
# Convert and save the audio file
|
| 10 |
-
file_path = "user_audio.wav"
|
| 11 |
-
audio.export(file_path, format="wav")
|
| 12 |
-
|
| 13 |
-
try:
|
| 14 |
-
# Send audio file to Flask API
|
| 15 |
-
response = requests.post("http://127.0.0.1:5000/voice_input", files={"audio": open(file_path, "rb")})
|
| 16 |
-
return response.json()["message"]
|
| 17 |
-
except Exception as e:
|
| 18 |
-
return f"Error: {str(e)}"
|
| 19 |
-
|
| 20 |
-
# Gradio UI
|
| 21 |
-
gr.Interface(
|
| 22 |
-
fn=record_audio,
|
| 23 |
-
inputs=gr.Audio(source="microphone", type="file"),
|
| 24 |
-
outputs="text",
|
| 25 |
-
title="Biryani Hub Voice Assistant",
|
| 26 |
-
description="Speak your name and email to register.",
|
| 27 |
-
).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|