Spaces:
Sleeping
Sleeping
File size: 899 Bytes
49374c1 a882137 2f5ca58 a882137 2f5ca58 a882137 2f5ca58 |
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 |
import os
import openai
import gradio as gr
try:
openai.api_key = os.environ["OPENAPI_API_KEY"]
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):
if input:
messages.append({"role": "user", "content": input})
chat = openai.ChatCompletion.create(
model="gpt-3.5-turbo", messages=messages
)
reply = chat.choices[0].message.content
messages.append({"role": "assistant", "content": reply})
return reply
gr.Interface(
fn=chatbot,
inputs=gr.inputs.Textbox(lines=7, label="Query"),
outputs=gr.outputs.Textbox(label="Response"),
theme="compact"
).launch()
|