Spaces:
Runtime error
Runtime error
jpdiazpardo
commited on
Commit
•
800c39a
1
Parent(s):
de08583
Update app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,8 @@ from functions.timestamp import format_timestamp
|
|
13 |
from functions.youtube import get_youtube_video_id
|
14 |
#---------------------------------------------------------------------
|
15 |
|
16 |
-
MODEL_NAME = "
|
|
|
17 |
BATCH_SIZE = 8
|
18 |
device = 0 if torch.cuda.is_available() else "cpu"
|
19 |
|
@@ -53,22 +54,22 @@ def transcribe(link,download,thumbnail,file,use_timestamps=True,sentiment_analys
|
|
53 |
|
54 |
#If return timestamps is True, return html text with timestamps format
|
55 |
if use_timestamps==True:
|
56 |
-
|
57 |
timestamps = [f"[{format_timestamp(chunk['timestamp'][0])} -> {format_timestamp(chunk['timestamp'][1])}] {chunk['text']}" for chunk in timestamps]
|
58 |
|
59 |
else:
|
60 |
timestamps = [f"{chunk['text']}" for chunk in timestamps]
|
61 |
-
|
62 |
|
63 |
text = "<br>".join(str(feature) for feature in timestamps)
|
64 |
text = f"<h4>Transcription</h4><div style='overflow-y: scroll; height: 150px;'>{text}</div>"
|
65 |
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
|
71 |
-
return file, text,
|
72 |
|
73 |
embed_html = '<iframe src="https://www.youtube.com/embed/YOUTUBE_ID'\
|
74 |
'title="YouTube video player" frameborder="0" allow="accelerometer;'\
|
@@ -81,11 +82,11 @@ def download(link):
|
|
81 |
subprocess.run(['python3', 'youtubetowav.py', link])
|
82 |
return thumbnail.update(value=embed_html.replace("YOUTUBE_ID",get_youtube_video_id(link)))
|
83 |
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
|
90 |
#----------------------------------------------------------------------------------------------------------------------------------------------
|
91 |
|
@@ -97,21 +98,21 @@ download_button = gr.Button(value="Download") #1
|
|
97 |
thumbnail = gr.HTML(value="", label = "Thumbnail") #2
|
98 |
audio_input = gr.Audio(source="upload", type="filepath", label="Upload audio file for transcription") #3
|
99 |
timestamp_checkbox = gr.Checkbox(value=True, label="Return timestamps") #4
|
100 |
-
|
101 |
|
102 |
inputs = [yt_link, #0
|
103 |
download_button, #1
|
104 |
thumbnail, #2
|
105 |
audio_input, #3
|
106 |
-
timestamp_checkbox
|
107 |
-
|
108 |
|
109 |
#Ouput components
|
110 |
audio_out = gr.Audio(label="Processed Audio", type="filepath", info = "Vocals only")
|
111 |
-
|
112 |
-
|
113 |
|
114 |
-
outputs = [audio_out, gr.outputs.HTML("text")]
|
115 |
|
116 |
#----------------------------------------------------------------------------------------------------------------------------------------------------
|
117 |
|
@@ -119,7 +120,7 @@ outputs = [audio_out, gr.outputs.HTML("text")]#, sentiment_plot, sentiment_frequ
|
|
119 |
|
120 |
with gr.Blocks() as demo:
|
121 |
download_button.click(download, inputs=[yt_link], outputs=[thumbnail])
|
122 |
-
|
123 |
|
124 |
|
125 |
with gr.Column():
|
|
|
13 |
from functions.youtube import get_youtube_video_id
|
14 |
#---------------------------------------------------------------------
|
15 |
|
16 |
+
MODEL_NAME = "openai/whisper-medium"
|
17 |
+
#MODEL_NAME = "jpdiazpardo/whisper-tiny-metal"
|
18 |
BATCH_SIZE = 8
|
19 |
device = 0 if torch.cuda.is_available() else "cpu"
|
20 |
|
|
|
54 |
|
55 |
#If return timestamps is True, return html text with timestamps format
|
56 |
if use_timestamps==True:
|
57 |
+
spider_text = [f"{chunk['text']}" for chunk in timestamps] #Text for spider chart without timestamps
|
58 |
timestamps = [f"[{format_timestamp(chunk['timestamp'][0])} -> {format_timestamp(chunk['timestamp'][1])}] {chunk['text']}" for chunk in timestamps]
|
59 |
|
60 |
else:
|
61 |
timestamps = [f"{chunk['text']}" for chunk in timestamps]
|
62 |
+
spider_text = timestamps
|
63 |
|
64 |
text = "<br>".join(str(feature) for feature in timestamps)
|
65 |
text = f"<h4>Transcription</h4><div style='overflow-y: scroll; height: 150px;'>{text}</div>"
|
66 |
|
67 |
+
spider_text = "\n".join(str(feature) for feature in spider_text)
|
68 |
+
trans_dict=[transform_dict(classifier.predict(t)[0]) for t in spider_text.split("\n")]
|
69 |
+
av_dict = calculate_average(trans_dict)
|
70 |
+
fig = spider_chart(av_dict)
|
71 |
|
72 |
+
return file, text, fig, av_dict
|
73 |
|
74 |
embed_html = '<iframe src="https://www.youtube.com/embed/YOUTUBE_ID'\
|
75 |
'title="YouTube video player" frameborder="0" allow="accelerometer;'\
|
|
|
82 |
subprocess.run(['python3', 'youtubetowav.py', link])
|
83 |
return thumbnail.update(value=embed_html.replace("YOUTUBE_ID",get_youtube_video_id(link)))
|
84 |
|
85 |
+
def hide_sentiment(value):
|
86 |
+
if value == True:
|
87 |
+
return sentiment_plot.update(visible=True), sentiment_frequency.update(visible=True)
|
88 |
+
else:
|
89 |
+
return sentiment_plot.update(visible=False), sentiment_frequency.update(visible=False)
|
90 |
|
91 |
#----------------------------------------------------------------------------------------------------------------------------------------------
|
92 |
|
|
|
98 |
thumbnail = gr.HTML(value="", label = "Thumbnail") #2
|
99 |
audio_input = gr.Audio(source="upload", type="filepath", label="Upload audio file for transcription") #3
|
100 |
timestamp_checkbox = gr.Checkbox(value=True, label="Return timestamps") #4
|
101 |
+
sentiment_checkbox = gr.Checkbox(value=True, label="Sentiment analysis") #5
|
102 |
|
103 |
inputs = [yt_link, #0
|
104 |
download_button, #1
|
105 |
thumbnail, #2
|
106 |
audio_input, #3
|
107 |
+
timestamp_checkbox, #4
|
108 |
+
sentiment_checkbox] #5
|
109 |
|
110 |
#Ouput components
|
111 |
audio_out = gr.Audio(label="Processed Audio", type="filepath", info = "Vocals only")
|
112 |
+
sentiment_plot = gr.Plot(label="Sentiment Analysis")
|
113 |
+
sentiment_frequency = gr.Label(label="Frequency")
|
114 |
|
115 |
+
outputs = [audio_out, gr.outputs.HTML("text")], sentiment_plot, sentiment_frequency]
|
116 |
|
117 |
#----------------------------------------------------------------------------------------------------------------------------------------------------
|
118 |
|
|
|
120 |
|
121 |
with gr.Blocks() as demo:
|
122 |
download_button.click(download, inputs=[yt_link], outputs=[thumbnail])
|
123 |
+
sentiment_checkbox.change(hide_sentiment, inputs=[sentiment_checkbox], outputs=[sentiment_plot, sentiment_frequency])
|
124 |
|
125 |
|
126 |
with gr.Column():
|