Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,10 +6,10 @@ import os
|
|
6 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
7 |
|
8 |
# Define a function to interact with OpenAI's ChatGPT
|
9 |
-
def chat_with_openai(input_text):
|
10 |
try:
|
11 |
response = openai.Completion.create(
|
12 |
-
engine=
|
13 |
prompt=input_text,
|
14 |
max_tokens=150,
|
15 |
n=1,
|
@@ -21,20 +21,29 @@ def chat_with_openai(input_text):
|
|
21 |
except Exception as e:
|
22 |
return str(e)
|
23 |
|
24 |
-
# Define the Gradio interface
|
25 |
-
with gr.Blocks() as ui:
|
26 |
-
gr.Markdown("# Chatbot with OpenAI API")
|
27 |
|
28 |
-
chatbot = gr.Chatbot(label="OpenAI Chatbot")
|
29 |
-
msg = gr.Textbox(label="Enter your message here:")
|
30 |
-
submit_btn = gr.Button("Submit")
|
31 |
|
32 |
-
|
|
|
33 |
response = chat_with_openai(message)
|
34 |
chat_history.append((message, response))
|
35 |
return chat_history, ""
|
36 |
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
# Launch the Gradio app
|
40 |
ui.launch()
|
|
|
6 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
7 |
|
8 |
# Define a function to interact with OpenAI's ChatGPT
|
9 |
+
def chat_with_openai(input_text, gpt_model):
|
10 |
try:
|
11 |
response = openai.Completion.create(
|
12 |
+
engine=gpt_model, # Use the model you want (e.g., 'gpt-3.5-turbo', 'gpt-4')
|
13 |
prompt=input_text,
|
14 |
max_tokens=150,
|
15 |
n=1,
|
|
|
21 |
except Exception as e:
|
22 |
return str(e)
|
23 |
|
|
|
|
|
|
|
24 |
|
|
|
|
|
|
|
25 |
|
26 |
+
|
27 |
+
def on_submit(message, chat_history):
|
28 |
response = chat_with_openai(message)
|
29 |
chat_history.append((message, response))
|
30 |
return chat_history, ""
|
31 |
|
32 |
+
|
33 |
+
|
34 |
+
# Define the Gradio interface
|
35 |
+
with gr.Blocks(theme="Hev832/niceandsimple") as ui:
|
36 |
+
gr.Markdown("# ChatGPT Clone")
|
37 |
+
|
38 |
+
chatbot = gr.Chatbot(label="OpenAI Chatbot")
|
39 |
+
with gr.Row():
|
40 |
+
msg = gr.Textbox(label="Enter your message here:")
|
41 |
+
model gr.Dropdown(["gpt-4o-mini", "gpt-3.5-turbo", " gpt-4o"], label="your gpt model")
|
42 |
+
submit_btn = gr.Button("Submit")
|
43 |
+
|
44 |
+
|
45 |
+
|
46 |
+
submit_btn.click(on_submit, inputs=[msg, model, chatbot], outputs=[chatbot, msg])
|
47 |
|
48 |
# Launch the Gradio app
|
49 |
ui.launch()
|