santarabantoosoo commited on
Commit
76612b7
1 Parent(s): 4f82b3b

adding topic modeling

Browse files
Files changed (3) hide show
  1. app.py +165 -12
  2. wordclouds_Q1 data.png +0 -0
  3. wordclouds_Q2-Q2 data.png +0 -0
app.py CHANGED
@@ -129,10 +129,9 @@ def plot_time_series(choice, keyword, user_keys):
129
  leg = plt.legend(loc='best')
130
  plt.xlabel('Time')
131
  plt.title("keywords quartely analysis (July 2021 - July 2022)")
132
- plt.ylabel(f'Freq. from {user_choice}')
133
  return fig
134
 
135
-
136
  # Wordcloud with anger tweets
137
  angry_tweets = data['tweet'][data["emotion"] == 'anger']
138
  angry_tweets = angry_tweets.apply(format_input, args = [it_stop])
@@ -239,6 +238,54 @@ def display_freq_plot(choice, *args):
239
 
240
  elif choice == "Whole_text":
241
  return plot_time_series(ser_whole_text, keyword, user_keys)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
 
243
 
244
  with gr.Blocks() as demo:
@@ -247,28 +294,134 @@ with gr.Blocks() as demo:
247
  with gr.Tabs():
248
 
249
  with gr.TabItem("Topic modeling"):
250
- gr.Markdown("Nothing here yet")
251
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
252
  with gr.TabItem("Word frequency"):
253
 
254
  inputs = [gr.Radio(choices = ['TFIDF', 'Whole_text'], label = 'Choose ur method'),
255
  gr.Textbox(label = 'word 1'),
256
  gr.Textbox(label = 'word 2'),
257
- gr.Textbox(label = 'word 3'),
258
- gr.Textbox(label = 'word 4')]
259
- plot_output = gr.Plot(elem_id = 1)
260
  freq_button = gr.Button("Submit")
261
-
 
 
 
 
 
 
262
 
263
  with gr.TabItem("Sentiment analysis"):
264
  text_input = gr.Radio(choices = ['Sentiment distribution', 'Word clouds', 'Time series'], label = 'Choose ur plot')
265
  sent_plot = gr.Plot()
266
  sent_button = gr.Button("Submit")
267
-
268
-
269
- sent_button.click(display_plot, inputs=text_input, outputs= sent_plot)
270
- freq_button.click(display_freq_plot, inputs=inputs, outputs=plot_output)
271
 
 
 
 
 
272
 
273
  demo.launch(debug=True, show_error = True);
274
 
 
129
  leg = plt.legend(loc='best')
130
  plt.xlabel('Time')
131
  plt.title("keywords quartely analysis (July 2021 - July 2022)")
132
+ plt.ylabel(f'Freq. from {user_keys}')
133
  return fig
134
 
 
135
  # Wordcloud with anger tweets
136
  angry_tweets = data['tweet'][data["emotion"] == 'anger']
137
  angry_tweets = angry_tweets.apply(format_input, args = [it_stop])
 
238
 
239
  elif choice == "Whole_text":
240
  return plot_time_series(ser_whole_text, keyword, user_keys)
