hugforziio commited on
Commit
4c7da61
1 Parent(s): a5410ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -7
app.py CHANGED
@@ -65,7 +65,7 @@ def on_click_send_btn(
65
  chat_log_md += '\n---\n'
66
 
67
  # if chat_input=='':
68
- # return old_state, chat_log, chat_log_md, None, None, chat_input
69
 
70
  print('\n')
71
  print(chat_input)
@@ -74,7 +74,7 @@ def on_click_send_btn(
74
  try:
75
  logit_bias_json = json.dumps(logit_bias) if logit_bias else None
76
  except:
77
- return old_state, chat_log, chat_log_md, None, None, chat_input
78
 
79
  new_state = copy.deepcopy(old_state) or {}
80
 
@@ -138,7 +138,7 @@ def on_click_send_btn(
138
  chat_log.append([the_response_role, the_response])
139
  chat_log_md += f"##### `{the_response_role}`\n\n{the_response}\n\n"
140
 
141
- return new_state, chat_log, chat_log_md, chat_last_resp, props_json, ''
142
  except Exception as error:
143
  print(error)
144
 
@@ -158,13 +158,16 @@ def on_click_send_btn(
158
 
159
  chat_log_md += "\n"
160
  chat_log_md += str(error)
161
- return new_state, chat_log, chat_log_md, None, props_json, chat_input
162
 
163
 
164
  def clear_history():
165
  return [], ""
166
 
167
  def copy_history(txt):
 
 
 
168
  pass
169
 
170
 
@@ -172,6 +175,7 @@ css = """
172
  .table-wrap .cell-wrap input {min-width:80%}
173
  #api-key-textbox textarea {filter:blur(8px); transition: filter 0.25s}
174
  #api-key-textbox textarea:focus {filter:none}
 
175
  """
176
  with gradio.Blocks(title="ChatGPT", css=css) as demo:
177
  global_state = gradio.State(value={})
@@ -250,11 +254,25 @@ with gradio.Blocks(title="ChatGPT", css=css) as demo:
250
  with gradio.Column(scale=10):
251
  chat_log = gradio.State()
252
  with gradio.Box():
253
- chat_log_box = gradio.Markdown(label='chat history', value="<center>(empty)</center>")
254
- chat_copy_history_btn = gradio.Button("Copy all (as html currently)")
 
 
 
 
 
255
  chat_copy_history_btn.click(
256
  copy_history, inputs=[chat_log_box],
257
  _js="""(txt)=>{
 
 
 
 
 
 
 
 
 
258
  try {let promise = navigator?.clipboard?.writeText?.(txt);}
259
  catch(error) {console?.log?.(error);};
260
  }""",
@@ -278,7 +296,7 @@ with gradio.Blocks(title="ChatGPT", css=css) as demo:
278
  global_state, api_key_text, chat_input_role, chat_input, prompt_table, chat_use_prompt, chat_use_history, chat_log,
279
  chat_model, chat_temperature, chat_top_p, chat_choices_num, chat_stream, chat_max_tokens, chat_presence_penalty, chat_frequency_penalty, chat_logit_bias,
280
  ],
281
- outputs=[global_state, chat_log, chat_log_box, chat_last_resp, chat_last_req, chat_input],
282
  api_name="click-send-btn",
283
  )
284
 
 
65
  chat_log_md += '\n---\n'
66
 
67
  # if chat_input=='':
68
+ # return old_state, chat_log, chat_log_md, chat_log_md, None, None, chat_input
69
 
70
  print('\n')
71
  print(chat_input)
 
74
  try:
75
  logit_bias_json = json.dumps(logit_bias) if logit_bias else None
76
  except:
77
+ return old_state, chat_log, chat_log_md, chat_log_md, None, None, chat_input
78
 
79
  new_state = copy.deepcopy(old_state) or {}
80
 
 
138
  chat_log.append([the_response_role, the_response])
139
  chat_log_md += f"##### `{the_response_role}`\n\n{the_response}\n\n"
140
 
141
+ return new_state, chat_log, chat_log_md, chat_log_md, chat_last_resp, props_json, ''
142
  except Exception as error:
143
  print(error)
144
 
 
158
 
159
  chat_log_md += "\n"
160
  chat_log_md += str(error)
161
+ return new_state, chat_log, chat_log_md, chat_log_md, None, props_json, chat_input
162
 
163
 
164
  def clear_history():
165
  return [], ""
166
 
167
  def copy_history(txt):
168
+ # print('\n\n copying')
169
+ # print(txt)
170
+ # print('\n\n')
171
  pass
172
 
173
 
 
175
  .table-wrap .cell-wrap input {min-width:80%}
176
  #api-key-textbox textarea {filter:blur(8px); transition: filter 0.25s}
177
  #api-key-textbox textarea:focus {filter:none}
178
+ #chat-log-md hr {margin-top: 1rem; margin-bottom: 1rem;}
179
  """
180
  with gradio.Blocks(title="ChatGPT", css=css) as demo:
181
  global_state = gradio.State(value={})
 
254
  with gradio.Column(scale=10):
255
  chat_log = gradio.State()
256
  with gradio.Box():
257
+ with gradio.Column(scale=10):
258
+ chat_log_box = gradio.Markdown(label='chat history', value="<center>(empty)</center>", elem_id="chat-log-md")
259
+ real_md_box = gradio.Textbox(value="", visible=False)
260
+ with gradio.Row():
261
+ chat_copy_history_btn = gradio.Button("Copy all (as HTML)")
262
+ chat_copy_history_md_btn = gradio.Button("Copy all (as Markdown)")
263
+
264
  chat_copy_history_btn.click(
265
  copy_history, inputs=[chat_log_box],
266
  _js="""(txt)=>{
267
+ console.log(txt);
268
+ try {let promise = navigator?.clipboard?.writeText?.(txt);}
269
+ catch(error) {console?.log?.(error);};
270
+ }""",
271
+ )
272
+ chat_copy_history_md_btn.click(
273
+ copy_history, inputs=[real_md_box],
274
+ _js="""(txt)=>{
275
+ console.log(txt);
276
  try {let promise = navigator?.clipboard?.writeText?.(txt);}
277
  catch(error) {console?.log?.(error);};
278
  }""",
 
296
  global_state, api_key_text, chat_input_role, chat_input, prompt_table, chat_use_prompt, chat_use_history, chat_log,
297
  chat_model, chat_temperature, chat_top_p, chat_choices_num, chat_stream, chat_max_tokens, chat_presence_penalty, chat_frequency_penalty, chat_logit_bias,
298
  ],
299
+ outputs=[global_state, chat_log, chat_log_box, real_md_box, chat_last_resp, chat_last_req, chat_input],
300
  api_name="click-send-btn",
301
  )
302