kk90ujhun commited on
Commit
f3ac8fd
·
1 Parent(s): 25b7016

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -33
app.py CHANGED
@@ -1,43 +1,29 @@
1
- # from transformers import pipeline
2
- # import gradio as gr
3
-
4
- # pipe = pipeline(model="kk90ujhun/whisper-small-zh") # 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"),
13
- # outputs="text",
14
- # title="Whisper Small Chinese",
15
- # description="Realtime demo for Chinese speech recognition using a fine-tuned Whisper small model.",
16
- # )
17
-
18
- # iface.launch()
19
-
20
  from transformers import pipeline
21
- from pytube import YouTube
22
  import gradio as gr
 
23
 
24
- pipe = pipeline(model="kk90ujhun/whisper-small-zh")
25
 
26
 
27
- def transcribe(url):
28
- audio = YouTube(url).streams.filter(file_extension='mp4', only_audio=True).first().download()
29
-
30
- text = pipe(audio, batch_size=512, truncation=True)["text"]
31
-
32
- return text
33
-
 
34
 
35
  iface = gr.Interface(
36
- fn=transcribe,
37
- inputs=gr.Textbox(label="Enter a YouTube URL:"),
38
- outputs="text",
39
- title="Whisper Small Chinese",
40
- description="Transcribe Chinese videos",
 
 
 
41
  )
42
 
 
43
  iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from transformers import pipeline
 
2
  import gradio as gr
3
+ import pytube
4
 
5
+ pipe = pipeline(model="kk90ujhun/whisper-small-zh")
6
 
7
 
8
+ def transcribe(my_url,audio):
9
+ if my_url:
10
+ my_audio = pytube.YouTube(my_url).streams.filter(subtype='mp4').first().download()
11
+ text = pipe(my_audio)["text"]
12
+ return text
13
+ else:
14
+ text = pipe(audio)["text"]
15
+ return text
16
 
17
  iface = gr.Interface(
18
+ fn=transcribe,
19
+ inputs=[
20
+ gr.Textbox(label="Enter your YouTube URL:"),
21
+ gr.Audio(label="Speak to your microphone",source="microphone", type="filepath"),
22
+ ], #
23
+ outputs="text",
24
+ title="Whisper Small Chinese",
25
+ description="Realtime demo for Chinese speech recognition using a fine-tuned Whisper small model.",
26
  )
27
 
28
+
29
  iface.launch()