Spaces:
Runtime error
Runtime error
storresbusquets
commited on
Commit
Β·
65b4025
1
Parent(s):
fb09c72
Update app.py
Browse files
app.py
CHANGED
@@ -155,7 +155,7 @@ class GradioInference:
|
|
155 |
self.yt = YouTube(link)
|
156 |
return self.yt.thumbnail_url, self.yt.title
|
157 |
|
158 |
-
def from_audio_input(self, lang, size, audio_file):
|
159 |
"""
|
160 |
Call the Gradio Inference python class.
|
161 |
Uses it directly the Whisper model to perform Automatic Speech Recognition (i.e Speech-to-Text).
|
@@ -165,6 +165,7 @@ class GradioInference:
|
|
165 |
- Sentiment Analysis: using Hugging Face's default sentiment classifier
|
166 |
- WordCloud: using the wordcloud python library.
|
167 |
"""
|
|
|
168 |
if lang == "none":
|
169 |
lang = None
|
170 |
|
@@ -172,8 +173,10 @@ class GradioInference:
|
|
172 |
self.loaded_model = whisper.load_model(size)
|
173 |
self.current_size = size
|
174 |
|
|
|
175 |
results = self.loaded_model.transcribe(audio_file, language=lang)
|
176 |
|
|
|
177 |
# Perform summarization on the transcription
|
178 |
transcription_summary = self.summarizer(
|
179 |
results["text"], max_length=150, min_length=30, do_sample=False
|
@@ -203,7 +206,8 @@ class GradioInference:
|
|
203 |
clean_up_tokenization_spaces=False
|
204 |
)
|
205 |
#### Fin prueba
|
206 |
-
|
|
|
207 |
# Extract keywords using VoiceLabT5
|
208 |
task_prefix = "Keywords: "
|
209 |
input_sequence = task_prefix + results["text"]
|
@@ -216,9 +220,11 @@ class GradioInference:
|
|
216 |
predicted = self.keyword_tokenizer.decode(output[0], skip_special_tokens=True)
|
217 |
keywords = [x.strip() for x in predicted.split(",") if x.strip()]
|
218 |
|
|
|
219 |
# Sentiment label
|
220 |
label = self.classifier(summary)[0]["label"]
|
221 |
-
|
|
|
222 |
# WordCloud object
|
223 |
wordcloud = WordCloud(colormap = "Oranges").generate(
|
224 |
results["text"]
|
@@ -331,7 +337,7 @@ with block as demo:
|
|
331 |
with gr.Row().style(equal_height=True):
|
332 |
clear = gr.ClearButton([audio_file,text, summary, keywords, label, wordcloud_image], scale=1, value="Clear ποΈ",rounded=True)
|
333 |
btn = gr.Button(
|
334 |
-
"Get
|
335 |
)
|
336 |
btn.click(
|
337 |
gio.from_audio_input,
|
|
|
155 |
self.yt = YouTube(link)
|
156 |
return self.yt.thumbnail_url, self.yt.title
|
157 |
|
158 |
+
def from_audio_input(self, lang, size, audio_file, progress=gr.Progress()):
|
159 |
"""
|
160 |
Call the Gradio Inference python class.
|
161 |
Uses it directly the Whisper model to perform Automatic Speech Recognition (i.e Speech-to-Text).
|
|
|
165 |
- Sentiment Analysis: using Hugging Face's default sentiment classifier
|
166 |
- WordCloud: using the wordcloud python library.
|
167 |
"""
|
168 |
+
progress(0, desc="Starting analysis")
|
169 |
if lang == "none":
|
170 |
lang = None
|
171 |
|
|
|
173 |
self.loaded_model = whisper.load_model(size)
|
174 |
self.current_size = size
|
175 |
|
176 |
+
progress(0.20, desc="Transcribing")
|
177 |
results = self.loaded_model.transcribe(audio_file, language=lang)
|
178 |
|
179 |
+
progress(0.40, desc="Summarizing")
|
180 |
# Perform summarization on the transcription
|
181 |
transcription_summary = self.summarizer(
|
182 |
results["text"], max_length=150, min_length=30, do_sample=False
|
|
|
206 |
clean_up_tokenization_spaces=False
|
207 |
)
|
208 |
#### Fin prueba
|
209 |
+
|
210 |
+
progress(0.50, desc="Extracting Keywords")
|
211 |
# Extract keywords using VoiceLabT5
|
212 |
task_prefix = "Keywords: "
|
213 |
input_sequence = task_prefix + results["text"]
|
|
|
220 |
predicted = self.keyword_tokenizer.decode(output[0], skip_special_tokens=True)
|
221 |
keywords = [x.strip() for x in predicted.split(",") if x.strip()]
|
222 |
|
223 |
+
progress(0.80, desc="Extracting Sentiment")
|
224 |
# Sentiment label
|
225 |
label = self.classifier(summary)[0]["label"]
|
226 |
+
|
227 |
+
progress(0.90, desc="Generating Wordcloud")
|
228 |
# WordCloud object
|
229 |
wordcloud = WordCloud(colormap = "Oranges").generate(
|
230 |
results["text"]
|
|
|
337 |
with gr.Row().style(equal_height=True):
|
338 |
clear = gr.ClearButton([audio_file,text, summary, keywords, label, wordcloud_image], scale=1, value="Clear ποΈ",rounded=True)
|
339 |
btn = gr.Button(
|
340 |
+
"Get audio insights π", variant="primary", scale=1, rounded=True
|
341 |
)
|
342 |
btn.click(
|
343 |
gio.from_audio_input,
|