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