Spaces:
Runtime error
Runtime error
Merge pull request #3 from arielhsieh8/main
Browse files- .github/workflows/sync_to_huggingface_hub.yml +1 -1
- README.md +8 -6
- app.py +74 -43
- requirements.txt +0 -2
.github/workflows/sync_to_huggingface_hub.yml
CHANGED
@@ -17,4 +17,4 @@ jobs:
|
|
17 |
- name: Push to hub
|
18 |
env:
|
19 |
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
20 |
-
run: git push --force https://Ariel8:$HF_TOKEN@huggingface.co/spaces/Ariel8/
|
|
|
17 |
- name: Push to hub
|
18 |
env:
|
19 |
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
20 |
+
run: git push --force https://Ariel8:$HF_TOKEN@huggingface.co/spaces/Ariel8/toxic-tweets main
|
README.md
CHANGED
@@ -1,12 +1,14 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: streamlit
|
7 |
-
sdk_version: 1.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
-
# cs-uy-4613-project milestone
|
|
|
|
|
|
1 |
---
|
2 |
+
title: Toxic Tweets
|
3 |
+
emoji: π
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: green
|
6 |
sdk: streamlit
|
7 |
+
sdk_version: 1.19.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
+
# cs-uy-4613-project milestone 3
|
13 |
+
|
14 |
+
https://huggingface.co/spaces/Ariel8/Toxic-Tweets
|
app.py
CHANGED
@@ -1,50 +1,81 @@
|
|
1 |
import streamlit as st #Web App
|
2 |
from transformers import pipeline
|
3 |
-
from
|
|
|
|
|
|
|
4 |
|
5 |
#title
|
6 |
-
st.title("
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
|
50 |
|
|
|
1 |
import streamlit as st #Web App
|
2 |
from transformers import pipeline
|
3 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
4 |
+
import torch
|
5 |
+
import numpy as np
|
6 |
+
import pandas as pd
|
7 |
|
8 |
#title
|
9 |
+
st.title("Toxic Tweet Classification / Sentiment Analysis")
|
10 |
+
|
11 |
+
selection = st.selectbox("Select fine-tuned model",("Ariel8/toxic-tweets-classification","roberta-large-mnli","twitter-XLM-roBERTa-base"))
|
12 |
+
|
13 |
+
if selection == "Ariel8/toxic-tweets-classification":
|
14 |
+
tokenizer = AutoTokenizer.from_pretrained("Ariel8/toxic-tweets-classification")
|
15 |
+
model = AutoModelForSequenceClassification.from_pretrained("Ariel8/toxic-tweets-classification")
|
16 |
+
|
17 |
+
tweets = ["BlackKite being a faggot",
|
18 |
+
"Yo bitch Ja Rule is more succesful then you'll ever be whats up with you and hating you sad mofuckas...i should bitch slap ur pethedic white faces and get you to kiss my ass you guys sicken me. Ja rule is about pride in da music man. dont diss that shit on him. and nothin is wrong bein like tupac he was a brother too...fuckin white boys get things right next time.,",
|
19 |
+
":Dear god this site is horrible.",
|
20 |
+
"I think its crap that the link to roggenbier is to this article. Somebody that knows how to do things should change it.",
|
21 |
+
":::::I have added more wikilinks to my sections and included more secondary sources as you suggested. For all the citations under human disease section, I went through them and exchanged review articles for the primary sources. Thanks again for all your input!",
|
22 |
+
"DJ Robinson is gay as hell! he sucks his dick so much!!!!!",
|
23 |
+
"I WILL BURN YOU TO HELL IF YOU REVOKE MY TALK PAGE ACCESS!!!!!!!!!!!!!",
|
24 |
+
"um, taking a shot here... Um lets say Three separate people whos wills are to each other.",
|
25 |
+
"How dare you vandalize that page about the HMS Beagle! Don't vandalize again, demon!",
|
26 |
+
":Thanks for the comment about Wiki-defenderness. I like that one. I usually wikiling Wiki-defender. I agree that at first he was somewhat innocent but now have my doubts as he is being really agressive about the whole matter."]
|
27 |
+
|
28 |
+
text = st.text_input("Enter Text here for Toxicity Classification:","Artificial Intelligence is useful")
|
29 |
+
|
30 |
+
if st.button("Run Toxicity Classification of Text (and prepopulated Tweets)"):
|
31 |
+
tweets.append(text)
|
32 |
+
|
33 |
+
labels = ["toxic", "severe_toxic", "obscene", "threat", "insult", "identity_hate"]
|
34 |
+
main_class = []
|
35 |
+
toxic_types = []
|
36 |
+
|
37 |
+
for i in range(len(tweets)):
|
38 |
+
batch = tokenizer(tweets[i], truncation=True, padding='max_length', return_tensors="pt")
|
39 |
+
with torch.no_grad():
|
40 |
+
outputs = model(**batch)
|
41 |
+
predictions = torch.sigmoid(outputs.logits)*100
|
42 |
+
probs = predictions[0].tolist()
|
43 |
+
|
44 |
+
first_max = max(probs)
|
45 |
+
fm_index = probs.index(first_max)
|
46 |
+
main_class.append((first_max,fm_index))
|
47 |
+
second_max = max(probs[2:])
|
48 |
+
sm_index = probs.index(second_max)
|
49 |
+
toxic_types.append((second_max,sm_index))
|
50 |
+
|
51 |
+
|
52 |
+
d = {'Tweet':tweets,'Highest Class':[labels[main_class[i][1]] for i in range(len(main_class))],'Classification Score':[round(main_class[i][0],3) for i in range(len(main_class))],
|
53 |
+
'Toxicity Type':[labels[toxic_types[i][1]] for i in range(len(toxic_types))],'Toxicity Type Score':[round(toxic_types[i][0],3) for i in range(len(toxic_types))]}
|
54 |
+
dataframe = pd.DataFrame(data=d)
|
55 |
+
st.table(dataframe)
|
56 |
+
else:
|
57 |
+
data = []
|
58 |
+
text = st.text_input("Enter text here for Sentiment Analysis:","Artificial Intelligence is useful")
|
59 |
+
data.append(text)
|
60 |
+
if selection == "roberta-large-mnli":
|
61 |
+
#1
|
62 |
+
if st.button("Run Sentiment Analysis of Text"):
|
63 |
+
model_path = "roberta-large-mnli"
|
64 |
+
sentiment_pipeline = pipeline(model=model_path)
|
65 |
+
result = sentiment_pipeline(data)
|
66 |
+
label = result[0]["label"]
|
67 |
+
score = result[0]["score"]
|
68 |
+
st.write("The classification of the given text is " + label + " with a score of " + str(score))
|
69 |
+
elif selection == "twitter-XLM-roBERTa-base":
|
70 |
+
#2
|
71 |
+
if st.button("Run Sentiment Analysis of Text"):
|
72 |
+
model_path = "cardiffnlp/twitter-xlm-roberta-base-sentiment"
|
73 |
+
sentiment_task = pipeline("sentiment-analysis", model=model_path, tokenizer=model_path)
|
74 |
+
result = sentiment_task(text)
|
75 |
+
label = result[0]["label"].capitalize()
|
76 |
+
score = result[0]["score"]
|
77 |
+
st.write("The classification of the given text is " + label + " with a score of " + str(score))
|
78 |
+
|
79 |
|
80 |
|
81 |
|
requirements.txt
CHANGED
@@ -2,5 +2,3 @@ streamlit
|
|
2 |
transformers
|
3 |
pipeline
|
4 |
tensorflow
|
5 |
-
pysentimiento
|
6 |
-
sentencepiece
|
|
|
2 |
transformers
|
3 |
pipeline
|
4 |
tensorflow
|
|
|
|