Spaces:
Sleeping
Sleeping
Niki Zhang
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -91,7 +91,7 @@ def validate_api_key(api_key):
|
|
| 91 |
return False
|
| 92 |
|
| 93 |
|
| 94 |
-
def init_openai_api_key(
|
| 95 |
text_refiner = None
|
| 96 |
visual_chatgpt = None
|
| 97 |
if api_key and len(api_key) > 30:
|
|
@@ -112,13 +112,12 @@ def init_openai_api_key(gpt_state,api_key=""):
|
|
| 112 |
print(text_refiner)
|
| 113 |
openai_available = text_refiner is not None
|
| 114 |
if openai_available:
|
| 115 |
-
|
| 116 |
-
return [gr.update(visible=True)]+[gr.update(visible=False)]+[gr.update(visible=True)]*3+[gr.update(visible=False)]+ [gr.update(visible=True)]+ [gr.update(visible=False)]*2 + [text_refiner, visual_chatgpt, None]
|
| 117 |
else:
|
| 118 |
return [gr.update(visible=False)]*7 + [gr.update(visible=True)]*2 + [text_refiner, visual_chatgpt, 'Your OpenAI API Key is not available']
|
| 119 |
|
| 120 |
def init_wo_openai_api_key():
|
| 121 |
-
return [gr.update(visible=False)]*4 + [gr.update(visible=True)]+ [gr.update(visible=False)]+[gr.update(visible=True)]+[gr.update(visible=False)]*2 + [None, None, None]
|
| 122 |
|
| 123 |
def get_click_prompt(chat_input, click_state, click_mode):
|
| 124 |
inputs = json.loads(chat_input)
|
|
@@ -637,13 +636,13 @@ def create_ui():
|
|
| 637 |
)
|
| 638 |
|
| 639 |
|
| 640 |
-
openai_api_key.submit(init_openai_api_key, inputs=[
|
| 641 |
outputs=[modules_need_gpt0, modules_need_gpt1, modules_need_gpt2, modules_need_gpt3, modules_not_need_gpt,
|
| 642 |
-
modules_not_need_gpt2, tts_interface,module_key_input ,module_notification_box, text_refiner, visual_chatgpt, notification_box])
|
| 643 |
-
enable_chatGPT_button.click(init_openai_api_key, inputs=[
|
| 644 |
outputs=[modules_need_gpt0, modules_need_gpt1, modules_need_gpt2, modules_need_gpt3,
|
| 645 |
modules_not_need_gpt,
|
| 646 |
-
modules_not_need_gpt2, tts_interface,module_key_input,module_notification_box, text_refiner, visual_chatgpt, notification_box])
|
| 647 |
disable_chatGPT_button.click(init_wo_openai_api_key,
|
| 648 |
outputs=[modules_need_gpt0, modules_need_gpt1, modules_need_gpt2, modules_need_gpt3,
|
| 649 |
modules_not_need_gpt,
|
|
|
|
| 91 |
return False
|
| 92 |
|
| 93 |
|
| 94 |
+
def init_openai_api_key(api_key=""):
|
| 95 |
text_refiner = None
|
| 96 |
visual_chatgpt = None
|
| 97 |
if api_key and len(api_key) > 30:
|
|
|
|
| 112 |
print(text_refiner)
|
| 113 |
openai_available = text_refiner is not None
|
| 114 |
if openai_available:
|
| 115 |
+
return [gr.update(visible=True)]+[gr.update(visible=False)]+[gr.update(visible=True)]*3+[gr.update(visible=False)]+ [gr.update(visible=True)]+ [gr.update(visible=False)]*2 + [text_refiner, visual_chatgpt, None]+[1]
|
|
|
|
| 116 |
else:
|
| 117 |
return [gr.update(visible=False)]*7 + [gr.update(visible=True)]*2 + [text_refiner, visual_chatgpt, 'Your OpenAI API Key is not available']
|
| 118 |
|
| 119 |
def init_wo_openai_api_key():
|
| 120 |
+
return [gr.update(visible=False)]*4 + [gr.update(visible=True)]+ [gr.update(visible=False)]+[gr.update(visible=True)]+[gr.update(visible=False)]*2 + [None, None, None]+[0]
|
| 121 |
|
| 122 |
def get_click_prompt(chat_input, click_state, click_mode):
|
| 123 |
inputs = json.loads(chat_input)
|
|
|
|
| 636 |
)
|
| 637 |
|
| 638 |
|
| 639 |
+
openai_api_key.submit(init_openai_api_key, inputs=[openai_api_key],
|
| 640 |
outputs=[modules_need_gpt0, modules_need_gpt1, modules_need_gpt2, modules_need_gpt3, modules_not_need_gpt,
|
| 641 |
+
modules_not_need_gpt2, tts_interface,module_key_input ,module_notification_box, text_refiner, visual_chatgpt, notification_box,gpt_state])
|
| 642 |
+
enable_chatGPT_button.click(init_openai_api_key, inputs=[openai_api_key],
|
| 643 |
outputs=[modules_need_gpt0, modules_need_gpt1, modules_need_gpt2, modules_need_gpt3,
|
| 644 |
modules_not_need_gpt,
|
| 645 |
+
modules_not_need_gpt2, tts_interface,module_key_input,module_notification_box, text_refiner, visual_chatgpt, notification_box,gpt_state])
|
| 646 |
disable_chatGPT_button.click(init_wo_openai_api_key,
|
| 647 |
outputs=[modules_need_gpt0, modules_need_gpt1, modules_need_gpt2, modules_need_gpt3,
|
| 648 |
modules_not_need_gpt,
|