Spaces:
Running
Running
Commit
·
6141b10
1
Parent(s):
6776809
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,6 @@ import langchain
|
|
7 |
import faiss
|
8 |
|
9 |
|
10 |
-
openai.api_key = os.environ['openai_key']
|
11 |
|
12 |
|
13 |
prompt_templates = {"All Needs Gurus": "I want you to act as a needs assessment expert."}
|
@@ -35,6 +34,9 @@ def download_prompt_templates():
|
|
35 |
choices = choices[:1] + sorted(choices[1:])
|
36 |
return gr.update(value=choices[0], choices=choices)
|
37 |
|
|
|
|
|
|
|
38 |
|
39 |
def on_prompt_template_change(prompt_template):
|
40 |
if not isinstance(prompt_template, str): return
|
@@ -111,6 +113,7 @@ with gr.Blocks(css=css) as demo:
|
|
111 |
with gr.Column():
|
112 |
#gr.Markdown("Enter your OpenAI API Key. You can get one [here](https://platform.openai.com/account/api-keys).", elem_id="label")
|
113 |
#user_token = gr.Textbox(value='', placeholder="OpenAI API Key", type="password", show_label=False)
|
|
|
114 |
prompt_template = gr.Dropdown(label="Choose a guru:", choices=list(prompt_templates.keys()))
|
115 |
prompt_template_preview = gr.Markdown(elem_id="prompt_template_preview")
|
116 |
with gr.Accordion("Advanced parameters", open=False):
|
@@ -120,12 +123,12 @@ with gr.Blocks(css=css) as demo:
|
|
120 |
|
121 |
gr.HTML('''<br><br><br><center>You can duplicate this Space to skip the queue:<a href="https://huggingface.co/spaces/anzorq/chatgpt-demo?duplicate=true"><img src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a><br>
|
122 |
<p><img src="https://visitor-badge.glitch.me/badge?page_id=anzorq.chatgpt_api_demo_hf" alt="visitors"></p></center>''')
|
123 |
-
|
124 |
btn_submit.click(submit_message, [key, input_message, prompt_template, temperature, max_tokens, context_length, state], [input_message, chatbot, total_tokens_str, state])
|
125 |
input_message.submit(submit_message, [key, input_message, prompt_template, temperature, max_tokens, context_length, state], [input_message, chatbot, total_tokens_str, state])
|
126 |
btn_clear_conversation.click(clear_conversation, [], [input_message, chatbot, total_tokens_str, state])
|
127 |
prompt_template.change(on_prompt_template_change, inputs=[prompt_template], outputs=[prompt_template_preview])
|
128 |
-
|
129 |
|
130 |
|
131 |
demo.load(download_prompt_templates, inputs=None, outputs=[prompt_template], queur=False)
|
|
|
7 |
import faiss
|
8 |
|
9 |
|
|
|
10 |
|
11 |
|
12 |
prompt_templates = {"All Needs Gurus": "I want you to act as a needs assessment expert."}
|
|
|
34 |
choices = choices[:1] + sorted(choices[1:])
|
35 |
return gr.update(value=choices[0], choices=choices)
|
36 |
|
37 |
+
def key_change(key):
|
38 |
+
openai.api_key = key
|
39 |
+
|
40 |
|
41 |
def on_prompt_template_change(prompt_template):
|
42 |
if not isinstance(prompt_template, str): return
|
|
|
113 |
with gr.Column():
|
114 |
#gr.Markdown("Enter your OpenAI API Key. You can get one [here](https://platform.openai.com/account/api-keys).", elem_id="label")
|
115 |
#user_token = gr.Textbox(value='', placeholder="OpenAI API Key", type="password", show_label=False)
|
116 |
+
key = os.environ['openai_key']
|
117 |
prompt_template = gr.Dropdown(label="Choose a guru:", choices=list(prompt_templates.keys()))
|
118 |
prompt_template_preview = gr.Markdown(elem_id="prompt_template_preview")
|
119 |
with gr.Accordion("Advanced parameters", open=False):
|
|
|
123 |
|
124 |
gr.HTML('''<br><br><br><center>You can duplicate this Space to skip the queue:<a href="https://huggingface.co/spaces/anzorq/chatgpt-demo?duplicate=true"><img src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a><br>
|
125 |
<p><img src="https://visitor-badge.glitch.me/badge?page_id=anzorq.chatgpt_api_demo_hf" alt="visitors"></p></center>''')
|
126 |
+
|
127 |
btn_submit.click(submit_message, [key, input_message, prompt_template, temperature, max_tokens, context_length, state], [input_message, chatbot, total_tokens_str, state])
|
128 |
input_message.submit(submit_message, [key, input_message, prompt_template, temperature, max_tokens, context_length, state], [input_message, chatbot, total_tokens_str, state])
|
129 |
btn_clear_conversation.click(clear_conversation, [], [input_message, chatbot, total_tokens_str, state])
|
130 |
prompt_template.change(on_prompt_template_change, inputs=[prompt_template], outputs=[prompt_template_preview])
|
131 |
+
key.change(key_change, inputs=[key], outputs=[])
|
132 |
|
133 |
|
134 |
demo.load(download_prompt_templates, inputs=None, outputs=[prompt_template], queur=False)
|