lg3394 commited on
Commit
cb839c5
·
verified ·
1 Parent(s): 7ebc89a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -9
app.py CHANGED
@@ -1,14 +1,21 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
- classifier = pipeline("zero-shot-classification",
5
- model="facebook/bart-large-mnli")
6
 
7
- def do_action(text):
8
- candidate_labels = ['gun control', 'abortion', 'gender transition', 'freedom of speech', 'immigration', 'taxes']
9
- result = classifier(text, candidate_labels)
 
 
 
 
 
 
 
 
 
10
 
11
- return result
12
-
13
- iface = gr.Interface(fn=do_action, inputs="text", outputs="text")
14
  iface.launch()
 
1
  import gradio as gr
2
+ from openai import OpenAI
3
 
4
+ # Initialize OpenAI moderation client
5
+ client = OpenAI()
6
 
7
+ def moderate_text(text):
8
+ response = client.moderations.create(
9
+ model="omni-moderation-latest",
10
+ input=text
11
+ )
12
+ moderation_categories = response["results"][0]["categories"]
13
+ moderation_flagged = response["results"][0]["flagged"]
14
+ if moderation_flagged:
15
+ flagged_categories = [category for category, flagged in moderation_categories.items() if flagged]
16
+ return f"The text is flagged for moderation due to: {', '.join(flagged_categories)}"
17
+ else:
18
+ return "The text is not flagged for any moderation issues."
19
 
20
+ iface = gr.Interface(fn=moderate_text, inputs="text", outputs="text")
 
 
21
  iface.launch()