Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,24 @@
|
|
1 |
-
from transformers import pipeline
|
2 |
import gradio as gr
|
3 |
|
|
|
|
|
4 |
pipe = pipeline(model="torileatherman/train_first_try") # change to "your-username/the-name-you-picked"
|
5 |
|
6 |
def transcribe(audio):
|
7 |
text = pipe(audio)["text"]
|
8 |
return text
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
iface = gr.Interface(
|
11 |
fn=transcribe,
|
12 |
inputs=gr.Audio(source="microphone", type="filepath"),
|
@@ -15,4 +27,25 @@ iface = gr.Interface(
|
|
15 |
description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model.",
|
16 |
)
|
17 |
|
18 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline, AutoTokenizer, AutoModelWithLMHead, TranslationPipeline
|
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 |
text = pipe(audio)["text"]
|
10 |
return text
|
11 |
|
12 |
+
translation_pipeline = TranslationPipeline( model=AutoModelWithLMHead.from_pretrained("SEBIS/legal_t5_small_trans_sv_en"),
|
13 |
+
tokenizer=AutoTokenizer.from_pretrained(pretrained_model_name_or_path = "SEBIS/legal_t5_small_trans_sv_en",
|
14 |
+
do_lower_case=False,
|
15 |
+
skip_special_tokens=True),
|
16 |
+
device=0)
|
17 |
+
|
18 |
+
def translate(text):
|
19 |
+
translation = translation_pipeline([text], max_length=512)
|
20 |
+
return translation
|
21 |
+
|
22 |
iface = gr.Interface(
|
23 |
fn=transcribe,
|
24 |
inputs=gr.Audio(source="microphone", type="filepath"),
|
|
|
27 |
description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model.",
|
28 |
)
|
29 |
|
30 |
+
iface.launch()
|
31 |
+
|
32 |
+
demo = gr.Blocks()
|
33 |
+
|
34 |
+
with demo:
|
35 |
+
|
36 |
+
title="Whisper Small Swedish",
|
37 |
+
description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model."
|
38 |
+
|
39 |
+
inputs_audio = gr.Audio(source="microphone", type="filepath"),
|
40 |
+
|
41 |
+
text = gr.Textbox()
|
42 |
+
translation = gr.Label()
|
43 |
+
|
44 |
+
b1 = gr.Button("Record audio")
|
45 |
+
b2 = gr.Button("Translate text")
|
46 |
+
|
47 |
+
b1.click(transcribe, inputs=inputs_audio, outputs=text)
|
48 |
+
b2.click(translate, inputs=text, outputs=translation)
|
49 |
+
|
50 |
+
demo.launch()
|
51 |
+
|