Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
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 |
|
@@ -9,28 +9,32 @@ def transcribe(audio):
|
|
9 |
text = pipe(audio)["text"]
|
10 |
return text
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
inputs="text",
|
21 |
-
outputs="text",
|
22 |
-
title="Whisper Swedish",
|
23 |
-
description="Swedish speech and audio recognition using a fine-tuned Whisper small model",
|
24 |
-
)
|
25 |
-
|
26 |
-
voice_demo = gr.Interface(
|
27 |
-
fn=transcribe,
|
28 |
-
inputs=gr.Audio(source="microphone", type="filepath"),
|
29 |
-
outputs="text",
|
30 |
-
title="Whisper Swedish",
|
31 |
-
description="Swedish speech and audio recognition using a fine-tuned Whisper small model",
|
32 |
-
)
|
33 |
-
|
34 |
-
demo = gr.TabbedInterface([url_demo, voice_demo], ["YouTube Video to Text", "Audio to Text"])
|
35 |
|
36 |
demo.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 |
|
|
|
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 |
+
demo = gr.Blocks()
|
23 |
+
|
24 |
+
with demo:
|
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()
|