241
+
242
+ def display_output(tweet_index):
243
+ topics = "<ol>\
244
+ <li>Discussion about scientific studies</li>\
245
+ <li>Anxiety about pandemic and the information about it OR Specific people in the context of LC</li>\
246
+ <li>Discussion about LC impact in terms of time periods</li>\
247
+ <li>Discussion about LC impact on patient life (impact on life so far or scope for lifelong impact)</li>\
248
+ <li>Treatment scenario</li>\
249
+ <li>Impact/Consequences of LC on children</li>\
250
+ </ol>"
251
+ item = topic_dist_list[tweet_index]
252
+ distribution = f'<html><body><h3>Topics Distribution</h3>({item[0][0]+1}, {item[0][1]}), ({item[1][0]+1}, {item[1][1]}), ({item[2][0]+1}, {item[2][1]}), ({item[3][0]+1}, {item[3][1]}), ({item[4][0]+1}, {item[4][1]}), ({item[5][0]+1}, {item[5][1]})\
253
+ </body></html>'
254
+ return gr.HTML.update(distribution, visible=True)
255
+
256
+ def display_output_Q2_Q4(tweet_index):
257
+ item = topic_dist_list_Q2_Q4[tweet_index]
258
+ distribution = f'<html><body><h3>Topics Distribution</h3>({item[0][0]+1}, {item[0][1]}), ({item[1][0]+1}, {item[1][1]}), ({item[2][0]+1}, {item[2][1]}), ({item[3][0]+1}, {item[3][1]}), ({item[4][0]+1}, {item[4][1]}), ({item[5][0]+1}, {item[5][1]})\
259
+ </body></html>'
260
+ return gr.HTML.update(distribution, visible=True)
261
+
262
+ # with gr.Blocks() as demo:
263
+ # gr.Markdown("## Choose your adventure")
264
+
265
+ # with gr.Tabs():
266
+
267
+ # with gr.TabItem("Topic modeling"):
268
+ # gr.Markdown("Nothing here yet")
269
+
270
+ # with gr.TabItem("Word frequency"):
271
+
272
+ # inputs = [gr.Radio(choices = ['TFIDF', 'Whole_text'], label = 'Choose ur method'),
273
+ # gr.Textbox(label = 'word 1'),
274
+ # gr.Textbox(label = 'word 2'),
275
+ # gr.Textbox(label = 'word 3'),
276
+ # gr.Textbox(label = 'word 4')]
277
+ # plot_output = gr.Plot(elem_id = 1)
278
+ # freq_button = gr.Button("Submit")
279
+
280
+
281
+ # with gr.TabItem("Sentiment analysis"):
282
+ # text_input = gr.Radio(choices = ['Sentiment distribution', 'Word clouds', 'Time series'], label = 'Choose ur plot')
283
+ # sent_plot = gr.Plot()
284
+ # sent_button = gr.Button("Submit")
285
+
286
+
287
+ # sent_button.click(display_plot, inputs=text_input, outputs= sent_plot)
288
+ # freq_button.click(display_freq_plot, inputs=inputs, outputs=plot_output)
289
 
290
 
291
  with gr.Blocks() as demo:
 
294
  with gr.Tabs():
295
 
296
  with gr.TabItem("Topic modeling"):
