Spaces:
Running
Running
Gopala Krishna
commited on
Commit
·
2f5ca58
1
Parent(s):
49374c1
added try except
Browse files
.vs/MyChatGPTTurbo/FileContentIndex/a0f053e5-9f7e-4b03-86d7-95fe4d8c7e5c.vsidx
ADDED
Binary file (5.75 kB). View file
|
|
.vs/MyChatGPTTurbo/FileContentIndex/{d9c2ef8b-7948-46ad-9281-0d97adf3f188.vsidx → df1cdd5e-5142-44ff-be56-7baaf787ba9a.vsidx}
RENAMED
File without changes
|
.vs/MyChatGPTTurbo/v17/.wsuo
CHANGED
Binary files a/.vs/MyChatGPTTurbo/v17/.wsuo and b/.vs/MyChatGPTTurbo/v17/.wsuo differ
|
|
.vs/slnx.sqlite
CHANGED
Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite differ
|
|
app.py
CHANGED
@@ -2,25 +2,31 @@ import os
|
|
2 |
import openai
|
3 |
import gradio as gr
|
4 |
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
)
|
17 |
-
reply = chat.choices[0].message.content
|
18 |
-
messages.append({"role": "assistant", "content": reply})
|
19 |
-
return reply
|
20 |
-
|
21 |
-
inputs = gr.inputs.Textbox(lines=7, label="Query")
|
22 |
-
outputs = gr.outputs.Textbox(label="Response")
|
23 |
-
|
24 |
-
gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="",
|
25 |
-
theme="compact").launch()
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
if input:
|
19 |
+
messages.append({"role": "user", "content": input})
|
20 |
+
chat = openai.ChatCompletion.create(
|
21 |
+
model="gpt-3.5-turbo", messages=messages
|
22 |
+
)
|
23 |
+
reply = chat.choices[0].message.content
|
24 |
+
messages.append({"role": "assistant", "content": reply})
|
25 |
+
return reply
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
+
gr.Interface(
|
28 |
+
fn=chatbot,
|
29 |
+
inputs=gr.inputs.Textbox(lines=7, label="Query"),
|
30 |
+
outputs=gr.outputs.Textbox(label="Response"),
|
31 |
+
theme="compact"
|
32 |
+
).launch()
|