Spaces:
Runtime error
Runtime error
| # download files | |
| import openai | |
| import gradio as gr | |
| # import shutup | |
| # shutup.please() | |
| def chatbot(api_key, input): | |
| openai.api_key = api_key | |
| messages = [{"role": "system", "content": "You are a helpful and kind AI Assistant."}] | |
| 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 | |
| api_key_input = gr.inputs.Textbox(lines=1, label="Enter your API key") | |
| chat_input = gr.inputs.Textbox(lines=7, label="Chat with AI") | |
| output_text = gr.outputs.Textbox(label="Reply") | |
| def get_reply(api_key, input): | |
| return chatbot(api_key, input) | |
| gr.Interface( | |
| fn=get_reply, | |
| inputs=[api_key_input, chat_input], | |
| outputs=output_text, | |
| title="AI Chatbot", | |
| description="Ask anything you want", | |
| theme="default" | |
| ).launch() |