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