Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -33,32 +33,27 @@ def predict_toxicity(comment):
|
|
33 |
|
34 |
return {labels[i]: float(probabilities[i]) for i in range(len(labels))}
|
35 |
|
36 |
-
def
|
37 |
-
"""
|
38 |
scores = predict_toxicity(comment)
|
39 |
-
|
40 |
-
|
41 |
-
plt.figure(figsize=(6, 4))
|
42 |
-
plt.bar(scores.keys(), scores.values(), color=['blue', 'red', 'green', 'purple', 'orange', 'brown'])
|
43 |
-
plt.ylim(0, 1)
|
44 |
-
plt.ylabel("Toxicity Score")
|
45 |
-
plt.title("Toxicity Analysis")
|
46 |
-
plt.xticks(rotation=45)
|
47 |
-
plt.grid(axis='y', linestyle='--', alpha=0.7)
|
48 |
-
|
49 |
-
# Save plot to display in Gradio
|
50 |
-
plt.savefig("toxicity_plot.png")
|
51 |
-
plt.close()
|
52 |
-
|
53 |
-
return "toxicity_plot.png"
|
54 |
|
55 |
# Gradio interface
|
56 |
demo = gr.Interface(
|
57 |
-
fn=
|
58 |
inputs=gr.Textbox(label="Enter a comment:"),
|
59 |
-
outputs=gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
title="Toxicity Detection with RogueBERT",
|
61 |
-
description="Enter a comment to analyze its toxicity levels. The results will be displayed as a bar chart."
|
62 |
)
|
63 |
|
64 |
demo.launch()
|
|
|
33 |
|
34 |
return {labels[i]: float(probabilities[i]) for i in range(len(labels))}
|
35 |
|
36 |
+
def format_toxicity_data(comment):
|
37 |
+
"""Formats the toxicity scores for a modern bar graph."""
|
38 |
scores = predict_toxicity(comment)
|
39 |
+
data = [[label, score] for label, score in scores.items()]
|
40 |
+
return data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
# Gradio interface
|
43 |
demo = gr.Interface(
|
44 |
+
fn=format_toxicity_data,
|
45 |
inputs=gr.Textbox(label="Enter a comment:"),
|
46 |
+
outputs=gr.BarPlot(
|
47 |
+
x="Category",
|
48 |
+
y="Score",
|
49 |
+
title="Toxicity Analysis",
|
50 |
+
y_lim=[0, 1],
|
51 |
+
color="blue",
|
52 |
+
label="Toxicity Scores",
|
53 |
+
interactive=False
|
54 |
+
),
|
55 |
title="Toxicity Detection with RogueBERT",
|
56 |
+
description="Enter a comment to analyze its toxicity levels. The results will be displayed as a modern bar chart."
|
57 |
)
|
58 |
|
59 |
demo.launch()
|