Spaces:
Runtime error
Runtime error
Commit
·
0aeece4
1
Parent(s):
15e2bf5
Update app.py
Browse files
app.py
CHANGED
@@ -2,14 +2,14 @@ import openai
|
|
2 |
import gradio as gr
|
3 |
|
4 |
# Define the chat function
|
5 |
-
def chat(api_key, message):
|
6 |
# Check if an API key has been provided
|
7 |
if api_key is None:
|
8 |
return "Please enter your OpenAI API key and try again."
|
9 |
|
10 |
# Set up the OpenAI API request
|
11 |
response = openai.Completion.create(
|
12 |
-
engine=
|
13 |
prompt=message,
|
14 |
max_tokens=1024,
|
15 |
n=1,
|
@@ -25,12 +25,17 @@ def chat(api_key, message):
|
|
25 |
|
26 |
# Define the Gradio interface
|
27 |
api_key_input = gr.inputs.Textbox(label="OpenAI API Key", default=None)
|
|
|
|
|
|
|
|
|
|
|
28 |
message_input = gr.inputs.Textbox(label="Enter your message here")
|
29 |
output = gr.outputs.Textbox(label="Bot response")
|
30 |
|
31 |
chat_button = gr.Interface(
|
32 |
fn=chat,
|
33 |
-
inputs=[api_key_input, message_input],
|
34 |
outputs=output,
|
35 |
title="OpenAI Chatbot",
|
36 |
description="Enter your message below to chat with an AI",
|
|
|
2 |
import gradio as gr
|
3 |
|
4 |
# Define the chat function
|
5 |
+
def chat(api_key, model, message):
|
6 |
# Check if an API key has been provided
|
7 |
if api_key is None:
|
8 |
return "Please enter your OpenAI API key and try again."
|
9 |
|
10 |
# Set up the OpenAI API request
|
11 |
response = openai.Completion.create(
|
12 |
+
engine=model,
|
13 |
prompt=message,
|
14 |
max_tokens=1024,
|
15 |
n=1,
|
|
|
25 |
|
26 |
# Define the Gradio interface
|
27 |
api_key_input = gr.inputs.Textbox(label="OpenAI API Key", default=None)
|
28 |
+
model_input = gr.inputs.Dropdown(
|
29 |
+
label="Select model",
|
30 |
+
choices=["text-davinci-003", "text-davinci-002"],
|
31 |
+
default="text-davinci-003",
|
32 |
+
)
|
33 |
message_input = gr.inputs.Textbox(label="Enter your message here")
|
34 |
output = gr.outputs.Textbox(label="Bot response")
|
35 |
|
36 |
chat_button = gr.Interface(
|
37 |
fn=chat,
|
38 |
+
inputs=[api_key_input, model_input, message_input],
|
39 |
outputs=output,
|
40 |
title="OpenAI Chatbot",
|
41 |
description="Enter your message below to chat with an AI",
|