Manbearpig01 commited on
Commit
b7d40e6
1 Parent(s): 2559ef6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """app.ipynb
3
+
4
+ Automatically generated by Colaboratory.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1SLY6vFgJGYJxXCiJWtRo3Qxag5r_Y4K7
8
+ """
9
+
10
+ !pip install transformers
11
+ !pip install pytube
12
+
13
+ !pip install gradio
14
+
15
+ import os
16
+ import gradio as gr
17
+ from transformers import pipeline
18
+ from pytube import YouTube
19
+
20
+
21
+ #pipe = pipeline(model="jdowling/whisper-small-hi") # change to "your-username/the-name-you-picked" 加
22
+
23
+
24
+ def yt(link):
25
+ yt = YouTube(link)
26
+ stream = yt.streams.filter(only_audio=True)[0]
27
+ stream.download(filename="audio.mp3")
28
+ text = pipe("audio.mp3")["text"]
29
+ return text
30
+
31
+ def transcribe(audio):
32
+ text = pipe(audio)["text"]
33
+ return text
34
+
35
+ demo = gr.Blocks()
36
+
37
+
38
+ iface = gr.Interface(
39
+ fn=transcribe,
40
+ inputs=gr.Audio(source="microphone", type="filepath"),
41
+ outputs="text",
42
+ title="Whisper Small Swedish-Microphone",
43
+ description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model. An audio for recognize.",
44
+ )
45
+
46
+ yt = gr.Interface(
47
+ fn=yt,
48
+ inputs=[gr.inputs.Textbox(lines=1, label="Youtube URL")],
49
+ outputs=["html", "text"],
50
+ title="Whisper Small Swedish-Youtube",
51
+ description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model. A Youtube URL for recognize."
52
+
53
+ )
54
+
55
+ with demo:
56
+ gr.TabbedInterface([iface, yt], ["Transcribe Audio", "Transcribe YouTube"])
57
+
58
+ demo.launch(enable_queue=True)