Spaces:
Runtime error
Runtime error
Commit
·
f02e809
1
Parent(s):
3e8acca
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pipe = pipeline(model="torileatherman/train_first_try") # change to "your-username/the-name-you-picked"
|
2 |
+
|
3 |
+
def transcribe(audio):
|
4 |
+
text = pipe(audio)["text"]
|
5 |
+
return text
|
6 |
+
|
7 |
+
translation_pipeline = TranslationPipeline( model=AutoModelWithLMHead.from_pretrained("SEBIS/legal_t5_small_trans_sv_en"),
|
8 |
+
tokenizer=AutoTokenizer.from_pretrained(pretrained_model_name_or_path = "SEBIS/legal_t5_small_trans_sv_en",
|
9 |
+
do_lower_case=False,
|
10 |
+
skip_special_tokens=True),
|
11 |
+
device=0)
|
12 |
+
|
13 |
+
def translate(text):
|
14 |
+
translation = translation_pipeline([text], max_length=512)
|
15 |
+
return translation
|
16 |
+
|
17 |
+
demo = gr.Blocks()
|
18 |
+
|
19 |
+
with demo:
|
20 |
+
|
21 |
+
title="Whisper Small Swedish",
|
22 |
+
description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model."
|
23 |
+
|
24 |
+
inputs_audio = gr.Audio(source="microphone", type="filepath"),
|
25 |
+
|
26 |
+
text = gr.Textbox()
|
27 |
+
translation = gr.Label()
|
28 |
+
|
29 |
+
b1 = gr.Button("Record audio")
|
30 |
+
b2 = gr.Button("Translate text")
|
31 |
+
|
32 |
+
b1.click(transcribe, inputs=inputs_audio, outputs=text)
|
33 |
+
b2.click(translate, inputs=text, outputs=translation)
|
34 |
+
|
35 |
+
demo.launch()
|