Spaces:
Runtime error
Runtime error
Gopala Krishna
commited on
Commit
·
78bfd66
1
Parent(s):
d4bf4bd
Added try except
Browse files
.vs/ContentModeration/FileContentIndex/4f81caf7-f67a-4f87-b7bb-cfec7041b74d.vsidx
DELETED
Binary file (272 Bytes)
|
|
.vs/ContentModeration/v17/.wsuo
CHANGED
Binary files a/.vs/ContentModeration/v17/.wsuo and b/.vs/ContentModeration/v17/.wsuo differ
|
|
.vs/slnx.sqlite
CHANGED
Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite differ
|
|
app.py
CHANGED
@@ -2,15 +2,28 @@ import os
|
|
2 |
import openai
|
3 |
import gradio as gr
|
4 |
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
def chatbot(input):
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
14 |
|
15 |
inputs = gr.inputs.Textbox(lines=7, label="Query")
|
16 |
outputs = gr.outputs.Textbox(label="Response")
|
|
|
2 |
import openai
|
3 |
import gradio as gr
|
4 |
|
5 |
+
try:
|
6 |
+
openai.api_key = os.environ["OPENAPI_API_KEY"]
|
7 |
+
except KeyError:
|
8 |
+
error_message = "System is at capacity right now.Please try again later"
|
9 |
+
print(error_message)
|
10 |
+
def chatbot(input):
|
11 |
+
return error_message
|
12 |
+
else:
|
13 |
+
messages = [
|
14 |
+
{"role": "system", "content": "My AI Assistant"},
|
15 |
+
]
|
16 |
|
17 |
def chatbot(input):
|
18 |
+
try:
|
19 |
+
response = openai.Moderation.create(input=input)
|
20 |
+
reply = response["results"][0].flagged
|
21 |
+
if reply == True:
|
22 |
+
return "This content is offensive and needs to be moderated"
|
23 |
+
else:
|
24 |
+
return "This content doesn't need moderation"
|
25 |
+
except openai.error.OpenAIError as e:
|
26 |
+
return "System is at capacity right now.Please try again later"
|
27 |
|
28 |
inputs = gr.inputs.Textbox(lines=7, label="Query")
|
29 |
outputs = gr.outputs.Textbox(label="Response")
|