eengel7 commited on
Commit
5ad6afe
1 Parent(s): 39f8776

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -25
app.py CHANGED
@@ -1,7 +1,7 @@
1
- from transformers import pipeline
2
  import gradio as gr
3
- from pytube import YouTube
4
- import os
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
- def transcribe_url(url):
13
- youtube = YouTube(str(url))
14
- audio = youtube.streams.filter(only_audio=True).first().download('yt_video')
15
- text = pipe(audio)["text"]
16
- return text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
- url_demo = gr.Interface(
19
- fn=transcribe_url,
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()