JulianHame commited on
Commit
050c119
1 Parent(s): 8bc44c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -38
app.py CHANGED
@@ -1,45 +1,24 @@
1
  import streamlit as st
2
  from transformers import pipeline
 
 
 
 
3
 
4
- st.title('Sentiment Analyser')
5
- st.image("https://www.pngall.com/wp-content/uploads/5/Emotion-Transparent.png")
6
 
7
- st.write("---")
8
- st.header('Step 1 - Select a language model')
9
- col1, col2 = st.columns(2)
10
 
11
- selection = "N/A"
12
- with col1:
13
- selection = st.radio("Pick one of the four pre-trained models below:",
14
- key = "modelChoice",
15
- options = ["DistilBERT", "Toxicity-Classifier", "SiEBERT", "Twitter-roBERTa"],
16
- )
17
 
18
- pipe = pipeline('sentiment-analysis')
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
- with col2:
29
- st.caption('DistilBERT - One of the most popular and widely-used language models. Labels text as POSITIVE or NEGATIVE. Developed by Hugging Face.')
30
- st.caption('Toxicity-Classifier - A model trained to classify tweets under different toxicity-related categories.')
31
- st.caption('SiEBERT - A model trained on diverse text sources to improve generalization. Labels text as POSITIVE or NEGATIVE. Developed by siebert.')
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)