binh99 commited on
Commit
29b883a
·
1 Parent(s): b30c13a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -36,7 +36,11 @@ prompt_template = "Instructions: Compose a comprehensive reply to the query usin
36
  # MODELS = ["universal-sentence-encoder", "instructor-large"]
37
  MODELS = ["text-davinci-001", "text-davinci-002", "text-davinci-003"]
38
 
 
 
 
39
 
 
40
  def add_source_numbers(lst):
41
  return [item[:3] + '\t' + item[3:] for item in (lst)]
42
 
@@ -119,7 +123,6 @@ def get_top_chunks(inp_emb, data, n_neighbors=5):
119
 
120
 
121
  def predict(
122
- my_api_key,
123
  history,
124
  chatbot,
125
  inputs,
@@ -155,7 +158,6 @@ def predict(
155
  chatbot.append((old_inputs, ""))
156
  else:
157
  chatbot.append((inputs, ""))
158
- open_ai.api_key = my_api_key
159
  completions = openai.Completion.create(
160
  engine=selected_model,
161
  prompt=inputs,
@@ -215,7 +217,7 @@ with gr.Blocks(css=customCSS, theme=beautiful_theme) as demo:
215
  with gr.Column(scale=5):
216
  with gr.Row():
217
  chatbot = gr.Chatbot(elem_id="chatbot").style(height="100%")
218
- with gr.Row():
219
  with gr.Column(scale=12):
220
  user_input = gr.Textbox(
221
  show_label=False, placeholder="Enter here"
@@ -244,7 +246,7 @@ with gr.Blocks(css=customCSS, theme=beautiful_theme) as demo:
244
  step=0.1,
245
  interactive=True,
246
  label="Temperature",
247
- )
248
  user_input.submit(predict, inputs=[history, chatbot, user_input, temperature, model_select_dropdown, index_files],
249
  outputs=[chatbot, history])
250
  user_input.submit(lambda: "", None, user_input)
 
36
  # MODELS = ["universal-sentence-encoder", "instructor-large"]
37
  MODELS = ["text-davinci-001", "text-davinci-002", "text-davinci-003"]
38
 
39
+ def set_openai_api_key(my_api_key):
40
+ openai.api_key = my_api_key
41
+ return gr.update(visible = True)
42
 
43
+
44
  def add_source_numbers(lst):
45
  return [item[:3] + '\t' + item[3:] for item in (lst)]
46
 
 
123
 
124
 
125
  def predict(
 
126
  history,
127
  chatbot,
128
  inputs,
 
158
  chatbot.append((old_inputs, ""))
159
  else:
160
  chatbot.append((inputs, ""))
 
161
  completions = openai.Completion.create(
162
  engine=selected_model,
163
  prompt=inputs,
 
217
  with gr.Column(scale=5):
218
  with gr.Row():
219
  chatbot = gr.Chatbot(elem_id="chatbot").style(height="100%")
220
+ with gr.Row() as input_raws:
221
  with gr.Column(scale=12):
222
  user_input = gr.Textbox(
223
  show_label=False, placeholder="Enter here"
 
246
  step=0.1,
247
  interactive=True,
248
  label="Temperature",
249
+ openAI_key.submit(set_openai_api_key, [openAI_key], [input_raws]) )
250
  user_input.submit(predict, inputs=[history, chatbot, user_input, temperature, model_select_dropdown, index_files],
251
  outputs=[chatbot, history])
252
  user_input.submit(lambda: "", None, user_input)