Spaces:
Runtime error
Runtime error
Rob Caamano commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoTokenizer
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
from transformers import (
|
| 5 |
+
TFAutoModelForSequenceClassification as AutoModelForSequenceClassification,
|
| 6 |
+
)
|
| 7 |
|
| 8 |
+
st.title("Detecting Toxic Tweets")
|
| 9 |
+
|
| 10 |
+
demo = """I'm so proud of myself for accomplishing my goals today. #motivation #success"""
|
| 11 |
+
|
| 12 |
+
text = st.text_area("Input text", demo, height=250)
|
| 13 |
+
|
| 14 |
+
model_name = "distilbert-base-uncased-finetuned-sst-2-english"
|
| 15 |
+
|
| 16 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 17 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 18 |
+
clf = pipeline(
|
| 19 |
+
"toxicity-analysis", model=model, tokenizer=tokenizer, return_all_scores=True
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
input = tokenizer(text, return_tensors="tf")
|
| 23 |
+
|
| 24 |
+
if st.button("Submit", type="primary"):
|
| 25 |
+
results = clf(text)[0]
|
| 26 |
+
classes = dict(d.values() for d in results)
|
| 27 |
+
st.bar_chart(classes)
|