storresbusquets commited on
Commit
221de09
ยท
1 Parent(s): 3dd2c60

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -3
app.py CHANGED
@@ -25,7 +25,7 @@ class GradioInference:
25
  # Initialize Pytube Object
26
  self.yt = None
27
 
28
- # Initialize summary model
29
  self.summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
30
 
31
  # Initialize VoiceLabT5 model and tokenizer
@@ -39,7 +39,7 @@ class GradioInference:
39
  # Sentiment Classifier
40
  self.classifier = pipeline("text-classification", model="lxyuan/distilbert-base-multilingual-cased-sentiments-student", return_all_scores=False)
41
 
42
-
43
  self.tokenizer = AutoTokenizer.from_pretrained("csebuetnlp/mT5_multilingual_XLSum")
44
  self.model = AutoModelForSeq2SeqLM.from_pretrained("csebuetnlp/mT5_multilingual_XLSum")
45
 
@@ -71,10 +71,12 @@ class GradioInference:
71
  self.current_size = size
72
 
73
  progress(0.20, desc="Transcribing")
 
74
  # Transcribe the audio extracted from pytube
75
  results = self.loaded_model.transcribe(path, language=lang)
76
 
77
  progress(0.40, desc="Summarizing")
 
78
  # Perform summarization on the transcription
