tonyassi commited on
Commit
35e75d5
β€’
1 Parent(s): a6c7fbc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -0
app.py CHANGED
@@ -6,6 +6,16 @@ def echo(message, chat_history):
6
  chat_history.append((message, bot_message))
7
  return '', chat_history
8
 
 
 
 
 
 
 
 
 
 
 
9
  with gr.Blocks() as demo:
10
  overview = gr.Markdown("""
11
  # CentaurSock
@@ -21,6 +31,8 @@ with gr.Blocks() as demo:
21
  openai_key_textbox = gr.Textbox(label='OpenAI Key')
22
  openai_key_button = gr.Button(value='Test OpenAI Key')
23
 
 
 
24
  # Titles
25
  with gr.Row():
26
  ally_title = gr.Markdown("""<center><h2> ALLY </h2></center>""")
 
6
  chat_history.append((message, bot_message))
7
  return '', chat_history
8
 
9
+ def check_openai_api_key(api_key):
10
+ openai.api_key = api_key
11
+ try:
12
+ openai.Model.list()
13
+ except openai.error.AuthenticationError as e:
14
+ return False
15
+ else:
16
+ return True
17
+
18
+
19
  with gr.Blocks() as demo:
20
  overview = gr.Markdown("""
21
  # CentaurSock
 
31
  openai_key_textbox = gr.Textbox(label='OpenAI Key')
32
  openai_key_button = gr.Button(value='Test OpenAI Key')
33
 
34
+ openai_key_button.click(check_openai_api_key, inputs=[openai_key_textbox], outputs=[openai_key_textbox])
35
+
36
  # Titles
37
  with gr.Row():
38
  ally_title = gr.Markdown("""<center><h2> ALLY </h2></center>""")