Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,28 @@
|
|
1 |
import gradio as gr
|
2 |
import openai
|
3 |
|
|
|
|
|
4 |
def echo(message, chat_history):
|
5 |
bot_message = 'echo ' + message
|
6 |
chat_history.append((message, bot_message))
|
7 |
return '', chat_history
|
8 |
|
9 |
def is_api_key_valid(api_key):
|
10 |
-
openai.api_key = api_key
|
11 |
try:
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
)
|
17 |
-
except:
|
|
|
18 |
return False
|
19 |
else:
|
20 |
return True
|
21 |
|
22 |
|
|
|
23 |
with gr.Blocks() as demo:
|
24 |
overview = gr.Markdown("""
|
25 |
# CentaurSock
|
|
|
1 |
import gradio as gr
|
2 |
import openai
|
3 |
|
4 |
+
client = OpenAI()
|
5 |
+
|
6 |
def echo(message, chat_history):
|
7 |
bot_message = 'echo ' + message
|
8 |
chat_history.append((message, bot_message))
|
9 |
return '', chat_history
|
10 |
|
11 |
def is_api_key_valid(api_key):
|
|
|
12 |
try:
|
13 |
+
client.api_key = api_key
|
14 |
+
response = client.chat.completions.create(
|
15 |
+
messages=[{"role": "user", "content": "Testing"}],
|
16 |
+
model="gpt-3.5-turbo",
|
17 |
)
|
18 |
+
except Exception as ex:
|
19 |
+
return str(ex)
|
20 |
return False
|
21 |
else:
|
22 |
return True
|
23 |
|
24 |
|
25 |
+
|
26 |
with gr.Blocks() as demo:
|
27 |
overview = gr.Markdown("""
|
28 |
# CentaurSock
|