Keldos commited on
Commit
677b142
1 Parent(s): 610bbc4

feat: Chatbot的label改为当前模型名称 (#733)

Browse files
Files changed (2) hide show
  1. ChuanhuChatbot.py +7 -5
  2. modules/models/models.py +3 -2
ChuanhuChatbot.py CHANGED
@@ -42,7 +42,7 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
42
  with gr.Row().style(equal_height=True):
43
  with gr.Column(scale=5):
44
  with gr.Row():
45
- chatbot = gr.Chatbot(elem_id="chuanhu_chatbot").style(height="100%")
46
  with gr.Row():
47
  with gr.Column(min_width=225, scale=12):
48
  user_input = gr.Textbox(
@@ -268,6 +268,7 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
268
 
269
  gr.Markdown(CHUANHU_DESCRIPTION, elem_id="description")
270
  gr.HTML(FOOTER.format(versions=versions_html()), elem_id="footer")
 
271
  # https://github.com/gradio-app/gradio/pull/3296
272
  def create_greeting(request: gr.Request):
273
  if hasattr(request, "username") and request.username: # is not None or is not ""
@@ -277,8 +278,9 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
277
  user_info, user_name = gr.Markdown.update(value=f"", visible=False), ""
278
  current_model = get_model(model_name = MODELS[DEFAULT_MODEL], access_key = my_api_key)[0]
279
  current_model.set_user_identifier(user_name)
280
- return user_info, user_name, current_model, toggle_like_btn_visibility(DEFAULT_MODEL), *current_model.auto_load(), get_history_names(False, user_name)
281
- demo.load(create_greeting, inputs=None, outputs=[user_info, user_name, current_model, like_dislike_area, systemPromptTxt, chatbot, historyFileSelectDropdown], api_name="load")
 
282
  chatgpt_predict_args = dict(
283
  fn=predict,
284
  inputs=[
@@ -390,9 +392,9 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
390
  keyTxt.change(set_key, [current_model, keyTxt], [user_api_key, status_display], api_name="set_key").then(**get_usage_args)
391
  keyTxt.submit(**get_usage_args)
392
  single_turn_checkbox.change(set_single_turn, [current_model, single_turn_checkbox], None)
393
- model_select_dropdown.change(get_model, [model_select_dropdown, lora_select_dropdown, user_api_key, temperature_slider, top_p_slider, systemPromptTxt, user_name], [current_model, status_display, lora_select_dropdown], show_progress=True, api_name="get_model")
394
  model_select_dropdown.change(toggle_like_btn_visibility, [model_select_dropdown], [like_dislike_area], show_progress=False)
395
- lora_select_dropdown.change(get_model, [model_select_dropdown, lora_select_dropdown, user_api_key, temperature_slider, top_p_slider, systemPromptTxt, user_name], [current_model, status_display], show_progress=True)
396
 
397
  # Template
398
  systemPromptTxt.change(set_system_prompt, [current_model, systemPromptTxt], None)
 
42
  with gr.Row().style(equal_height=True):
43
  with gr.Column(scale=5):
44
  with gr.Row():
45
+ chatbot = gr.Chatbot(label="Chuanhu Chat", elem_id="chuanhu_chatbot").style(height="100%")
46
  with gr.Row():
47
  with gr.Column(min_width=225, scale=12):
48
  user_input = gr.Textbox(
 
268
 
269
  gr.Markdown(CHUANHU_DESCRIPTION, elem_id="description")
270
  gr.HTML(FOOTER.format(versions=versions_html()), elem_id="footer")
271
+
272
  # https://github.com/gradio-app/gradio/pull/3296
273
  def create_greeting(request: gr.Request):
274
  if hasattr(request, "username") and request.username: # is not None or is not ""
 
278
  user_info, user_name = gr.Markdown.update(value=f"", visible=False), ""
279
  current_model = get_model(model_name = MODELS[DEFAULT_MODEL], access_key = my_api_key)[0]
280
  current_model.set_user_identifier(user_name)
281
+ chatbot = gr.Chatbot.update(label=MODELS[DEFAULT_MODEL])
282
+ return user_info, user_name, current_model, toggle_like_btn_visibility(DEFAULT_MODEL), *current_model.auto_load(), get_history_names(False, user_name), chatbot
283
+ demo.load(create_greeting, inputs=None, outputs=[user_info, user_name, current_model, like_dislike_area, systemPromptTxt, chatbot, historyFileSelectDropdown, chatbot], api_name="load")
284
  chatgpt_predict_args = dict(
285
  fn=predict,
286
  inputs=[
 
392
  keyTxt.change(set_key, [current_model, keyTxt], [user_api_key, status_display], api_name="set_key").then(**get_usage_args)
393
  keyTxt.submit(**get_usage_args)
394
  single_turn_checkbox.change(set_single_turn, [current_model, single_turn_checkbox], None)
395
+ model_select_dropdown.change(get_model, [model_select_dropdown, lora_select_dropdown, user_api_key, temperature_slider, top_p_slider, systemPromptTxt, user_name], [current_model, status_display, chatbot, lora_select_dropdown], show_progress=True, api_name="get_model")
396
  model_select_dropdown.change(toggle_like_btn_visibility, [model_select_dropdown], [like_dislike_area], show_progress=False)
397
+ lora_select_dropdown.change(get_model, [model_select_dropdown, lora_select_dropdown, user_api_key, temperature_slider, top_p_slider, systemPromptTxt, user_name], [current_model, status_display, chatbot], show_progress=True)
398
 
399
  # Template
400
  systemPromptTxt.change(set_system_prompt, [current_model, systemPromptTxt], None)
modules/models/models.py CHANGED
@@ -602,13 +602,14 @@ def get_model(
602
  elif model_type == ModelType.Unknown:
603
  raise ValueError(f"未知模型: {model_name}")
604
  logging.info(msg)
 
605
  except Exception as e:
606
  logging.error(e)
607
  msg = f"{STANDARD_ERROR_MSG}: {e}"
608
  if dont_change_lora_selector:
609
- return model, msg
610
  else:
611
- return model, msg, gr.Dropdown.update(choices=lora_choices, visible=lora_selector_visibility)
612
 
613
 
614
  if __name__ == "__main__":
 
602
  elif model_type == ModelType.Unknown:
603
  raise ValueError(f"未知模型: {model_name}")
604
  logging.info(msg)
605
+ chatbot = gr.Chatbot.update(label=model_name)
606
  except Exception as e:
607
  logging.error(e)
608
  msg = f"{STANDARD_ERROR_MSG}: {e}"
609
  if dont_change_lora_selector:
610
+ return model, msg, chatbot
611
  else:
612
+ return model, msg, chatbot, gr.Dropdown.update(choices=lora_choices, visible=lora_selector_visibility)
613
 
614
 
615
  if __name__ == "__main__":