Commit
·
f1d8d2b
1
Parent(s):
42dfe73
Correct api key cache
Browse files
app.py
CHANGED
|
@@ -78,21 +78,32 @@ def gen_conv(query: str, history=[system_template], ipcc=True):
|
|
| 78 |
return gradio_format, messages, sources
|
| 79 |
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
| 84 |
return f"You're all set: this is your api key: {openai.api_key}"
|
| 85 |
|
| 86 |
-
|
|
|
|
| 87 |
with gr.Blocks(title="Eki IPCC Explorer") as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
with gr.Row():
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
|
|
|
| 96 |
gr.Markdown(
|
| 97 |
"""
|
| 98 |
# Ask me anything, I'm a climate expert
|
|
@@ -119,6 +130,9 @@ with gr.Blocks(title="Eki IPCC Explorer") as demo:
|
|
| 119 |
ask.submit(
|
| 120 |
fn=gen_conv, inputs=[ask, state], outputs=[chatbot, state, sources_textbox]
|
| 121 |
)
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
demo.launch()
|
| 124 |
|
|
|
|
| 78 |
return gradio_format, messages, sources
|
| 79 |
|
| 80 |
|
| 81 |
+
def set_openai_api_key(api_key):
|
| 82 |
+
"""Set the api key and return chain.
|
| 83 |
+
If no api_key, then None is returned.
|
| 84 |
+
"""
|
| 85 |
+
os.environ["OPENAI_API_KEY"] = api_key
|
| 86 |
+
openai.api_key = api_key
|
| 87 |
return f"You're all set: this is your api key: {openai.api_key}"
|
| 88 |
|
| 89 |
+
|
| 90 |
+
# Gradio
|
| 91 |
with gr.Blocks(title="Eki IPCC Explorer") as demo:
|
| 92 |
+
gr.Markdown(
|
| 93 |
+
"""
|
| 94 |
+
# Add your OPENAI api key First
|
| 95 |
+
"""
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
with gr.Row():
|
| 99 |
+
openai_api_key_textbox = gr.Textbox(
|
| 100 |
+
placeholder="Paste your OpenAI API key (sk-...) and hit Enter",
|
| 101 |
+
show_label=False,
|
| 102 |
+
lines=1,
|
| 103 |
+
type="password",
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
|
| 107 |
gr.Markdown(
|
| 108 |
"""
|
| 109 |
# Ask me anything, I'm a climate expert
|
|
|
|
| 130 |
ask.submit(
|
| 131 |
fn=gen_conv, inputs=[ask, state], outputs=[chatbot, state, sources_textbox]
|
| 132 |
)
|
| 133 |
+
|
| 134 |
+
openai_api_key_textbox.change(set_openai_api_key, inputs=[openai_api_key_textbox])
|
| 135 |
+
openai_api_key_textbox.submit(set_openai_api_key, inputs=[openai_api_key_textbox])
|
| 136 |
|
| 137 |
demo.launch()
|
| 138 |
|