File size: 1,057 Bytes
6227b42
 
 
 
78bfd66
01be1e5
 
 
78bfd66
 
 
 
 
 
 
 
 
6227b42
 
78bfd66
 
 
 
 
 
 
 
 
6227b42
 
 
 
 
 
01be1e5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import openai
import gradio as gr

try:
    #.api_key = os.environ["OPENAPI_API_KEY"]
    openai.api_key = "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"

except KeyError:
    error_message = "System is at capacity right now.Please try again later"
    print(error_message)
    def chatbot(input):
        return error_message
else:
    messages = [
        {"role": "system", "content": "My AI Assistant"},
    ]

def chatbot(input):
    try:
        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"
    except openai.error.OpenAIError as e:
        return "System is at capacity right now.Please try again later"

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()