Ariel Hsieh commited on
Commit
ef71cfe
1 Parent(s): 52b6d96

update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -15
app.py CHANGED
@@ -1,32 +1,48 @@
1
  import streamlit as st #Web App
2
  from transformers import pipeline
 
 
3
  import numpy as np
4
  import pandas as pd
5
 
6
  #title
7
  st.title("Toxic Tweets")
8
 
9
- model = st.selectbox("Which pretrained model would you like to use?",("roberta-large-mnli","twitter-XLM-roBERTa-base","bertweet-sentiment-analysis"))
10
 
11
  #d = {'col1':[1,2],'col2':[3,4]}
12
  #data = pd.DataFrame(data=d)
13
  #st.table(data)
14
 
15
- data = []
16
- text = st.text_input("Enter text here:","Artificial Intelligence is useful")
17
- data.append(text)
 
 
 
18
 
19
- if model == "roberta-large-mnli":
20
- #1
21
- if st.button("Run Sentiment Analysis of Text"):
22
- model_path = "roberta-large-mnli"
23
- sentiment_pipeline = pipeline(model=model_path)
24
- result = sentiment_pipeline(data)
25
- label = result[0]["label"]
26
- score = result[0]["score"]
27
- d = {'tweet':[model_path],'classification':[label],'score':[score]}
28
- dataframe = pd.DataFrame(data=d)
29
- st.table(dataframe)
 
 
 
 
 
 
 
 
 
 
 
30
  #st.write("The classification of the given text is " + label + " with a score of " + str(score))
31
 
32
 
 
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 Tweets")
10
 
11
+ # model = st.selectbox("Which pretrained model would you like to use?",("roberta-large-mnli","twitter-XLM-roBERTa-base","bertweet-sentiment-analysis"))
12
 
13
  #d = {'col1':[1,2],'col2':[3,4]}
14
  #data = pd.DataFrame(data=d)
15
  #st.table(data)
16
 
17
+ # data = []
18
+ # text = st.text_input("Enter text here:","Artificial Intelligence is useful")
19
+ # data.append(text)
20
+
21
+ tokenizer = AutoTokenizer.from_pretrained("Ariel8/toxic-tweets-classification")
22
+ model = AutoModelForSequenceClassification.from_pretrained("Ariel8/toxic-tweets-classification")
23
 
24
+ X_train = ["Why is Owen's retirement from football not mentioned? He hasn't played a game since 2005."]
25
+ batch = tokenizer(X_train, truncation=True, padding='max_length', return_tensors="pt")
26
+ labels = ["toxic", "severe_toxic", "obscene", "threat", "insult", "identity_hate"]
27
+
28
+ with torch.no_grad():
29
+ outputs = model(**batch)
30
+ predictions = torch.sigmoid(outputs.logits)*100
31
+ probs = predictions[0].tolist()
32
+ for i in range(len(probs)):
33
+ st.write(f"{labels[i]}: {round(probs[i], 3)}%")
34
+
35
+ # if model == "roberta-large-mnli":
36
+ # #1
37
+ # if st.button("Run Sentiment Analysis of Text"):
38
+ # model_path = "roberta-large-mnli"
39
+ # sentiment_pipeline = pipeline(model=model_path)
40
+ # result = sentiment_pipeline(data)
41
+ # label = result[0]["label"]
42
+ # score = result[0]["score"]
43
+ # d = {'tweet':[model_path],'classification':[label],'score':[score]}
44
+ # dataframe = pd.DataFrame(data=d)
45
+ # st.table(dataframe)
46
  #st.write("The classification of the given text is " + label + " with a score of " + str(score))
47
 
48