JulianHame
commited on
Commit
•
050c119
1
Parent(s):
8bc44c7
Update app.py
Browse files
app.py
CHANGED
@@ -1,45 +1,24 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
|
5 |
-
st.image("https://www.pngall.com/wp-content/uploads/5/Emotion-Transparent.png")
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
options = ["DistilBERT", "Toxicity-Classifier", "SiEBERT", "Twitter-roBERTa"],
|
16 |
-
)
|
17 |
|
18 |
-
|
19 |
-
if selection == "DistilBERT":
|
20 |
-
pipe = pipeline(model = "distilbert-base-uncased-finetuned-sst-2-english")
|
21 |
-
if selection == "Toxicity-Classifier":
|
22 |
-
pipe = pipeline(model = "JulianHame/Toxicity-Classifier")
|
23 |
-
if selection == "Twitter-roBERTa":
|
24 |
-
pipe = pipeline(model = "unitary/toxic-bert")
|
25 |
-
if selection == "SiEBERT":
|
26 |
-
pipe = pipeline(model = "siebert/sentiment-roberta-large-english")
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
st.caption('Twitter-roBERTa - A model trained on over 124M tweets. Labels text as POSITIVE, NEGATIVE or NEUTRAL. Developed by cardiffnlp.')
|
33 |
-
|
34 |
-
st.write("---")
|
35 |
-
st.header('Step 2 - Enter some text')
|
36 |
-
text = st.text_area('The sentiment of the text entered here will be determined based on the model you chose above.',
|
37 |
-
value = "It was the best of times, it was the worst of times.")
|
38 |
-
|
39 |
-
st.write("---")
|
40 |
-
st.header('Step 3 - View your results')
|
41 |
-
|
42 |
-
if text:
|
43 |
-
st.write('Model used: ', selection)
|
44 |
-
out = pipe(text)
|
45 |
-
st.json(out)
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
+
import tensorflow as tf
|
4 |
+
import numpy as np
|
5 |
+
from tensorflow.keras.layers import TextVectorization
|
6 |
+
from tensorflow import keras
|
7 |
|
8 |
+
model = tf.keras.models.load_model('toxicity_model.h5')
|
|
|
9 |
|
10 |
+
df = pd.read_csv('train.csv')
|
11 |
+
X = df['comment_text']
|
12 |
+
y = df[df.columns[2:]].values
|
13 |
|
14 |
+
MAX_FEATURES = 200000
|
15 |
+
vectorizer = TextVectorization(max_tokens=MAX_FEATURES,
|
16 |
+
output_sequence_length=1800,
|
17 |
+
output_mode='int')
|
|
|
|
|
18 |
|
19 |
+
vectorizer.adapt(X.values)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
input_str = vectorizer('I hate you.')
|
22 |
+
res = model.predict(np.expand_dims(input_str,0))
|
23 |
+
classification = res[0].tolist()
|
24 |
+
st.write(classification)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|