Gopala Krishna
initial commit
01be1e5
raw
history blame
1.06 kB
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()