MZhaovo commited on
Commit
a3e8551
·
1 Parent(s): ff3263f

自动查询API使用情况,去掉查询按钮

Browse files
Files changed (2) hide show
  1. ChuanhuChatbot.py +11 -5
  2. modules/utils.py +3 -3
ChuanhuChatbot.py CHANGED
@@ -103,7 +103,6 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
103
  label="API-Key",
104
  )
105
  usageTxt = gr.Markdown(get_usage(my_api_key), elem_id="usage_display")
106
- usageUpdateBtn = gr.Button("🔄 更新API使用情况")
107
  model_select_dropdown = gr.Dropdown(
108
  label="选择模型", choices=MODELS, multiselect=False, value=MODELS[0]
109
  )
@@ -262,17 +261,19 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
262
  transfer_input_args = dict(
263
  fn=transfer_input, inputs=[user_input], outputs=[user_question, user_input, submitBtn, cancelBtn], show_progress=True
264
  )
 
 
 
 
265
 
266
- keyTxt.submit(submit_key, keyTxt, [user_api_key, status_display, usageTxt])
267
- keyTxt.change(submit_key, keyTxt, [user_api_key, status_display, usageTxt])
268
  # Chatbot
269
  cancelBtn.click(cancel_outputing, [], [])
270
 
271
- usageUpdateBtn.click(get_usage, [user_api_key], [usageTxt], show_progress=True)
272
-
273
  user_input.submit(**transfer_input_args).then(**chatgpt_predict_args).then(**end_outputing_args)
 
274
 
275
  submitBtn.click(**transfer_input_args).then(**chatgpt_predict_args).then(**end_outputing_args)
 
276
 
277
  emptyBtn.click(
278
  reset_state,
@@ -298,6 +299,7 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
298
  [chatbot, history, status_display, token_count],
299
  show_progress=True,
300
  ).then(**end_outputing_args)
 
301
 
302
  delLastBtn.click(
303
  delete_last_conversation,
@@ -323,6 +325,10 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
323
  [chatbot, history, status_display, token_count],
324
  show_progress=True,
325
  )
 
 
 
 
326
 
327
  # Template
328
  templateRefreshBtn.click(get_template_names, None, [templateFileSelectDropdown])
 
103
  label="API-Key",
104
  )
105
  usageTxt = gr.Markdown(get_usage(my_api_key), elem_id="usage_display")
 
106
  model_select_dropdown = gr.Dropdown(
107
  label="选择模型", choices=MODELS, multiselect=False, value=MODELS[0]
108
  )
 
261
  transfer_input_args = dict(
262
  fn=transfer_input, inputs=[user_input], outputs=[user_question, user_input, submitBtn, cancelBtn], show_progress=True
263
  )
264
+
265
+ get_usage_args = dict(
266
+ fn=get_usage, inputs=[user_api_key], outputs=[usageTxt], show_progress=False
267
+ )
268
 
 
 
269
  # Chatbot
270
  cancelBtn.click(cancel_outputing, [], [])
271
 
 
 
272
  user_input.submit(**transfer_input_args).then(**chatgpt_predict_args).then(**end_outputing_args)
273
+ user_input.submit(**get_usage_args)
274
 
275
  submitBtn.click(**transfer_input_args).then(**chatgpt_predict_args).then(**end_outputing_args)
276
+ submitBtn.click(**get_usage_args)
277
 
278
  emptyBtn.click(
279
  reset_state,
 
299
  [chatbot, history, status_display, token_count],
300
  show_progress=True,
301
  ).then(**end_outputing_args)
302
+ retryBtn.click(**get_usage_args)
303
 
304
  delLastBtn.click(
305
  delete_last_conversation,
 
325
  [chatbot, history, status_display, token_count],
326
  show_progress=True,
327
  )
328
+ reduceTokenBtn.click(**get_usage_args)
329
+
330
+ # ChatGPT
331
+ keyTxt.change(submit_key, keyTxt, [user_api_key, status_display]).then(**get_usage_args)
332
 
333
  # Template
334
  templateRefreshBtn.click(get_template_names, None, [templateFileSelectDropdown])
modules/utils.py CHANGED
@@ -22,7 +22,6 @@ from pygments.formatters import HtmlFormatter
22
 
23
  from modules.presets import *
24
  import modules.shared as shared
25
- from modules.openai_func import get_usage
26
 
27
  logging.basicConfig(
28
  level=logging.INFO,
@@ -116,7 +115,8 @@ def convert_mdtext(md_text):
116
 
117
 
118
  def convert_asis(userinput):
119
- return f"<p style=\"white-space:pre-wrap;\">{html.escape(userinput)}</p>"+ALREADY_CONVERTED_MARK
 
120
 
121
  def detect_converted_mark(userinput):
122
  if userinput.endswith(ALREADY_CONVERTED_MARK):
@@ -350,7 +350,7 @@ def submit_key(key):
350
  key = key.strip()
351
  msg = f"API密钥更改为了{hide_middle_chars(key)}"
352
  logging.info(msg)
353
- return key, msg, get_usage(key)
354
 
355
 
356
  def sha1sum(filename):
 
22
 
23
  from modules.presets import *
24
  import modules.shared as shared
 
25
 
26
  logging.basicConfig(
27
  level=logging.INFO,
 
115
 
116
 
117
  def convert_asis(userinput):
118
+ escaped_html = html.escape(userinput).replace(" ", "&nbsp;").replace("\n", "<br>")
119
+ return f"{escaped_html}"+ALREADY_CONVERTED_MARK
120
 
121
  def detect_converted_mark(userinput):
122
  if userinput.endswith(ALREADY_CONVERTED_MARK):
 
350
  key = key.strip()
351
  msg = f"API密钥更改为了{hide_middle_chars(key)}"
352
  logging.info(msg)
353
+ return key, msg
354
 
355
 
356
  def sha1sum(filename):