KavinduHansaka's picture
Update app.py
e00c4c7 verified
raw
history blame
959 Bytes
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()