297
+ gr.Markdown(
298
+ """
299
+ ## <div style="text-align: center;">Topic modeling analysis on Twitter</div>
300
+ """
301
+ )
302
+ with gr.Tabs():
303
+ with gr.TabItem("July-Semptember 2021"):
304
+ with gr.Row():
305
+ gr.Image("./wordclouds_Q1 data.png", label="July-September 2021")
306
+
307
+
308
+
309
+ tweets_list = ['C\'è uno studio a riguardo condotto proprio sui più giovani che identifica il long covid alla stregua di ogni strascico di malattie infettive polmonari. Il long covid è dannoso come una polmonite in quanto a effetti a lungo termine. Se lo ritrovo te lo passo, ora sono fuori...',
310
+ 'Mio cugino è guarito dal covid dopo 4 mesi di ospedale, di cui più di 2 intubato, grazie alla testardaggine dei medici che hanno fatto di tutto per salvargli la vita a 57 anni. Ora è nella fase long covid per recuperare i danni fisici riportati',
311
+ 'È importante parlare di #LongCovid e sensibilizzare tutti, giovani compresi, che non è un gioco ma una malattia debilitante/invalidante che può stravolgere la vita. Io 39 anni e #LongCovid da 18 mesi (con 4 figli piccoli). #countlongcovid',
312
+ 'Il Long Covid è una diretta conseguenza di quelli che nei primi tempi sono stati abbandonati a se stessi giorni e giorni e curati solo quando molto aggravati, in ospedale. Se ti curi tempestivamente non hai nessuna conseguenza.',
313
+ 'Non sai di cosa parli sono stato un mese attaccato ad un respiratore e sono salvo per miracolo. Ma questo è niente in confronto con il #LongCovid che mi porto dietro da mesi e mesi. Siete dei criminali a pensare ch\'è meglio curare che prevenire. Dei pazzi da rinchiudere',
314
+ 'A chi dice ""Il COVID è innocuo per i bambini"". Oltre ad alcuni decessi 500+ bambini sono morti di COVID negli USA 2020) c\'è #LongCOVID. Se ne parla in questo studio: ""Studio inglese rileva che il COVID a lungo colpisce fino a 1 bambino su 7 mesi dopo l\'infezione']
315
+
316
+ q1_data_topic_list=['0. Discussion about scientific studies','1. Anxiety about pandemic and the information about it OR Specific people in the context of LC',
317
+ '2. Discussion about LC impact in terms of time periods','3. Discussion about LC impact on patient life (impact on life so far or scope for lifelong impact)' ,
318
+ '4. Treatment scenario', '5. Impact/Consequences of LC on children']
319
+
320
+
321
+ topic_dist_list=[[(0, 0.03202321), (1, 0.26949906), (2, 0.05191976), (3, 0.24642), (4, 0.33530965), (5, 0.064828366)],
322
+ [(0, 0.04221856), (1, 0.0374047), (2, 0.06841562), (3, 0.07528768), (4, 0.3782018), (5, 0.3984716)],
323
+ [(0, 0.2181524), (1, 0.13380228), (2, 0.021277282), (3, 0.48123622), (4, 0.01883339), (5, 0.12669843)],
324
+ [(0, 0.0145399235), (1, 0.01287178), (2, 0.43158862), (3, 0.24750596), (4, 0.264914), (5, 0.028579665)],
325
+ [(0, 0.016303344), (1, 0.014450405), (2, 0.36162496), (3, 0.48426068), (4, 0.023487965), (5, 0.09987263)],
326
+ [(0, 0.018612841), (1, 0.016472807), (2, 0.44922927), (3, 0.033633586), (4, 0.026889767), (5, 0.45516175)],
327
+ [(0, 0.016305258), (1, 0.014453228), (2, 0.7628153), (3, 0.029092493), (4, 0.14613572), (5, 0.031198042)],
328
+ [(0, 0.016303508), (1, 0.014449066), (2, 0.15605325), (3, 0.029179793), (4, 0.023376595), (5, 0.7606378)]]
329
+
330
+ topics = '<html><body>\
331
+ <h3><b>Topics July to Sept, 2021</b></h3>\
332
+ <ol type="1">\
333
+ <li>1. Discussion about scientific studies</li>\
334
+ <li>2. Anxiety about pandemic and the information about it OR Specific people in the context of LC</li>\
335
+ <li>3. Discussion about LC impact in terms of time periods</li>\
336
+ <li>4. Discussion about LC impact on patient life (impact on life so far or scope for lifelong impact)</li>\
337
+ <li>5. Treatment scenario</li>\
338
+ <li>6. Impact/Consequences of LC on children</li>\
339
+ </ol>\
340
+ </body></html>'
341
+
342
+ Q1_topics = gr.HTML(topics, visible=True)
343
+
344
+ gr.Markdown(
345
+ """
346
+ ### Test our topic modeling model : select a tweet and check the topics distribution !
347
+ """
348
+ )
349
+
350
+ tweet = gr.Dropdown(tweets_list, label="Example tweets", interactive=True, type="index")
351
+
352
+ model_output = gr.HTML("", visible=False)
353
+ tweet.change(display_output, tweet, model_output)
354
+
355
+ with gr.TabItem("October 2021-July 2022"):
356
+
357
+ topic_dist_list_Q2_Q4=[[(0, 0.4377157), (1, 0.05924045), (2, 0.1525337), (3, 0.1941842), (4, 0.075339705), (5, 0.08098622)],
358
+ [(0, 0.16064012), (1, 0.063850455), (2, 0.08664099), (3, 0.2870743), (4, 0.081202514), (5, 0.32059166)],
359
+ [(0, 0.14904374), (1, 0.059243646), (2, 0.08039133), (3, 0.26638654), (4, 0.07534457), (5, 0.36959016)],
360
+ [(0, 0.14897935), (1, 0.059245925), (2, 0.08039324), (3, 0.41068354), (4, 0.14752874), (5, 0.15316921)],
361
+ [(0, 0.089826144), (1, 0.069229595), (2, 0.09393969), (3, 0.5643193), (4, 0.08804329), (5, 0.09464199)],
362
+ [(0, 0.08284077), (1, 0.29718927), (2, 0.08663448), (3, 0.36485678), (4, 0.08119658), (5, 0.08728213)]]
363
+
364
+ with gr.Row():
365
+ gr.Image("./wordclouds_Q2-Q2 data.png", label="October 2021-July 2022")
366
+
367
+ Q2_Q4_topics = '<html><body>\
368
+ <h3><b>Topics October 2021 to July 2022</b></h3>\
369
+ <ol type="1">\
370
+ <li>1. Variants</li>\
371
+ <li>2. Vaccine side-effects (and general anti-vax/ anti-LC narrative)</li>\
372
+ <li>3. Aftermath of LC or vaccine</li>\
373
+ <li>4. Impact of LC in terms of time OR Risks/Symptoms of LC</li>\
374
+ <li>5. Anger or anxiety about LC information</li>\
375
+ <li>6. Discussion or Information about the science/knowledge surrounding LC</li>\
376
+ </ol>\
377
+ </body></html>'
378
+
379
+
380
+ Q2_Q4_topics_html = gr.HTML(Q2_Q4_topics, visible=True)
381
+
382
+ tweet_list_Q2_Q4=["Omicron e Long Covid: palpitazioni e perdita d'udito tra i sintomi - #Omicron #Covid: #palpitazioni ",
383
+ 'Long Covid e trombosi. La correlazione è spiegata da Giovanni Esposito, Presidente GISE, in un articolo sul sito https://t.co/8TdI9nhDHY e avvalorata da uno studio svedese pubblicato sul British Medical Journal. https://t.co/UebaXUtfbz',
384
+ 'Peccato che il ""long COVID"" che è proprio ciò di cui parla l\'esimio dottore citato determini una alterazione o soppressione del sistema immunitario di cui si sa ancora poco ma che può portare a conseguenze fatali per il paziente.',
385
+ 'Il Long covid rappresentava un problema solo fino ad aprile 2021, i vaccini hanno molto ridotto l\'impatto e la gravità delle patologie a lungo termine, in pratica si può dire che il long covid non esiste più',
386
+ 'Sicuro, 100-150 morti al giorno, 6 ondate l anno, rischio long covid, rischio evoluzionario, e via dicendo — finitissimo',
387
+ 'le cure le fai giorno dopo giorno... ci sono casi di long-covid dopo 6 mesi dall\'infezione. [Vaccino > >Cure] è un dato di fatto',
388
+ 'A parte il rischio di sviluppare il #longcovid, il pericolo grave di lasciar circolare il virus e di farlo diventare endemico come preconizza il governo e lo sciagurato #speranza non è nel decorso del singolo caso ma nell\'aumento proporzionale dell\'insorgere di nuove varianti']
389
+
390
+ gr.Markdown(
391
+ """
392
+ ### Test our topic modeling model : select a tweet and check the topics distribution !
393
+ """
394
+ )
395
+
396
+ tweet_Q2_Q4 = gr.Dropdown(tweet_list_Q2_Q4, label="Example tweets", interactive=True, type="index")
397
+
398
+ model_output_Q2_Q4 = gr.HTML("", visible=False)
399
+ tweet_Q2_Q4.change(display_output_Q2_Q4, tweet_Q2_Q4, model_output_Q2_Q4)
400
  with gr.TabItem("Word frequency"):
