xiaoheiqaq commited on
Commit
8a5f65c
1 Parent(s): 1e11e19

add model parameters

Browse files
Files changed (1) hide show
  1. app.py +42 -12
app.py CHANGED
@@ -9,12 +9,16 @@ username = os.getenv('USERNAME')
9
  password = os.getenv('PASSWORD')
10
  system_prompt_text = "你是Emi,正在和用户手机聊天"
11
 
12
- def predict(message, history):
13
  global system_prompt_text, url
14
  payload = {
15
  "message": message,
16
  "system_message": system_prompt_text,
17
- "history": history
 
 
 
 
18
  }
19
  headers = {
20
  "Content-Type": "application/json"
@@ -33,20 +37,46 @@ def update_system_prompt(new_content):
33
  system_prompt_text = new_content
34
 
35
  with gr.Blocks(fill_height=True) as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  gr.ChatInterface(
37
  predict,
38
  cache_examples=False,
39
- examples=["我心情好差呜呜",
40
- "工作之余,你有什么爱好或兴趣吗?",
41
- "谁创造了你?",
42
- "请自我介绍一下",
43
- "对未来有什么打算吗?",
44
- "Emi会弹钢琴吗",
45
- "你能感觉到疼痛吗?",
46
- "你觉得自己像AI吗?",
47
- "你能全天候工作吗?",
48
- "你有更新过吗?"]
 
49
  )
 
50
  system_prompt = gr.Textbox(value=system_prompt_text, info="System Message:", placeholder="你是Emi",
51
  interactive=True, lines=5)
52
  system_prompt.change(
 
9
  password = os.getenv('PASSWORD')
10
  system_prompt_text = "你是Emi,正在和用户手机聊天"
11
 
12
+ def predict(message, history, max_new_tokens, top_k, top_p, temperature):
13
  global system_prompt_text, url
14
  payload = {
15
  "message": message,
16
  "system_message": system_prompt_text,
17
+ "history": history,
18
+ "max_new_tokens": max_new_tokens,
19
+ "top_k": top_k,
20
+ "top_p": top_p,
21
+ "temperature": temperature,
22
  }
23
  headers = {
24
  "Content-Type": "application/json"
 
37
  system_prompt_text = new_content
38
 
39
  with gr.Blocks(fill_height=True) as demo:
40
+ max_new_tokens_slider = gr.Slider(
41
+ minimum=1, maximum=500, value=50, step=1,
42
+ label="Max New Tokens (The maximum number of tokens to generate in the response. This limits the length of the generated text.)",
43
+ render=False
44
+ )
45
+
46
+ top_k_slider = gr.Slider(
47
+ minimum=0, maximum=100, value=50, step=1,
48
+ label="Top K (The number of highest probability vocabulary tokens to keep for top-k filtering. This controls the diversity of the generated text by limiting the number of token options at each step.)",
49
+ render=False
50
+ )
51
+
52
+ top_p_slider = gr.Slider(
53
+ minimum=0.0, maximum=1.0, value=1.0, step=0.01,
54
+ label="Top P (The cumulative probability threshold for nucleus sampling. This controls the diversity of the generated text by sampling tokens from the smallest possible set whose cumulative probability is above the threshold.)",
55
+ render=False
56
+ )
57
+
58
+ temperature_slider = gr.Slider(
59
+ minimum=0.0, maximum=2.0, value=1.0, step=0.01,
60
+ label="Temperature (The sampling temperature to use. This controls the randomness of predictions by scaling the logits before applying softmax. Lower values make the model more deterministic, while higher values increase diversity.)",
61
+ render=False
62
+ )
63
+
64
  gr.ChatInterface(
65
  predict,
66
  cache_examples=False,
67
+ additional_inputs=[max_new_tokens_slider, top_k_slider, top_p_slider, temperature_slider],
68
+ examples=[ ["我心情好差呜呜", None, None, None, None],
69
+ ["工作之余,你有什么爱好或兴趣吗?", None, None, None, None],
70
+ ["谁创造了你?", None, None, None, None],
71
+ ["请自我介绍一下", None, None, None, None],
72
+ ["对未来有什么打算吗?", None, None, None, None],
73
+ ["Emi会弹钢琴吗", None, None, None, None],
74
+ ["你能感觉到疼痛吗?", None, None, None, None],
75
+ ["你觉得自己像AI吗?", None, None, None, None],
76
+ ["你能全天候工作吗?", None, None, None, None],
77
+ ["你有更新过吗?", None, None, None, None]]
78
  )
79
+
80
  system_prompt = gr.Textbox(value=system_prompt_text, info="System Message:", placeholder="你是Emi",
81
  interactive=True, lines=5)
82
  system_prompt.change(