ayberkuckun commited on
Commit
feaa0ac
1 Parent(s): de9a449
Files changed (3) hide show
  1. .gitignore +1 -0
  2. app.py +51 -0
  3. requirements.txt +5 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .idea/
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ from pytube import YouTube
3
+
4
+ import gradio as gr
5
+ import librosa
6
+
7
+ import hopsworks
8
+
9
+ project = hopsworks.login()
10
+ fs = project.get_feature_store()
11
+
12
+ dataset_api = project.get_dataset_api()
13
+
14
+ dataset_api.download("Resources/titanic/images/latest_titanic.png", overwrite=True) # change link
15
+ # dataset_api.download("Resources/images/deadImage.png", overwrite=True) # change link
16
+
17
+
18
+ # pipe = pipeline(model="fimster/whisper-small-sv-SE") # change model
19
+ # pipe = pipeline(model="ayberkuckun/whisper-small-sv-SE")
20
+ pipe = pipeline(model="openai/whisper-small")
21
+
22
+
23
+ def transcribe(url):
24
+ selected_video = YouTube(url)
25
+
26
+ try:
27
+ audio = selected_video.streams.filter(only_audio=True, file_extension='mp4')[0]
28
+ except:
29
+ raise Exception("Can't find an mp4 audio.")
30
+
31
+ audio.download(filename="audio.mp4")
32
+
33
+ speech_array, sr = librosa.load("audio.mp4", sr=16000)
34
+
35
+ output = pipe(speech_array[:sr*30])
36
+
37
+ return output["text"]
38
+
39
+
40
+ iface = gr.Interface(
41
+ fn=transcribe,
42
+ inputs=gr.Textbox("https://www.youtube.com/watch?v=n9g12Xm9UJM", label="Paste a YouTube video URL"),
43
+ outputs=[gr.Textbox(label="Only the first approximately 30 sec will be transcripted"),
44
+ gr.Image("latest_titanic.png", label="Model Scores")],
45
+ # gr.Image("deadImage.png", elem_id="predicted-img", label="Model Scores")],
46
+ title="Whisper Small Swedish",
47
+ description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model.",
48
+ allow_flagging="never"
49
+ )
50
+
51
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ hopsworks
2
+ librosa
3
+ gradio
4
+ git+https://github.com/huggingface/transformers
5
+ git+https://github.com/pytube/pytube