79
  transcription_summary = self.summarizer(
80
  results["text"], max_length=150, min_length=30, do_sample=False
@@ -106,6 +108,7 @@ class GradioInference:
106
  #### Fin prueba
107
 
108
  progress(0.50, desc="Extracting Keywords")
 
109
  # Extract keywords using VoiceLabT5
110
  task_prefix = "Keywords: "
111
  input_sequence = task_prefix + results["text"]
@@ -135,6 +138,7 @@ class GradioInference:
135
  formatted_sentiment = sentiment_emojis.get(label, label)
136
 
137
  progress(0.90, desc="Generating Wordcloud")
 
138
  # Generate WordCloud object
139
  wordcloud = WordCloud(colormap = "Oranges").generate(results["text"])
140
 
@@ -166,7 +170,7 @@ class GradioInference:
166
  - link: a YouTube URL.
167
  """
168
  if not link:
169
- return "", "..."
170
 
171
  self.yt = YouTube(link)
172
  return self.yt.thumbnail_url, self.yt.title
@@ -182,6 +186,7 @@ class GradioInference:
182
  - WordCloud: using the wordcloud python library.
183
  """
184
  progress(0, desc="Starting analysis")
 
185
  if lang == "none":
186
  lang = None
187
 
@@ -190,9 +195,11 @@ class GradioInference:
190
  self.current_size = size
191
 
192
  progress(0.20, desc="Transcribing")
 
193
  results = self.loaded_model.transcribe(audio_file, language=lang)
194
 
195
  progress(0.40, desc="Summarizing")
 
196
  # Perform summarization on the transcription
197
  transcription_summary = self.summarizer(
198
  results["text"], max_length=150, min_length=30, do_sample=False
@@ -224,6 +231,7 @@ class GradioInference:
224
  #### Fin prueba
225
 
226
  progress(0.50, desc="Extracting Keywords")
 
227
  # Extract keywords using VoiceLabT5
228
  task_prefix = "Keywords: "
229
  input_sequence = task_prefix + results["text"]
@@ -282,6 +290,7 @@ title = "YouTube Insights"
282
  description = "Your AI-powered video analytics tool"
283
 
284
  block = gr.Blocks()
 
285
  with block as demo:
286
  gr.HTML(
287
  """
@@ -298,6 +307,7 @@ with block as demo:
298
  with gr.Group():
299
  with gr.Tab("From YouTube ๐Ÿ“น"):
300
  with gr.Box():
 
301
  with gr.Row().style(equal_height=True):
302
  size = gr.Dropdown(
303
  label="Model Size", choices=gio.sizes, value="base"
@@ -309,6 +319,7 @@ with block as demo:
309
  label="YouTube Link", placeholder="Enter YouTube link..."
310
  )
311
  title = gr.Label(label="Video Title")
 
312
  with gr.Row().style(equal_height=True):
313
  img = gr.Image(label="Thumbnail", rounded=True)
314
  text = gr.Textbox(
@@ -316,6 +327,7 @@ with block as demo:
316
  placeholder="Transcription Output...",
317
  lines=10,
318
  ).style(show_copy_button=True, container=True)
 
319
  with gr.Row().style(equal_height=True):
320
  summary = gr.Textbox(
321
  label="Summary", placeholder="Summary Output...", lines=5
@@ -325,6 +337,7 @@ with block as demo:
325
  ).style(show_copy_button=True, container=True)
326
  label = gr.Label(label="Sentiment Analysis")
327
  wordcloud_image = gr.Image(label="WordCloud")
 
328
  with gr.Row().style(equal_height=True):
329
  clear = gr.ClearButton(
330
  [link, title, img, text, summary, keywords, label, wordcloud_image], scale=1, value="Clear ๐Ÿ—‘๏ธ", rounded=True
@@ -339,6 +352,7 @@ with block as demo:
339
 
340
  with gr.Tab("From Audio file ๐ŸŽ™๏ธ"):
341
  with gr.Box():
 
342
  with gr.Row().style(equal_height=True):
343
  size = gr.Dropdown(
344
  label="Model Size", choices=gio.sizes, value="base"
@@ -347,12 +361,14 @@ with block as demo:
347
  label="Language (Optional)", choices=gio.langs, value="none"
348
  )
349
  audio_file = gr.Audio(type="filepath")
 
350
  with gr.Row().style(equal_height=True):
351
  text = gr.Textbox(
352
  label="Transcription",
353
  placeholder="Transcription Output...",
354
  lines=10,
355
  ).style(show_copy_button=True, container=False)
 
356
  with gr.Row().style(equal_height=True):
357
  summary = gr.Textbox(
358
  label="Summary", placeholder="Summary Output", lines=5
@@ -362,6 +378,7 @@ with block as demo:
362
  )
363
  label = gr.Label(label="Sentiment Analysis")
364
  wordcloud_image = gr.Image(label="WordCloud")
 
365
  with gr.Row().style(equal_height=True):
366
  clear = gr.ClearButton([audio_file,text, summary, keywords, label, wordcloud_image], scale=1, value="Clear ๐Ÿ—‘๏ธ",rounded=True)
367
  btn = gr.Button(
@@ -422,6 +439,9 @@ with block:
422
  """
423
  <div style="text-align: center; max-width: 500px; margin: 0 auto;">
424
  <p style="margin-bottom: 10px; font-size: 96%">
 
 
 
425
  2023 Master in Big Data & Data Science - Universidad Complutense de Madrid
426
  </p>
427
  </div>
 
25
  # Initialize Pytube Object
26
  self.yt = None
27
 
28
+ # Initialize summary model for English
29
  self.summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
30
 
31
  # Initialize VoiceLabT5 model and tokenizer
 
39
  # Sentiment Classifier
40
  self.classifier = pipeline("text-classification", model="lxyuan/distilbert-base-multilingual-cased-sentiments-student", return_all_scores=False)
41
 
42
+ # Initialize Multilingual summary model
43
  self.tokenizer = AutoTokenizer.from_pretrained("csebuetnlp/mT5_multilingual_XLSum")
44
  self.model = AutoModelForSeq2SeqLM.from_pretrained("csebuetnlp/mT5_multilingual_XLSum")
45
 
 
71
  self.current_size = size
72
 
73
  progress(0.20, desc="Transcribing")
74
+
75
  # Transcribe the audio extracted from pytube
76
  results = self.loaded_model.transcribe(path, language=lang)
77
 
78
  progress(0.40, desc="Summarizing")
79
+
80
  # Perform summarization on the transcription
81
  transcription_summary = self.summarizer(
82
  results["text"], max_length=150, min_length=30, do_sample=False
 
108
  #### Fin prueba
109
 
110
  progress(0.50, desc="Extracting Keywords")
111
+
112
  # Extract keywords using VoiceLabT5
113
  task_prefix = "Keywords: "
114
  input_sequence = task_prefix + results["text"]
 
138
  formatted_sentiment = sentiment_emojis.get(label, label)
139
 
140
  progress(0.90, desc="Generating Wordcloud")
141
+
142
  # Generate WordCloud object
143
  wordcloud = WordCloud(colormap = "Oranges").generate(results["text"])
144
 
 
170
  - link: a YouTube URL.
171
  """
172
  if not link:
173
+ return None, "..."
174
 
175
  self.yt = YouTube(link)
176
  return self.yt.thumbnail_url, self.yt.title
 
186
  - WordCloud: using the wordcloud python library.
187
  """
188
  progress(0, desc="Starting analysis")
189
+
190
  if lang == "none":
191
  lang = None
192
 
 
195
  self.current_size = size
196
 
197
  progress(0.20, desc="Transcribing")
198
+
199
  results = self.loaded_model.transcribe(audio_file, language=lang)
200
 
201
  progress(0.40, desc="Summarizing")
202
+
203
  # Perform summarization on the transcription
204
  transcription_summary = self.summarizer(
205
  results["text"], max_length=150, min_length=30, do_sample=False
 
231
  #### Fin prueba
232
 
233
  progress(0.50, desc="Extracting Keywords")
234
+
235
  # Extract keywords using VoiceLabT5
236
  task_prefix = "Keywords: "
237
  input_sequence = task_prefix + results["text"]
 
290
  description = "Your AI-powered video analytics tool"
291
 
292
  block = gr.Blocks()
293
+
294
  with block as demo:
295
  gr.HTML(
296
  """
 
307
  with gr.Group():
308
  with gr.Tab("From YouTube ๐Ÿ“น"):
309
  with gr.Box():
310
+
311
  with gr.Row().style(equal_height=True):
312
  size = gr.Dropdown(
313
  label="Model Size", choices=gio.sizes, value="base"
 
319
  label="YouTube Link", placeholder="Enter YouTube link..."
320
  )
321
  title = gr.Label(label="Video Title")
322
+
323
  with gr.Row().style(equal_height=True):
324
  img = gr.Image(label="Thumbnail", rounded=True)
325
  text = gr.Textbox(
 
327
  placeholder="Transcription Output...",
328
  lines=10,
329
  ).style(show_copy_button=True, container=True)
330
+
331
  with gr.Row().style(equal_height=True):
332
  summary = gr.Textbox(
333
  label="Summary", placeholder="Summary Output...", lines=5
 
337
  ).style(show_copy_button=True, container=True)
338
  label = gr.Label(label="Sentiment Analysis")
339
  wordcloud_image = gr.Image(label="WordCloud")
340
+
341
  with gr.Row().style(equal_height=True):
342
  clear = gr.ClearButton(
343
  [link, title, img, text, summary, keywords, label, wordcloud_image], scale=1, value="Clear ๐Ÿ—‘๏ธ", rounded=True
 
352
 
353
  with gr.Tab("From Audio file ๐ŸŽ™๏ธ"):
354
  with gr.Box():
355
+
356
  with gr.Row().style(equal_height=True):
357
  size = gr.Dropdown(
358
  label="Model Size", choices=gio.sizes, value="base"
 
361
  label="Language (Optional)", choices=gio.langs, value="none"
362
  )
363
  audio_file = gr.Audio(type="filepath")
364
+
365
  with gr.Row().style(equal_height=True):
366
  text = gr.Textbox(
367
  label="Transcription",
368
  placeholder="Transcription Output...",
369
  lines=10,
370
  ).style(show_copy_button=True, container=False)
371
+
372
  with gr.Row().style(equal_height=True):
373
  summary = gr.Textbox(
374
  label="Summary", placeholder="Summary Output", lines=5
 
378
  )
379
  label = gr.Label(label="Sentiment Analysis")
380
  wordcloud_image = gr.Image(label="WordCloud")
381
+
382
  with gr.Row().style(equal_height=True):
383
  clear = gr.ClearButton([audio_file,text, summary, keywords, label, wordcloud_image], scale=1, value="Clear ๐Ÿ—‘๏ธ",rounded=True)
384
  btn = gr.Button(
 
439
  """
440
  <div style="text-align: center; max-width: 500px; margin: 0 auto;">
441
  <p style="margin-bottom: 10px; font-size: 96%">
442
+ Trabajo de Fin de Mรกster - Grupo 3
443
+ </p>
444
+ <p style="margin-bottom: 10px; font-size: 90%">
445
  2023 Master in Big Data & Data Science - Universidad Complutense de Madrid
446
  </p>
447
  </div>