Spaces:
Runtime error
Runtime error
Commit ·
e4a01a2
1
Parent(s): 8753751
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,30 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
|
| 3 |
-
from transformers import DistilBertTokenizer, DistilBertForSequenceClassification
|
| 4 |
-
from transformers import pipeline
|
| 5 |
-
from transformers import pretrained_model
|
| 6 |
from transformers import AutoModelForSequenceClassification
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
#st.title("Enter Phrase: ")
|
| 9 |
uInput = st.text_input("Enter Phrase: ")
|
|
|
|
| 10 |
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
-
pipe = pipeline(model=mymodel)
|
| 14 |
-
data = [uInput]
|
| 15 |
-
#pipeline(data)
|
| 16 |
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
col2.subheader(f"{ p['label'] }: { round(p['score'] * 100, 1)}%")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import torch
|
|
|
|
|
|
|
|
|
|
| 3 |
from transformers import AutoModelForSequenceClassification
|
| 4 |
+
from transformers import AutoTokenizer, AutoModel
|
| 5 |
+
from transformers import pipeline
|
| 6 |
+
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained("Michael54546/ToxicTweet")
|
| 8 |
+
model = AutoModelForSequenceClassification.from_pretrained("Michael54546/ToxicTweet")
|
| 9 |
|
| 10 |
#st.title("Enter Phrase: ")
|
| 11 |
uInput = st.text_input("Enter Phrase: ")
|
| 12 |
+
data = [uInput]
|
| 13 |
|
| 14 |
+
classifier = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer, return_all_scores=True)
|
| 15 |
+
results = classifier(data)
|
| 16 |
|
| 17 |
+
col1, col2, col3 = st.columns(3)
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
for x in results:
|
| 20 |
+
for p in x:
|
| 21 |
+
#print(f"{ p['label'] }: { round(p['score'] * 100, 1)}%")
|
| 22 |
+
if(p['score']>highestscore and p['label']!='toxic'):
|
| 23 |
+
highestscore=p['score']
|
| 24 |
+
highest=p['label']
|
| 25 |
|
| 26 |
+
col2.header("Highest Label")
|
| 27 |
+
print(highest)
|
| 28 |
|
| 29 |
+
col3.header("Probability")
|
| 30 |
+
print(f"{ round([highestscore * 100, 1)}%")
|
|
|