thushalya
commited on
Commit
•
6907c28
1
Parent(s):
aea70a5
Add bar plot for emotions
Browse files
app.py
CHANGED
@@ -18,6 +18,7 @@ from torch.utils.data import Dataset, DataLoader
|
|
18 |
import torch.nn as nn
|
19 |
import os
|
20 |
from dotenv import load_dotenv
|
|
|
21 |
load_dotenv()
|
22 |
|
23 |
|
@@ -220,6 +221,7 @@ def load_model(tweet):
|
|
220 |
print(inputs)
|
221 |
emotion_list = calc_emotion_score(tweet)
|
222 |
print(emotion_list)
|
|
|
223 |
|
224 |
features_list = extract_features(tweet)
|
225 |
for i in features_list.values():
|
@@ -358,22 +360,44 @@ def load_model(tweet):
|
|
358 |
return pred
|
359 |
|
360 |
predicted_class = predict_single_text(model, inputs, device)
|
361 |
-
return predicted_class
|
362 |
# print("Hate speech result",predicted_class)
|
363 |
|
364 |
|
365 |
|
366 |
|
367 |
#Gradio interface
|
|
|
368 |
def greet(tweet):
|
369 |
print("start")
|
370 |
-
prediction = load_model(tweet)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
371 |
prediction_value = round(prediction.item(),2)
|
372 |
# features_list = extract_features(tweet)
|
373 |
# print(personality_detection(tweet))
|
374 |
# print(str(features_list["Average_Word_Length"]))
|
375 |
# print(calc_emotion_score(tweet))
|
376 |
predicted_class = torch.round(prediction).item()
|
|
|
|
|
377 |
print("end")
|
378 |
if (predicted_class==0.0):
|
379 |
label = "Non Hate"
|
|
|
18 |
import torch.nn as nn
|
19 |
import os
|
20 |
from dotenv import load_dotenv
|
21 |
+
import pandas as pd
|
22 |
load_dotenv()
|
23 |
|
24 |
|
|
|
221 |
print(inputs)
|
222 |
emotion_list = calc_emotion_score(tweet)
|
223 |
print(emotion_list)
|
224 |
+
preemotion_list = emotion_list[:]
|
225 |
|
226 |
features_list = extract_features(tweet)
|
227 |
for i in features_list.values():
|
|
|
360 |
return pred
|
361 |
|
362 |
predicted_class = predict_single_text(model, inputs, device)
|
363 |
+
return predicted_class,preemotion_list,personality_list
|
364 |
# print("Hate speech result",predicted_class)
|
365 |
|
366 |
|
367 |
|
368 |
|
369 |
#Gradio interface
|
370 |
+
simple = None
|
371 |
def greet(tweet):
|
372 |
print("start")
|
373 |
+
prediction,preemotion_list,personality_list = load_model(tweet)
|
374 |
+
preemotion_list = [x * 100 for x in preemotion_list]
|
375 |
+
simple = pd.DataFrame(
|
376 |
+
{
|
377 |
+
"keys": ["Anger", "Anticipation", "Disgust", "Fear", "Joy", "Love", "Optimism", "Pessimism", "Sadness","Surprise","Trust"],
|
378 |
+
"values": preemotion_list,
|
379 |
+
}
|
380 |
+
)
|
381 |
+
with gr.Blocks() as bar_plot:
|
382 |
+
bar_plot.load(outputs= gr.BarPlot(
|
383 |
+
simple,
|
384 |
+
x="Emotions",
|
385 |
+
y="Values",
|
386 |
+
title="Simple Bar Plot with made up data",
|
387 |
+
tooltip=["a", "b"],
|
388 |
+
y_lim=[20, 100],
|
389 |
+
))
|
390 |
+
|
391 |
+
bar_plot.launch()
|
392 |
+
|
393 |
prediction_value = round(prediction.item(),2)
|
394 |
# features_list = extract_features(tweet)
|
395 |
# print(personality_detection(tweet))
|
396 |
# print(str(features_list["Average_Word_Length"]))
|
397 |
# print(calc_emotion_score(tweet))
|
398 |
predicted_class = torch.round(prediction).item()
|
399 |
+
print(preemotion_list)
|
400 |
+
print(personality_list)
|
401 |
print("end")
|
402 |
if (predicted_class==0.0):
|
403 |
label = "Non Hate"
|