Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,29 @@
|
|
| 1 |
-
from transformers import pipeline
|
| 2 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 3 |
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
pipe = pipeline(model="torileatherman/train_first_try") # change to "your-username/the-name-you-picked"
|
| 7 |
|
| 8 |
def transcribe(audio):
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
title="Whisper Small Swedish",
|
| 27 |
-
description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model."
|
| 28 |
-
|
| 29 |
-
inputs_audio = gr.Audio(source="microphone", type="filepath"),
|
| 30 |
-
|
| 31 |
-
text = gr.Textbox()
|
| 32 |
-
translation = gr.Label()
|
| 33 |
-
|
| 34 |
-
b1 = gr.Button("Record audio")
|
| 35 |
-
b2 = gr.Button("Translate text")
|
| 36 |
-
|
| 37 |
-
b1.click(transcribe, inputs=inputs_audio, outputs=text)
|
| 38 |
-
b2.click(translate, inputs=text, outputs=translation)
|
| 39 |
-
|
| 40 |
-
demo.launch()
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
import gradio as gr
|
| 3 |
+
import os
|
| 4 |
+
import deepl
|
| 5 |
+
import openai
|
| 6 |
|
| 7 |
+
TARGET_LANG = "EN-GB"
|
| 8 |
+
deepl_key = os.environ.get('DEEPL')
|
| 9 |
|
| 10 |
+
translator = deepl.Translator(deepl_key)
|
| 11 |
pipe = pipeline(model="torileatherman/train_first_try") # change to "your-username/the-name-you-picked"
|
| 12 |
|
| 13 |
def transcribe(audio):
|
| 14 |
+
text_sv = pipe(audio)["text"]
|
| 15 |
+
print(f"Audio transcribed: {text_sv}")
|
| 16 |
+
text_en = translator.translate_text(text_sv, target_lang=TARGET_LANG).text
|
| 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 speech to text and translating to english!",
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|