sistudent-at-300100160591 commited on
Commit
91a98ef
Β·
1 Parent(s): fe164f1

Enhanced with Engish/Tamil message and emojis

Browse files
Files changed (1) hide show
  1. app.py +10 -11
app.py CHANGED
@@ -2,16 +2,16 @@ import torch
2
  import gradio as gr
3
  from transformers import pipeline
4
 
5
- # Load moderation model
6
  moderator = pipeline("text-classification", model="KoalaAI/Text-Moderation")
7
 
8
- # Define function
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,14 +25,13 @@ def moderate_text(input_text):
25
  emoji = "😐"
26
  message = "⚠️ Uncertain classification"
27
 
28
- html_output = f"""
29
- <div style='padding:1em;border-radius:10px;background-color:{color};color:white;font-weight:bold;font-size:16px'>
30
- {emoji} {message} <br>
31
- Confidence Score: {score}% <br>
32
- <span style='font-size:14px; color:white; font-style:italic;'>Supports analysis in English and Tamil 🌐</span>
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