Spaces:
Sleeping
Sleeping
lachie0232
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -4,14 +4,19 @@ import gradio as gr
|
|
4 |
# Set up OpenAI API key
|
5 |
openai.api_key = "your-openai-secret-key"
|
6 |
|
7 |
-
# Define a function to call the OpenAI API
|
8 |
def chatbot(input_text):
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
# Create the Gradio interface
|
17 |
iface = gr.Interface(
|
@@ -23,3 +28,4 @@ iface = gr.Interface(
|
|
23 |
|
24 |
# Launch the interface
|
25 |
iface.launch()
|
|
|
|
4 |
# Set up OpenAI API key
|
5 |
openai.api_key = "your-openai-secret-key"
|
6 |
|
7 |
+
# Define a function to call the OpenAI API (new method)
|
8 |
def chatbot(input_text):
|
9 |
+
try:
|
10 |
+
response = openai.chat_completions.create(
|
11 |
+
model="gpt-3.5-turbo", # You can change this model if you have access to GPT-4 or other models
|
12 |
+
messages=[
|
13 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
14 |
+
{"role": "user", "content": input_text},
|
15 |
+
]
|
16 |
+
)
|
17 |
+
return response['choices'][0]['message']['content'].strip()
|
18 |
+
except Exception as e:
|
19 |
+
return f"Error: {str(e)}"
|
20 |
|
21 |
# Create the Gradio interface
|
22 |
iface = gr.Interface(
|
|
|
28 |
|
29 |
# Launch the interface
|
30 |
iface.launch()
|
31 |
+
|