Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,49 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from streamlit_chat import message
|
3 |
import requests
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
)
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
st.
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
"past_user_inputs": st.session_state.past,
|
37 |
-
"generated_responses": st.session_state.generated,
|
38 |
-
"text": user_input,
|
39 |
-
},"parameters": {"repetition_penalty": 1.33},
|
40 |
-
})
|
41 |
-
|
42 |
-
st.session_state.past.append(user_input)
|
43 |
-
st.session_state.generated.append(output["generated_text"])
|
44 |
-
|
45 |
-
if st.session_state['generated']:
|
46 |
-
|
47 |
-
for i in range(len(st.session_state['generated'])-1, -1, -1):
|
48 |
-
message(st.session_state["generated"][i], key=str(i))
|
49 |
-
message(st.session_state['past'][i], is_user=True, key=str(i) + '_user')
|
|
|
1 |
+
from pathlib import Path
|
2 |
+
from sklearn.model_selection import train_test_split
|
3 |
+
import torch
|
4 |
+
from torch.utils.data import Dataset
|
5 |
+
from transformers import DistilBertTokenizerFast, DistilBertForSequenceClassification
|
6 |
+
from transformers import Trainer, TrainingArguments
|
7 |
+
|
8 |
import streamlit as st
|
9 |
from streamlit_chat import message
|
10 |
import requests
|
11 |
|
12 |
+
model_one = "distilbert-base-uncased-finetuned-sst-2-english"
|
13 |
+
model_two = "Newtral/xlm-r-finetuned-toxic-political-tweets-es"
|
14 |
+
|
15 |
+
def toxicRating(text, model):
|
16 |
+
model = AutoModelForSequenceClassification.from_pretrained(model)
|
17 |
+
tokenizer = AutoTokenizer.from_pretrained(model)
|
18 |
+
|
19 |
+
classifier = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
|
20 |
+
results = classifier(text)
|
21 |
+
return results
|
22 |
+
|
23 |
+
def main():
|
24 |
+
st.title("TOXIC TWEETS, \n TOXIC OR NOT?")
|
25 |
+
prompt = st.header("Select Model")
|
26 |
+
selection = st.radio("Models",('Model 1', 'Model 2'))
|
27 |
+
|
28 |
+
|
29 |
+
input = st.text_area("Enter Tweet: ")
|
30 |
+
if input:
|
31 |
+
if selection == 'Model 1':
|
32 |
+
rating = rate_ModelOne(input, model_one)
|
33 |
+
st.write(f"Label: {rating[1]} \n Score : {rating[3]}")
|
34 |
+
elif selection == 'Model 2':
|
35 |
+
rating = rate_ModelTwo(input, model_two)
|
36 |
+
rating = rate_ModelOne(input, model_one)
|
37 |
+
st.write(f"Label: {rating[1]} \n Score : {rating[3]}")
|
38 |
+
else:
|
39 |
+
st.warning("Enter Tweet")
|
40 |
+
|
41 |
+
if __name__ == "__main__":
|
42 |
+
main();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|