sistudent-at-300100160591 commited on
Commit
5f1cd5b
·
1 Parent(s): 222ab1e

Update app.py to enable text moderation feature

Browse files
Files changed (2) hide show
  1. app.py +12 -3
  2. requirements.txt +2 -1
app.py CHANGED
@@ -1,7 +1,16 @@
1
  import gradio as gr
 
2
 
3
- def greet(name):
4
- return f"Hello, {name} ! Welcome to AISA"
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
 
 
 
 
 
 
7
  demo.launch()
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ # Load moderation model
5
+ moderator = pipeline("text-classification", model="KoalaAI/Text-Moderation")
6
 
7
+ # Define function
8
+ def moderate_text(input_text):
9
+ result = moderator(input_text)
10
+ label = result[0]['label']
11
+ score = round(result[0]['score'] * 100, 2)
12
+ return f"Label: {label}, Confidence: {score}%"
13
+
14
+ # Gradio interface
15
+ demo = gr.Interface(fn=moderate_text, inputs="text", outputs="text", title="AISA - Text Moderation")
16
  demo.launch()
requirements.txt CHANGED
@@ -1 +1,2 @@
1
- gradio
 
 
1
+ gradio
2
+ transformers