|
import gradio as gr |
|
from detoxify import Detoxify |
|
import pandas as pd |
|
|
|
|
|
model = Detoxify('original') |
|
|
|
def classify_multiple(comments): |
|
|
|
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) |
|
|
|
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() |