update ui and parameters
Browse files
app.py
CHANGED
@@ -16,10 +16,10 @@ urllib.request.urlretrieve(
|
|
16 |
parser = argparse.ArgumentParser()
|
17 |
parser.add_argument("-m", "--model", default=DEFAULT_MODEL_PATH, type=Path, help="model path")
|
18 |
parser.add_argument("--mode", default="chat", type=str, choices=["chat", "generate"], help="inference mode")
|
19 |
-
parser.add_argument("-l", "--
|
20 |
parser.add_argument("-c", "--max_context_length", default=1024, type=int, help="max context length")
|
21 |
parser.add_argument("--top_k", default=40, type=int, help="top-k sampling")
|
22 |
-
parser.add_argument("--top_p", default=0.
|
23 |
parser.add_argument("--temp", default=0.5, type=float, help="temperature")
|
24 |
parser.add_argument("--repeat_penalty", default=1.0, type=float, help="penalize repeat sequence of tokens")
|
25 |
parser.add_argument("-t", "--threads", default=0, type=int, help="number of threads for inference")
|
@@ -36,13 +36,13 @@ def postprocess(text):
|
|
36 |
return text
|
37 |
|
38 |
|
39 |
-
def predict(input, chatbot,
|
40 |
chatbot.append((postprocess(input), ""))
|
41 |
messages.append(chatglm_cpp.ChatMessage(role="user", content=input))
|
42 |
full_messages = [system_message] + messages
|
43 |
|
44 |
generation_kwargs = dict(
|
45 |
-
|
46 |
max_context_length=args.max_context_length,
|
47 |
do_sample=temperature > 0,
|
48 |
top_k=args.top_k,
|
@@ -83,13 +83,13 @@ title = """
|
|
83 |
with gr.Blocks() as demo:
|
84 |
gr.HTML(title)
|
85 |
|
86 |
-
chatbot = gr.Chatbot()
|
87 |
with gr.Row():
|
88 |
with gr.Column(scale=4):
|
89 |
user_input = gr.Textbox(show_label=False, placeholder="Input...", lines=8)
|
90 |
submitBtn = gr.Button("Submit", variant="primary")
|
91 |
with gr.Column(scale=1):
|
92 |
-
|
93 |
top_p = gr.Slider(0, 1, value=args.top_p, step=0.01, label="Top P", interactive=True)
|
94 |
temperature = gr.Slider(0, 1, value=args.temp, step=0.01, label="Temperature", interactive=True)
|
95 |
emptyBtn = gr.Button("Clear History")
|
@@ -98,7 +98,7 @@ with gr.Blocks() as demo:
|
|
98 |
|
99 |
submitBtn.click(
|
100 |
predict,
|
101 |
-
[user_input, chatbot,
|
102 |
[chatbot, messages],
|
103 |
show_progress=True,
|
104 |
)
|
|
|
16 |
parser = argparse.ArgumentParser()
|
17 |
parser.add_argument("-m", "--model", default=DEFAULT_MODEL_PATH, type=Path, help="model path")
|
18 |
parser.add_argument("--mode", default="chat", type=str, choices=["chat", "generate"], help="inference mode")
|
19 |
+
parser.add_argument("-l", "--max_new_tokens", default=64, type=int, help="max total output tokens")
|
20 |
parser.add_argument("-c", "--max_context_length", default=1024, type=int, help="max context length")
|
21 |
parser.add_argument("--top_k", default=40, type=int, help="top-k sampling")
|
22 |
+
parser.add_argument("--top_p", default=0.75, type=float, help="top-p sampling")
|
23 |
parser.add_argument("--temp", default=0.5, type=float, help="temperature")
|
24 |
parser.add_argument("--repeat_penalty", default=1.0, type=float, help="penalize repeat sequence of tokens")
|
25 |
parser.add_argument("-t", "--threads", default=0, type=int, help="number of threads for inference")
|
|
|
36 |
return text
|
37 |
|
38 |
|
39 |
+
def predict(input, chatbot, max_new_tokens, top_p, temperature, messages):
|
40 |
chatbot.append((postprocess(input), ""))
|
41 |
messages.append(chatglm_cpp.ChatMessage(role="user", content=input))
|
42 |
full_messages = [system_message] + messages
|
43 |
|
44 |
generation_kwargs = dict(
|
45 |
+
max_new_tokens=max_new_tokens,
|
46 |
max_context_length=args.max_context_length,
|
47 |
do_sample=temperature > 0,
|
48 |
top_k=args.top_k,
|
|
|
83 |
with gr.Blocks() as demo:
|
84 |
gr.HTML(title)
|
85 |
|
86 |
+
chatbot = gr.Chatbot().style(height=300)
|
87 |
with gr.Row():
|
88 |
with gr.Column(scale=4):
|
89 |
user_input = gr.Textbox(show_label=False, placeholder="Input...", lines=8)
|
90 |
submitBtn = gr.Button("Submit", variant="primary")
|
91 |
with gr.Column(scale=1):
|
92 |
+
max_new_tokens = gr.Slider(0, 512, value=args.max_new_tokens, step=1.0, label="Maximum output tokens", interactive=True)
|
93 |
top_p = gr.Slider(0, 1, value=args.top_p, step=0.01, label="Top P", interactive=True)
|
94 |
temperature = gr.Slider(0, 1, value=args.temp, step=0.01, label="Temperature", interactive=True)
|
95 |
emptyBtn = gr.Button("Clear History")
|
|
|
98 |
|
99 |
submitBtn.click(
|
100 |
predict,
|
101 |
+
[user_input, chatbot, max_new_tokens, top_p, temperature, messages],
|
102 |
[chatbot, messages],
|
103 |
show_progress=True,
|
104 |
)
|