Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from openai import OpenAI
|
| 3 |
+
|
| 4 |
+
def Moderation(prompt, api_key):
|
| 5 |
+
if api_key == '':
|
| 6 |
+
output= gr.Textbox("*** Please provide API Key ***")
|
| 7 |
+
else:
|
| 8 |
+
try:
|
| 9 |
+
client = OpenAI(api_key= api_key)
|
| 10 |
+
response = client.moderations.create(input=prompt)
|
| 11 |
+
output = response.results[0]
|
| 12 |
+
except :
|
| 13 |
+
output = gr.Textbox("*** Please check your API-Key and try again ***")
|
| 14 |
+
return output
|
| 15 |
+
|
| 16 |
+
title = "Enter your Prompt"
|
| 17 |
+
description = """
|
| 18 |
+
<img src = "https://upload.wikimedia.org/wikipedia/commons/4/4d/OpenAI_Logo.svg" width=300px>
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
# Provide OpenAI API Key
|
| 23 |
+
|
| 24 |
+
# Moderation tool : A fine-tuned model that can detect whether text may be sensitive or unsafe.
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
gr.Interface(
|
| 30 |
+
Moderation,
|
| 31 |
+
[
|
| 32 |
+
gr.Textbox(label="Enter your Prompt"),
|
| 33 |
+
gr.Textbox(type = 'password',label="Enter your API-Key", placeholder="API-Key", lines=1),
|
| 34 |
+
]
|
| 35 |
+
,outputs="text",
|
| 36 |
+
title=title,
|
| 37 |
+
description=description,
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
).launch()
|