Spaces:
Runtime error
Runtime error
jpdiazpardo
commited on
Commit
•
a2c2b3c
1
Parent(s):
f9b90bd
Update app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,36 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
import subprocess
|
3 |
import torch
|
|
|
|
|
|
|
4 |
from functions.charts import spider_chart
|
5 |
from functions.dictionaries import calculate_average, transform_dict
|
6 |
from functions.icon import generate_icon
|
7 |
-
from transformers import pipeline
|
8 |
from functions.timestamp import format_timestamp
|
9 |
from functions.youtube import get_youtube_video_id
|
|
|
10 |
|
11 |
MODEL_NAME = "openai/whisper-medium"
|
12 |
BATCH_SIZE = 8
|
13 |
-
|
14 |
device = 0 if torch.cuda.is_available() else "cpu"
|
15 |
|
|
|
16 |
pipe = pipeline(
|
17 |
task="automatic-speech-recognition",
|
18 |
model=MODEL_NAME,
|
19 |
chunk_length_s=30,
|
20 |
-
device=device
|
21 |
)
|
22 |
|
23 |
-
#Formating
|
24 |
title = "Whisper Demo: Transcribe Audio"
|
25 |
MODEL_NAME1 = "jpdiazpardo/whisper-tiny-metal"
|
26 |
description = ("Transcribe long-form audio inputs with the click of a button! Demo uses the"
|
27 |
f" checkpoint [{MODEL_NAME1}](https://huggingface.co/{MODEL_NAME1}) and 🤗 Transformers to transcribe audio files"
|
28 |
" of arbitrary length. Check some of the 'cool' examples below")
|
29 |
|
30 |
-
examples = [["https://www.youtube.com/watch?v=W72Lnz1n-jw&ab_channel=Whitechapel-Topic",None,None,
|
31 |
-
"examples/When a Demon Defiles a Witch.wav",True, True],
|
32 |
-
["https://www.youtube.com/watch?v=BnO3Io0KOl4&ab_channel=MotionlessInWhite-Topic",None,None,
|
33 |
-
"examples/Immaculate Misconception.wav",True, True]]
|
34 |
-
|
35 |
linkedin = generate_icon("linkedin")
|
36 |
github = generate_icon("github")
|
37 |
article = ("<div style='text-align: center; max-width:800px; margin:10px auto;'>"
|
@@ -45,6 +44,7 @@ title = "Scream: Fine-Tuned Whisper model for automatic gutural speech recogniti
|
|
45 |
#Define classifier for sentiment analysis
|
46 |
classifier = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base", top_k=None)
|
47 |
|
|
|
48 |
def transcribe(*args):#file, return_timestamps, *kwargs):
|
49 |
'''inputs: file, return_timestamps'''
|
50 |
outputs = pipe(args[3], batch_size=BATCH_SIZE, generate_kwargs={"task": 'transcribe'}, return_timestamps=True)
|
@@ -70,15 +70,6 @@ def transcribe(*args):#file, return_timestamps, *kwargs):
|
|
70 |
|
71 |
return args[3], text, fig, av_dict
|
72 |
|
73 |
-
def filter(choice):
|
74 |
-
if choice=="YouTube":
|
75 |
-
return yt_link.update(interactive=True), audio_input.update(interactive=False)
|
76 |
-
elif choice == "Upload File":
|
77 |
-
return yt_link.update(value=None,interactive=False), audio_input.update(interactive=True)
|
78 |
-
else:
|
79 |
-
return yt_link.update(interactive=False), audio_input.update(interactive=False)
|
80 |
-
|
81 |
-
|
82 |
embed_html = '<iframe src="https://www.youtube.com/embed/YOUTUBE_ID'\
|
83 |
'title="YouTube video player" frameborder="0" allow="accelerometer;'\
|
84 |
'autoplay; clipboard-write; encrypted-media; gyroscope;'\
|
@@ -93,7 +84,11 @@ def hide_sa(value):
|
|
93 |
return sa_plot.update(visible=True), sa_frequency.update(visible=True)
|
94 |
else:
|
95 |
return sa_plot.update(visible=False), sa_frequency.update(visible=False)
|
96 |
-
|
|
|
|
|
|
|
|
|
97 |
#Input components
|
98 |
yt_link = gr.Textbox(value=None,label="YouTube link", info = "Optional: Copy and paste YouTube URL")
|
99 |
audio_input = gr.Audio(source="upload", type="filepath", label="Upload audio file for transcription")
|
@@ -115,6 +110,10 @@ sa_frequency = gr.Label(label="Frequency")
|
|
115 |
|
116 |
outputs = [audio_out, gr.outputs.HTML("text"), sa_plot, sa_frequency]
|
117 |
|
|
|
|
|
|
|
|
|
118 |
with gr.Blocks() as demo:
|
119 |
download_button.click(download, inputs=[yt_link], outputs=[thumbnail])
|
120 |
sa_checkbox.change(hide_sa, inputs=[sa_checkbox], outputs=[sa_plot, sa_frequency])
|
@@ -125,6 +124,8 @@ with gr.Blocks() as demo:
|
|
125 |
description=description, cache_examples=True, allow_flagging="never", article = article , examples='examples')
|
126 |
|
127 |
demo.queue(concurrency_count=3)
|
128 |
-
demo.launch(debug = True)
|
129 |
|
|
|
|
|
130 |
|
|
|
|
1 |
+
#Imports-------------------------------------------------------------
|
2 |
import gradio as gr
|
3 |
import subprocess
|
4 |
import torch
|
5 |
+
from transformers import pipeline
|
6 |
+
|
7 |
+
#User defined functions (UDF)
|
8 |
from functions.charts import spider_chart
|
9 |
from functions.dictionaries import calculate_average, transform_dict
|
10 |
from functions.icon import generate_icon
|
|
|
11 |
from functions.timestamp import format_timestamp
|
12 |
from functions.youtube import get_youtube_video_id
|
13 |
+
#---------------------------------------------------------------------
|
14 |
|
15 |
MODEL_NAME = "openai/whisper-medium"
|
16 |
BATCH_SIZE = 8
|
|
|
17 |
device = 0 if torch.cuda.is_available() else "cpu"
|
18 |
|
19 |
+
#Transformers pipeline
|
20 |
pipe = pipeline(
|
21 |
task="automatic-speech-recognition",
|
22 |
model=MODEL_NAME,
|
23 |
chunk_length_s=30,
|
24 |
+
device=device
|
25 |
)
|
26 |
|
27 |
+
#Formating---------------------------------------------------------------------------------------------
|
28 |
title = "Whisper Demo: Transcribe Audio"
|
29 |
MODEL_NAME1 = "jpdiazpardo/whisper-tiny-metal"
|
30 |
description = ("Transcribe long-form audio inputs with the click of a button! Demo uses the"
|
31 |
f" checkpoint [{MODEL_NAME1}](https://huggingface.co/{MODEL_NAME1}) and 🤗 Transformers to transcribe audio files"
|
32 |
" of arbitrary length. Check some of the 'cool' examples below")
|
33 |
|
|
|
|
|
|
|
|
|
|
|
34 |
linkedin = generate_icon("linkedin")
|
35 |
github = generate_icon("github")
|
36 |
article = ("<div style='text-align: center; max-width:800px; margin:10px auto;'>"
|
|
|
44 |
#Define classifier for sentiment analysis
|
45 |
classifier = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base", top_k=None)
|
46 |
|
47 |
+
#Functions-----------------------------------------------------------------------------------------------------------------------
|
48 |
def transcribe(*args):#file, return_timestamps, *kwargs):
|
49 |
'''inputs: file, return_timestamps'''
|
50 |
outputs = pipe(args[3], batch_size=BATCH_SIZE, generate_kwargs={"task": 'transcribe'}, return_timestamps=True)
|
|
|
70 |
|
71 |
return args[3], text, fig, av_dict
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
embed_html = '<iframe src="https://www.youtube.com/embed/YOUTUBE_ID'\
|
74 |
'title="YouTube video player" frameborder="0" allow="accelerometer;'\
|
75 |
'autoplay; clipboard-write; encrypted-media; gyroscope;'\
|
|
|
84 |
return sa_plot.update(visible=True), sa_frequency.update(visible=True)
|
85 |
else:
|
86 |
return sa_plot.update(visible=False), sa_frequency.update(visible=False)
|
87 |
+
|
88 |
+
#----------------------------------------------------------------------------------------------------------------------------------------------
|
89 |
+
|
90 |
+
#Components------------------------------------------------------------------------------------------------------------------------------------
|
91 |
+
|
92 |
#Input components
|
93 |
yt_link = gr.Textbox(value=None,label="YouTube link", info = "Optional: Copy and paste YouTube URL")
|
94 |
audio_input = gr.Audio(source="upload", type="filepath", label="Upload audio file for transcription")
|
|
|
110 |
|
111 |
outputs = [audio_out, gr.outputs.HTML("text"), sa_plot, sa_frequency]
|
112 |
|
113 |
+
#----------------------------------------------------------------------------------------------------------------------------------------------------
|
114 |
+
|
115 |
+
#Launch demo-----------------------------------------------------------------------------------------------------------------------------------------
|
116 |
+
|
117 |
with gr.Blocks() as demo:
|
118 |
download_button.click(download, inputs=[yt_link], outputs=[thumbnail])
|
119 |
sa_checkbox.change(hide_sa, inputs=[sa_checkbox], outputs=[sa_plot, sa_frequency])
|
|
|
124 |
description=description, cache_examples=True, allow_flagging="never", article = article , examples='examples')
|
125 |
|
126 |
demo.queue(concurrency_count=3)
|
|
|
127 |
|
128 |
+
if __name__ == "__main__":
|
129 |
+
demo.launch(debug = True)
|
130 |
|
131 |
+
#----------------------------------------------------------------------------------------------------------------------------------------------------
|