Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
gr.Interface(
|
6 |
-
fn=
|
7 |
inputs=gr.Audio(source="microphone", type="file", label="Speak something"),
|
8 |
-
outputs=gr.Audio(type="file", label="
|
9 |
live=True
|
10 |
).launch()
|
11 |
-
|
|
|
1 |
import gradio as gr
|
2 |
+
import requests
|
3 |
+
from io import BytesIO
|
4 |
+
from pydub import AudioSegment
|
5 |
+
|
6 |
+
def translate_audio_to_audio(audio):
|
7 |
+
# Send the audio data to the translation model
|
8 |
+
translation_response = requests.post(
|
9 |
+
"https://api-inference.huggingface.co/models/facebook/xm_transformer_s2ut_hk-en",
|
10 |
+
files={"file": audio},
|
11 |
+
)
|
12 |
+
|
13 |
+
# Get the translated audio from the response
|
14 |
+
translated_audio_bytes = translation_response.content
|
15 |
+
translated_audio = AudioSegment.from_file(BytesIO(translated_audio_bytes))
|
16 |
+
|
17 |
+
return translated_audio
|
18 |
|
19 |
gr.Interface(
|
20 |
+
fn=translate_audio_to_audio,
|
21 |
inputs=gr.Audio(source="microphone", type="file", label="Speak something"),
|
22 |
+
outputs=gr.Audio(type="file", label="Translated Audio"),
|
23 |
live=True
|
24 |
).launch()
|
25 |
+
|