File size: 776 Bytes
1a5f890
 
300f06d
2268b75
 
6c042c6
 
 
 
 
 
 
2268b75
 
6767b70
 
2268b75
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import streamlit as st

from transformers import AutoTokenizer, AutoModelForSequenceClassification


txt = st.text_area('Text to analyze', '''
    It was the best of times, it was the worst of times, it was
    the age of wisdom, it was the age of foolishness, it was
    the epoch of belief, it was the epoch of incredulity, it
    was the season of Light, it was the season of Darkness, it
    was the spring of hope, it was the winter of despair, (...)
    ''')

# load tokenizer and model weights
tokenizer = AutoTokenizer.from_pretrained("s-nlp/roberta_toxicity_classifier")
model = AutoModelForSequenceClassification.from_pretrained("s-nlp/roberta_toxicity_classifier")

# prepare the input
batch = tokenizer.encode('txt', return_tensors='pt')

# inference
model(batch)