Spaces:
Sleeping
Sleeping
sistudent-at-300100160591
commited on
Commit
Β·
91a98ef
1
Parent(s):
fe164f1
Enhanced with Engish/Tamil message and emojis
Browse files
app.py
CHANGED
@@ -2,16 +2,16 @@ import torch
|
|
2 |
import gradio as gr
|
3 |
from transformers import pipeline
|
4 |
|
5 |
-
# Load
|
6 |
moderator = pipeline("text-classification", model="KoalaAI/Text-Moderation")
|
7 |
|
8 |
-
#
|
9 |
def moderate_text(input_text):
|
10 |
result = moderator(input_text)
|
11 |
label = result[0]['label']
|
12 |
score = round(result[0]['score'] * 100, 2)
|
13 |
|
14 |
-
|
15 |
if label == "toxic":
|
16 |
color = "#FF4C4C" # Bright red
|
17 |
emoji = "π‘"
|
@@ -25,14 +25,13 @@ def moderate_text(input_text):
|
|
25 |
emoji = "π"
|
26 |
message = "β οΈ Uncertain classification"
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
</div>
|
34 |
-
"""
|
35 |
-
|
36 |
return html_output
|
37 |
|
38 |
# Gradio interface
|
|
|
2 |
import gradio as gr
|
3 |
from transformers import pipeline
|
4 |
|
5 |
+
# Load the model
|
6 |
moderator = pipeline("text-classification", model="KoalaAI/Text-Moderation")
|
7 |
|
8 |
+
# Visual styling logic
|
9 |
def moderate_text(input_text):
|
10 |
result = moderator(input_text)
|
11 |
label = result[0]['label']
|
12 |
score = round(result[0]['score'] * 100, 2)
|
13 |
|
14 |
+
# Set color and emoji
|
15 |
if label == "toxic":
|
16 |
color = "#FF4C4C" # Bright red
|
17 |
emoji = "π‘"
|
|
|
25 |
emoji = "π"
|
26 |
message = "β οΈ Uncertain classification"
|
27 |
|
28 |
+
# HTML-formatted response
|
29 |
+
html_output = f"""
|
30 |
+
<div style='padding:1em;border-radius:10px;background-color:{color};color:white;font-weight:bold;font-size:16px'>
|
31 |
+
{emoji} {message} <br>
|
32 |
+
Confidence Score: {score}%
|
33 |
+
</div>
|
34 |
+
"""
|
|
|
35 |
return html_output
|
36 |
|
37 |
# Gradio interface
|