401
 
402
  inputs = [gr.Radio(choices = ['TFIDF', 'Whole_text'], label = 'Choose ur method'),
403
  gr.Textbox(label = 'word 1'),
404
  gr.Textbox(label = 'word 2'),
405
+ gr.Textbox(label = 'word 3')]
406
+ plot_output = gr.Plot()
 
407
  freq_button = gr.Button("Submit")
408
+
409
+ freq_button.click(display_freq_plot, inputs=inputs, outputs=plot_output)
410
+ gr.Examples(
411
+ examples= [['Stanchezza', "l'età", '#LongCovidKids'], ['nebbia cognitiva', 'mal di testa', 'Dura PROVA']],
412
+ inputs= [gr.Textbox(),gr.Textbox(),gr.Textbox()],
413
+ outputs=plot_output,
414
+ fn=display_freq_plot)
415
 
416
  with gr.TabItem("Sentiment analysis"):
417
  text_input = gr.Radio(choices = ['Sentiment distribution', 'Word clouds', 'Time series'], label = 'Choose ur plot')
418
  sent_plot = gr.Plot()
419
  sent_button = gr.Button("Submit")
 
 
 
 
420
 
421
+ sent_button.click(display_plot, inputs=text_input, outputs= sent_plot)
422
+
423
+
424
+ demo.launch(debug=True, show_error = True);
425
 
426
  demo.launch(debug=True, show_error = True);
427
 
wordclouds_Q1 data.png ADDED
wordclouds_Q2-Q2 data.png ADDED