File size: 983 Bytes
1e225c4
a16f964
4e66a4e
a16f964
 
 
 
 
1e225c4
 
a16f964
4e66a4e
 
 
1e225c4
4e66a4e
 
 
 
 
 
 
 
 
 
 
 
a70dc7d
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
29
import gradio as gr
from transformers import pipeline, AutoTokenizer

# Load the tokenizer and model
tokenizer = AutoTokenizer.from_pretrained('prabhaskenche/toxic-comment-classification-using-RoBERTa')
classifier = pipeline(
    'text-classification', 
    model='prabhaskenche/toxic-comment-classification-using-RoBERTa', 
    tokenizer=tokenizer,
    top_k=None  # Use top_k=None to get all scores
)

def classify(text):
    results = classifier(text)
    # Assuming LABEL_0 is non-toxic and LABEL_1 is toxic
    non_toxic_score = next((item['score'] for item in results[0] if item['label'] == 'LABEL_0'), 0)
    toxic_score = next((item['score'] for item in results[0] if item['label'] == 'LABEL_1'), 0)
    return f"{non_toxic_score:.3f} non-toxic, {toxic_score:.3f} toxic"

# Create the Gradio interface
interface = gr.Interface(
    fn=classify,
    inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
    outputs="text"
)

# Launch the interface
interface.launch()