ryanrwatkins commited on
Commit
6c42480
Β·
1 Parent(s): ab8109f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -6,6 +6,8 @@ import os
6
  import langchain
7
  import faiss
8
 
 
 
9
  prompt_templates = {"All Needs Gurus": "I want you to act as a needs assessment expert."}
10
 
11
  def get_empty_state():
@@ -31,16 +33,17 @@ def download_prompt_templates():
31
  choices = choices[:1] + sorted(choices[1:])
32
  return gr.update(value=choices[0], choices=choices)
33
 
34
- #def key_change(key):
35
- # openai.api_key = key
36
 
37
 
38
  def on_prompt_template_change(prompt_template):
39
  if not isinstance(prompt_template, str): return
40
  return prompt_templates[prompt_template]
41
 
42
- def submit_message(key, prompt, prompt_template, temperature, max_tokens, context_length, state):
43
 
 
44
  history = state['messages']
45
 
46
  if not prompt:
@@ -108,7 +111,7 @@ with gr.Blocks(css=css) as demo:
108
  total_tokens_str = gr.Markdown(elem_id="total_tokens_str")
109
  btn_clear_conversation = gr.Button("πŸ”ƒ Start New Conversation")
110
  with gr.Column():
111
- key = os.environ['openai_key']
112
  #gr.Markdown(key, 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()))
@@ -121,7 +124,7 @@ with gr.Blocks(css=css) as demo:
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, [ 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])
 
6
  import langchain
7
  import faiss
8
 
9
+
10
+
11
  prompt_templates = {"All Needs Gurus": "I want you to act as a needs assessment expert."}
12
 
13
  def get_empty_state():
 
33
  choices = choices[:1] + sorted(choices[1:])
34
  return gr.update(value=choices[0], choices=choices)
35
 
36
+
37
+
38
 
39
 
40
  def on_prompt_template_change(prompt_template):
41
  if not isinstance(prompt_template, str): return
42
  return prompt_templates[prompt_template]
43
 
44
+ def submit_message(prompt, prompt_template, temperature, max_tokens, context_length, state):
45
 
46
+ openai.api_key = os.environ['openai_key']
47
  history = state['messages']
48
 
49
  if not prompt:
 
111
  total_tokens_str = gr.Markdown(elem_id="total_tokens_str")
112
  btn_clear_conversation = gr.Button("πŸ”ƒ Start New Conversation")
113
  with gr.Column():
114
+
115
  #gr.Markdown(key, elem_id="label")
116
  #user_token = gr.Textbox(value='', placeholder="OpenAI API Key", type="password", show_label=False)
117
  prompt_template = gr.Dropdown(label="Choose a guru:", choices=list(prompt_templates.keys()))
 
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, [ input_message, prompt_template, temperature, max_tokens, context_length, state], [input_message, chatbot, total_tokens_str, state])
128
  input_message.submit(submit_message, [ 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])