Spaces:
Runtime error
Runtime error
Commit
·
e4848d6
1
Parent(s):
250dce3
Update app.py
Browse files
app.py
CHANGED
@@ -11,8 +11,11 @@ from langchain.llms import OpenAI
|
|
11 |
|
12 |
def set_api_key(key):
|
13 |
os.environ["OPENAI_API_KEY"] = key
|
14 |
-
|
|
|
|
|
15 |
os.environ["OPENAI_API_KEY"] = ""
|
|
|
16 |
|
17 |
def get_api_key():
|
18 |
api_key = os.getenv("OPENAI_API_KEY")
|
@@ -45,10 +48,11 @@ with gr.Blocks() as demo:
|
|
45 |
with gr.Tab("OpenAI API Key Submission"):
|
46 |
api_input = gr.Textbox(label = "API Key - Your key will be active for 10 minutes. The bar below shows the time left.",
|
47 |
placeholder = "Please provide your OpenAI API key here.")
|
48 |
-
|
49 |
-
placeholder = "Your API Key has been reset or has not be set yet. Please
|
50 |
interactive = False)
|
51 |
api_submit_button = gr.Button("Submit")
|
|
|
52 |
|
53 |
with gr.Tab("Coding Assistant"):
|
54 |
api_check_button = gr.Button("Get API Key")
|
@@ -57,7 +61,8 @@ with gr.Blocks() as demo:
|
|
57 |
msg = gr.Textbox(label="User Prompt", placeholder="Your Query Here")
|
58 |
clear = gr.Button("Clear")
|
59 |
|
60 |
-
api_submit_button.click(set_api_key, inputs=api_input, outputs=
|
|
|
61 |
api_check_button.click(get_api_key, outputs=api_print)
|
62 |
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
63 |
clear.click(lambda: None, None, chatbot, queue=False)
|
|
|
11 |
|
12 |
def set_api_key(key):
|
13 |
os.environ["OPENAI_API_KEY"] = key
|
14 |
+
return f"Your API Key has been set to {key}"
|
15 |
+
|
16 |
+
def reset_api_key():
|
17 |
os.environ["OPENAI_API_KEY"] = ""
|
18 |
+
return api_key_status: gr.update(placeholder="Your API Key has been reset")
|
19 |
|
20 |
def get_api_key():
|
21 |
api_key = os.getenv("OPENAI_API_KEY")
|
|
|
48 |
with gr.Tab("OpenAI API Key Submission"):
|
49 |
api_input = gr.Textbox(label = "API Key - Your key will be active for 10 minutes. The bar below shows the time left.",
|
50 |
placeholder = "Please provide your OpenAI API key here.")
|
51 |
+
api_key_status = gr.Textbox(label = "API Key Status",
|
52 |
+
placeholder = "Your API Key has been reset or has not be set yet. Please enter your key.",
|
53 |
interactive = False)
|
54 |
api_submit_button = gr.Button("Submit")
|
55 |
+
api_reset_button = gr.Button("Clear API Key from session")
|
56 |
|
57 |
with gr.Tab("Coding Assistant"):
|
58 |
api_check_button = gr.Button("Get API Key")
|
|
|
61 |
msg = gr.Textbox(label="User Prompt", placeholder="Your Query Here")
|
62 |
clear = gr.Button("Clear")
|
63 |
|
64 |
+
api_submit_button.click(set_api_key, inputs=api_input, outputs=api_key_status)
|
65 |
+
api_reset_button.click(reset_api_key, outputs=api_key_status)
|
66 |
api_check_button.click(get_api_key, outputs=api_print)
|
67 |
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
68 |
clear.click(lambda: None, None, chatbot, queue=False)
|