User1342 commited on
Commit
6a4d73b
·
1 Parent(s): 386ac0c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -9
app.py CHANGED
@@ -277,6 +277,7 @@ def button_pressed(text_box):
277
 
278
  tweets = 0
279
 
 
280
  for user in tweet_data:
281
  data = tweet_data[user]
282
 
@@ -300,6 +301,7 @@ def button_pressed(text_box):
300
  total_types_count[type] = total_types_count[type] + 1
301
 
302
  total_average_toxicity.append(data["average_toxicity"])
 
303
  total_average_severe_toxicity.append(data["average_severe_toxicity"])
304
  total_average_obscene.append(data["average_obscene"])
305
  total_average_identity_attack.append(data["average_identity_attack"])
@@ -349,6 +351,22 @@ def button_pressed(text_box):
349
 
350
  sentiment_plot_fig = go.Figure(sentiment_plot)
351
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
352
  # Comprise elements for 'type' plot
353
  colours = []
354
  keys = list(total_types_count.keys())
@@ -374,10 +392,10 @@ def button_pressed(text_box):
374
 
375
  # Comprise text for summary label
376
  original_text = "A total number of {} recent tweets in @{}'s mentions and timeline were reviewed, of which @{} was exposed to {} users via mentions and " \
377
- "{} directly via following them.".format(tweets, text_box, text_box, mentions, following)
378
 
379
  text = original_text
380
-
381
  high_identifiers = []
382
  extreme_identifiers = []
383
 
@@ -430,15 +448,16 @@ def button_pressed(text_box):
430
 
431
  text = text[:len(text - 1)] + " language."
432
 
433
- if total_average_neg_sentiment > 0.7 and total_average_neg_sentiment > total_average_pos_sentiment:
434
  text = text + " @{} is experiencing a high amount of negative sentiment content.".format(text_box)
435
- elif total_average_neg_sentiment > 0.9 and total_average_neg_sentiment > total_average_pos_sentiment:
436
  text = text + " '{} is experiencing a significantly high amount of negative sentiment content.".format(text_box)
437
 
438
  if len(text) == len(original_text):
439
- text = text + " No excessive hate speech or low sentiment was observed in @{}'s mentions or timeline.".format(text_box)
440
-
441
- return [toxicity_plot_fig, sentiment_plot_fig, fig, text]
 
442
 
443
 
444
  # The main chunk of code that uses Gradio blocks to create the UI
@@ -465,7 +484,11 @@ with block:
465
  sentiment_plot = gr.Plot(label="Sentiment Graph")
466
  gr.HTML(value="<br>")
467
  type_plot = gr.Plot(label="Content Type Graph")
468
- btn.click(fn=button_pressed, inputs=[text_input], outputs=[toxicity_plot, sentiment_plot, type_plot, output_label])
 
 
 
 
469
  gr.Markdown(
470
  """___
471
  <p style='text-align: center'>
@@ -477,4 +500,4 @@ with block:
477
  # block.attach_load_events()
478
 
479
  # Launcg the page
480
- block.launch(enable_queue=True)
 
277
 
278
  tweets = 0
279
 
280
+ user_data = {}
281
  for user in tweet_data:
282
  data = tweet_data[user]
283
 
 
301
  total_types_count[type] = total_types_count[type] + 1
302
 
303
  total_average_toxicity.append(data["average_toxicity"])
304
+ user_data[user.name] = data["average_toxicity"]
305
  total_average_severe_toxicity.append(data["average_severe_toxicity"])
306
  total_average_obscene.append(data["average_obscene"])
307
  total_average_identity_attack.append(data["average_identity_attack"])
 
351
 
352
  sentiment_plot_fig = go.Figure(sentiment_plot)
353
 
354
+ # User distrabution plot
355
+ user_plot = dict({
356
+ "data": [{"type": "bar",
357
+ "x": list(user_data.keys()),
358
+ "y": list(user_data.values())}],
359
+ "layout": {"title": {"text": "Hate Speech By Observed User"}}
360
+ })
361
+
362
+ user_plot_fig = go.Figure(user_plot)
363
+
364
+ # Distrabution Pie
365
+ labels = ['Timeline Users Observed', 'Observed Users Mentioning @{}'.format(text_box)]
366
+ values = [following,mentions]
367
+
368
+ distrabution_fig = go.Figure(data=[go.Pie(labels=labels, values=values, title="Distribution Of Observed Users")])
369
+
370
  # Comprise elements for 'type' plot
371
  colours = []
372
  keys = list(total_types_count.keys())
 
392
 
393
  # Comprise text for summary label
394
  original_text = "A total number of {} recent tweets in @{}'s mentions and timeline were reviewed, of which @{} was exposed to {} users via mentions and " \
395
+ "{} directly via following them.".format(tweets, text_box, text_box, mentions, following)
396
 
397
  text = original_text
398
+
399
  high_identifiers = []
400
  extreme_identifiers = []
401
 
 
448
 
449
  text = text[:len(text - 1)] + " language."
450
 
451
+ if total_average_neg_sentiment > 0.7 and total_average_neg_sentiment > total_average_pos_sentiment:
452
  text = text + " @{} is experiencing a high amount of negative sentiment content.".format(text_box)
453
+ elif total_average_neg_sentiment > 0.9 and total_average_neg_sentiment > total_average_pos_sentiment:
454
  text = text + " '{} is experiencing a significantly high amount of negative sentiment content.".format(text_box)
455
 
456
  if len(text) == len(original_text):
457
+ text = text + " No excessive hate speech or low sentiment was observed in @{}'s mentions or timeline.".format(
458
+ text_box)
459
+
460
+ return [toxicity_plot_fig, sentiment_plot_fig, fig, text,user_plot_fig,distrabution_fig]
461
 
462
 
463
  # The main chunk of code that uses Gradio blocks to create the UI
 
484
  sentiment_plot = gr.Plot(label="Sentiment Graph")
485
  gr.HTML(value="<br>")
486
  type_plot = gr.Plot(label="Content Type Graph")
487
+ gr.HTML(value="<br>")
488
+ with gr.Row().style(equal_height=True):
489
+ user_plot = gr.Plot(label="Observed Users")
490
+ format_type_plot = gr.Plot(label="Distribution")
491
+ btn.click(fn=button_pressed, inputs=[text_input], outputs=[toxicity_plot, sentiment_plot, type_plot, output_label,user_plot,format_type_plot])
492
  gr.Markdown(
493
  """___
494
  <p style='text-align: center'>
 
500
  # block.attach_load_events()
501
 
502
  # Launcg the page
503
+ block.launch(enable_queue=True,show_api=False)