File size: 959 Bytes
2e4f9f7
 
 
 
e00c4c7
2e4f9f7
 
e00c4c7
 
 
 
 
2e4f9f7
e00c4c7
 
 
2e4f9f7
 
 
e00c4c7
 
 
 
 
2e4f9f7
 
 
 
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
import gradio as gr
from detoxify import Detoxify
import pandas as pd

# Load model once
model = Detoxify('original')

def classify_multiple(comments):
    # Split input by newlines and clean
    comment_list = [c.strip() for c in comments.split('\n') if c.strip()]
    if not comment_list:
        return "Please enter at least one valid comment."

    results = model.predict(comment_list)  # Returns a dict of lists

    df = pd.DataFrame(results, index=comment_list).round(4)
    return df

iface = gr.Interface(
    fn=classify_multiple,
    inputs=gr.Textbox(lines=8, placeholder="Enter one or more comments, each on a new line..."),
    outputs=gr.Dataframe(label="Toxicity Predictions"),
    title="💬 Toxic Comment Classifier (Multi-Comment)",
    description="Paste one or more comments. Each will be scored for toxicity, severe toxicity, insult, threat, obscene, and identity hate using Detoxify."
)

if __name__ == "__main__":
    iface.launch()