xu song commited on
Commit
7085eea
1 Parent(s): 411027b
Files changed (2) hide show
  1. app.py +34 -41
  2. app_util.py +2 -1
app.py CHANGED
@@ -1,21 +1,4 @@
1
  """
2
- 来自 https://github.com/OpenLMLab/MOSS/blob/main/moss_web_demo_gradio.py
3
-
4
-
5
- # 难点
6
-
7
- ## TODO
8
-
9
-
10
- -[x] 代码和表格的预览
11
- -[x] markdown解析:mdtex2html
12
- -[ ] 可编辑chatbot:https://github.com/gradio-app/gradio/issues/4444
13
- -[ ] 乱码问题
14
-
15
-
16
- ## Reference
17
-
18
- - https://github.com/GaiZhenbiao/ChuanhuChatGPT/
19
  """
20
 
21
  import config
@@ -29,51 +12,61 @@ system_list = [
29
  "你是一个心理咨询师。",
30
  ]
31
 
 
 
 
 
 
32
  """
33
- TODO: 使用说明
34
- """
35
  with gr.Blocks() as demo:
36
  # Knowledge Distillation through Self Chatting
37
  gr.HTML("""<h1 align="center">Distilling the Knowledge through Self Chatting</h1>""")
 
38
  with gr.Row():
39
- system = gr.Dropdown(
40
- choices=system_list,
41
- value=system_list[0],
42
- allow_custom_value=True,
43
- interactive=True,
44
- label="System message",
45
- scale=4,
46
- )
47
  gr.Dropdown(
48
  ["Qwen2-0.5B-Instruct", "llama3.1", "gemini"],
49
  value="Qwen2-0.5B-Instruct",
50
  label="model",
51
  interactive=True,
52
  scale=1,
 
 
 
 
 
 
 
 
 
53
  )
 
54
  chatbot = gr.Chatbot(avatar_images=("assets/man.png", "assets/bot.png"))
55
  with gr.Row():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  with gr.Column(scale=4):
57
  generated_text = gr.Textbox(show_label=False, placeholder="...", lines=10, visible=False)
 
58
  with gr.Row():
59
- generate_btn = gr.Button("🤔️ Generate")
60
  retry_btn = gr.Button("🔄 Regenerate")
61
  undo_btn = gr.Button("↩️ Undo")
62
  clear_btn = gr.Button("🗑️ Clear") # 🧹 Clear History (清除历史)
63
- stop_btn = gr.Button("停止生成", variant="primary")
 
64
 
65
- slider_max_tokens = gr.Slider(minimum=1, maximum=config.MAX_SEQUENCE_LENGTH,
66
- value=config.DEFAULT_MAX_TOKENS, step=1, label="Max tokens")
67
- slider_temperature = gr.Slider(minimum=0.1, maximum=10.0,
68
- value=config.DEFAULT_TEMPERATURE, step=0.1, label="Temperature",
69
- info="Larger temperature increase the randomness")
70
- slider_top_p = gr.Slider(
71
- minimum=0.1,
72
- maximum=1.0,
73
- value=config.DEFAULT_TOP_P,
74
- step=0.05,
75
- label="Top-p (nucleus sampling)",
76
- )
77
 
78
  ########
79
  history = gr.State([{"role": "system", "content": system_list[0]}])
 
1
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  """
3
 
4
  import config
 
12
  "你是一个心理咨询师。",
13
  ]
14
 
15
+
16
+ doc = """\
17
+ There are maily two types of user simulator:
18
+ - prompt-based user-simulator (role-play)
19
+ - model-based user-simulator
20
  """
21
+
 
22
  with gr.Blocks() as demo:
23
  # Knowledge Distillation through Self Chatting
24
  gr.HTML("""<h1 align="center">Distilling the Knowledge through Self Chatting</h1>""")
25
+ gr.Markdown(doc, visible=False)
26
  with gr.Row():
 
 
 
 
 
 
 
 
27
  gr.Dropdown(
28
  ["Qwen2-0.5B-Instruct", "llama3.1", "gemini"],
29
  value="Qwen2-0.5B-Instruct",
30
  label="model",
31
  interactive=True,
32
  scale=1,
33
+ visible=False
34
+ )
35
+ system = gr.Dropdown(
36
+ choices=system_list,
37
+ value=system_list[0],
38
+ allow_custom_value=True,
39
+ interactive=True,
40
+ label="System message",
41
+ scale=5,
42
  )
43
+
44
  chatbot = gr.Chatbot(avatar_images=("assets/man.png", "assets/bot.png"))
45
  with gr.Row():
46
+ with gr.Column():
47
+ slider_max_tokens = gr.Slider(minimum=1, maximum=config.MAX_SEQUENCE_LENGTH,
48
+ value=config.DEFAULT_MAX_TOKENS, step=1, label="Max tokens")
49
+ slider_temperature = gr.Slider(minimum=0.1, maximum=10.0,
50
+ value=config.DEFAULT_TEMPERATURE, step=0.1, label="Temperature",
51
+ info="Larger temperature increase the randomness")
52
+ slider_top_p = gr.Slider(
53
+ minimum=0.1,
54
+ maximum=1.0,
55
+ value=config.DEFAULT_TOP_P,
56
+ step=0.05,
57
+ label="Top-p (nucleus sampling)",
58
+ )
59
+
60
  with gr.Column(scale=4):
61
  generated_text = gr.Textbox(show_label=False, placeholder="...", lines=10, visible=False)
62
+ generate_btn = gr.Button("🤔️ Generate", variant="primary")
63
  with gr.Row():
 
64
  retry_btn = gr.Button("🔄 Regenerate")
65
  undo_btn = gr.Button("↩️ Undo")
66
  clear_btn = gr.Button("🗑️ Clear") # 🧹 Clear History (清除历史)
67
+ # stop_btn = gr.Button("停止生成", variant="primary", visible=False)
68
+
69
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
71
  ########
72
  history = gr.State([{"role": "system", "content": system_list[0]}])
app_util.py CHANGED
@@ -1,7 +1,8 @@
1
  import json
2
  import gradio as gr
3
  from utils.logging_util import logger
4
- from models.cpp_qwen2 import bot
 
5
 
6
 
7
  #
 
1
  import json
2
  import gradio as gr
3
  from utils.logging_util import logger
4
+ # from models.cpp_qwen2 import bot
5
+ from models.hf_qwen2 import bot
6
 
7
 
8
  #