Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,39 +1,38 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
-
import tempfile
|
| 4 |
import soundfile as sf
|
|
|
|
| 5 |
|
| 6 |
# π€ Speech to Text
|
| 7 |
stt = pipeline("automatic-speech-recognition", model="openai/whisper-base")
|
| 8 |
|
| 9 |
-
# π Translation
|
| 10 |
-
translator = pipeline(
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
-
def
|
| 14 |
|
| 15 |
-
# 1.
|
| 16 |
text = stt(audio)["text"]
|
| 17 |
|
| 18 |
-
# 2.
|
| 19 |
-
translated = translator(text
|
| 20 |
-
translated_text = translated[0]["translation_text"]
|
| 21 |
-
|
| 22 |
-
# 3. π₯ SAME VOICE SIMULATION (placeholder voice cloning)
|
| 23 |
-
# NOTE: real voice cloning needs RVC/OpenVoice model
|
| 24 |
-
fake_voice_audio = audio # keeps original voice style (demo)
|
| 25 |
|
| 26 |
-
|
|
|
|
| 27 |
|
| 28 |
|
| 29 |
iface = gr.Interface(
|
| 30 |
-
fn=
|
| 31 |
inputs=gr.Audio(type="filepath"),
|
| 32 |
outputs=[
|
| 33 |
-
gr.Textbox(
|
| 34 |
-
gr.Audio(
|
| 35 |
],
|
| 36 |
-
title="
|
| 37 |
)
|
| 38 |
|
| 39 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
|
|
|
| 3 |
import soundfile as sf
|
| 4 |
+
import tempfile
|
| 5 |
|
| 6 |
# π€ Speech to Text
|
| 7 |
stt = pipeline("automatic-speech-recognition", model="openai/whisper-base")
|
| 8 |
|
| 9 |
+
# π Translation (FIXED)
|
| 10 |
+
translator = pipeline(
|
| 11 |
+
"translation",
|
| 12 |
+
model="facebook/nllb-200-distilled-600M"
|
| 13 |
+
)
|
| 14 |
|
| 15 |
|
| 16 |
+
def translate(audio):
|
| 17 |
|
| 18 |
+
# 1. speech β text
|
| 19 |
text = stt(audio)["text"]
|
| 20 |
|
| 21 |
+
# 2. translation (simple safe version)
|
| 22 |
+
translated = translator(text)[0]["translation_text"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
# 3. fake same voice output (RVC not included yet)
|
| 25 |
+
return translated, audio
|
| 26 |
|
| 27 |
|
| 28 |
iface = gr.Interface(
|
| 29 |
+
fn=translate,
|
| 30 |
inputs=gr.Audio(type="filepath"),
|
| 31 |
outputs=[
|
| 32 |
+
gr.Textbox(),
|
| 33 |
+
gr.Audio()
|
| 34 |
],
|
| 35 |
+
title="Audio Translator FIXED"
|
| 36 |
)
|
| 37 |
|
| 38 |
iface.launch()
|