Update app.py
Browse files
app.py
CHANGED
|
@@ -2,24 +2,26 @@ import gradio as gr
|
|
| 2 |
from detoxify import Detoxify
|
| 3 |
import pandas as pd
|
| 4 |
|
| 5 |
-
# Load model once
|
| 6 |
model = Detoxify('original')
|
| 7 |
|
| 8 |
-
def
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
results = model.predict(
|
| 13 |
-
|
| 14 |
-
df =
|
| 15 |
return df
|
| 16 |
|
| 17 |
iface = gr.Interface(
|
| 18 |
-
fn=
|
| 19 |
-
inputs=gr.Textbox(
|
| 20 |
-
outputs=gr.Dataframe(label="Toxicity
|
| 21 |
-
title="💬 Toxic Comment Classifier",
|
| 22 |
-
description="
|
| 23 |
)
|
| 24 |
|
| 25 |
if __name__ == "__main__":
|
|
|
|
| 2 |
from detoxify import Detoxify
|
| 3 |
import pandas as pd
|
| 4 |
|
| 5 |
+
# Load model once
|
| 6 |
model = Detoxify('original')
|
| 7 |
|
| 8 |
+
def classify_multiple(comments):
|
| 9 |
+
# Split input by newlines and clean
|
| 10 |
+
comment_list = [c.strip() for c in comments.split('\n') if c.strip()]
|
| 11 |
+
if not comment_list:
|
| 12 |
+
return "Please enter at least one valid comment."
|
| 13 |
|
| 14 |
+
results = model.predict(comment_list) # Returns a dict of lists
|
| 15 |
+
|
| 16 |
+
df = pd.DataFrame(results, index=comment_list).round(4)
|
| 17 |
return df
|
| 18 |
|
| 19 |
iface = gr.Interface(
|
| 20 |
+
fn=classify_multiple,
|
| 21 |
+
inputs=gr.Textbox(lines=8, placeholder="Enter one or more comments, each on a new line..."),
|
| 22 |
+
outputs=gr.Dataframe(label="Toxicity Predictions"),
|
| 23 |
+
title="💬 Toxic Comment Classifier (Multi-Comment)",
|
| 24 |
+
description="Paste one or more comments. Each will be scored for toxicity, severe toxicity, insult, threat, obscene, and identity hate using Detoxify."
|
| 25 |
)
|
| 26 |
|
| 27 |
if __name__ == "__main__":
|