Spaces:
Runtime error
Runtime error
Commit
·
bbbecb9
1
Parent(s):
9217737
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,13 +17,44 @@ def transcribe(audio):
|
|
| 17 |
print(f"Text translated: {text_en}")
|
| 18 |
return text_sv, text_en
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
iface = gr.Interface(
|
| 21 |
fn=transcribe,
|
| 22 |
inputs=gr.Audio(source="microphone", type="filepath"),
|
| 23 |
outputs=[gr.Textbox(label="Transcribed text"),
|
| 24 |
gr.Textbox(label="English translation")],
|
| 25 |
title="Swedish speech to english text",
|
| 26 |
-
description="Transcribing swedish
|
| 27 |
)
|
| 28 |
|
| 29 |
iface.launch()
|
|
|
|
| 17 |
print(f"Text translated: {text_en}")
|
| 18 |
return text_sv, text_en
|
| 19 |
|
| 20 |
+
def transcribe_url(url):
|
| 21 |
+
youtube = YouTube(str(url))
|
| 22 |
+
audio = youtube.streams.filter(only_audio=True).first().download('yt_video')
|
| 23 |
+
text_sv = pipe(audio)["text"]
|
| 24 |
+
print(f"Audio transcribed: {text_sv}")
|
| 25 |
+
text_en = translator.translate_text(text_sv, target_lang=TARGET_LANG).text
|
| 26 |
+
print(f"Text translated: {text_en}")
|
| 27 |
+
return text_sv, text_en
|
| 28 |
+
|
| 29 |
+
url_demo = gr.Interface(
|
| 30 |
+
fn=transcribe_url,
|
| 31 |
+
inputs="text",
|
| 32 |
+
outputs=[gr.Textbox(label="Transcribed text"),
|
| 33 |
+
gr.Textbox(label="English translation")],
|
| 34 |
+
title="Swedish video speech to english text",
|
| 35 |
+
description="Transcribing swedish video to text and translating to english!",
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
voice_demo = gr.Interface(
|
| 39 |
+
fn=transcribe,
|
| 40 |
+
inputs=gr.Audio(source="microphone", type="filepath"),
|
| 41 |
+
outputs=[gr.Textbox(label="Transcribed text"),
|
| 42 |
+
gr.Textbox(label="English translation")],
|
| 43 |
+
title="Swedish recorded speech to english text",
|
| 44 |
+
description="Transcribing swedish speech to text and translating to english!",
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
demo = gr.TabbedInterface([url_demo, voice_demo], ["Swedish YouTube Video to English Text", "Swedish Audio to English Text"])
|
| 48 |
+
|
| 49 |
+
demo.launch()
|
| 50 |
+
|
| 51 |
iface = gr.Interface(
|
| 52 |
fn=transcribe,
|
| 53 |
inputs=gr.Audio(source="microphone", type="filepath"),
|
| 54 |
outputs=[gr.Textbox(label="Transcribed text"),
|
| 55 |
gr.Textbox(label="English translation")],
|
| 56 |
title="Swedish speech to english text",
|
| 57 |
+
description="Transcribing swedish audio and video to text and translating to english!",
|
| 58 |
)
|
| 59 |
|
| 60 |
iface.launch()
|