File size: 570 Bytes
6227b42
 
 
 
 
 
 
66cd45e
 
 
d4bf4bd
66cd45e
 
6227b42
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import os
import openai
import gradio as gr

openai.api_key = os.environ["OPENAPI_API_KEY"]

def chatbot(input):
    response = openai.Moderation.create(input=input)
    reply = response["results"][0].flagged
    if reply == True:
        return "This content is offensive and needs to be moderated"
    else:
        return "This content doesn't need moderation"

inputs = gr.inputs.Textbox(lines=7, label="Query")
outputs = gr.outputs.Textbox(label="Response")

gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="",
             theme="compact").launch()