Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,32 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
def
|
| 4 |
-
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
"
|
|
|
|
|
|
|
|
|
|
| 12 |
)
|
| 13 |
|
| 14 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
+
def send_audio_to_laravel(audio):
|
| 6 |
+
url = os.getenv("BASE_URL") # Make sure to set this environment variable or replace with the actual URL
|
| 7 |
|
| 8 |
+
# Save audio to a temporary file
|
| 9 |
+
temp_audio_path = "temp_audio.wav"
|
| 10 |
+
audio.save(temp_audio_path)
|
| 11 |
+
|
| 12 |
+
# Prepare form data for request
|
| 13 |
+
files = {
|
| 14 |
+
'file': open(temp_audio_path, 'rb'),
|
| 15 |
+
}
|
| 16 |
+
data = {
|
| 17 |
+
'lang': 'english-twi' # You can adjust this based on your needs
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
response = requests.post(url, files=files, data=data)
|
| 21 |
+
return response.json()
|
| 22 |
|
| 23 |
+
# Gradio interface for recording speech
|
| 24 |
+
iface = gr.Interface(
|
| 25 |
+
fn=send_audio_to_laravel,
|
| 26 |
+
inputs=gr.Audio(source="microphone", type="filepath"),
|
| 27 |
+
outputs="text",
|
| 28 |
+
title="Speech Translation",
|
| 29 |
+
description="Record speech and send it to Laravel for processing.",
|
| 30 |
)
|
| 31 |
|
| 32 |
+
iface.launch()
|