Spaces:
Running
Running
customize token output number
Browse files
app.py
CHANGED
@@ -288,7 +288,7 @@ class AbliterationProcessor:
|
|
288 |
modified_weight = down_proj_weight - scale_factor * torch.matmul(projection_matrix, down_proj_weight)
|
289 |
layer.mlp.down_proj.weight.data = modified_weight
|
290 |
|
291 |
-
def chat(self, message, history):
|
292 |
"""Chat functionality"""
|
293 |
if self.model is None or self.tokenizer is None:
|
294 |
return "β οΈ Please load a model first!", history
|
@@ -335,7 +335,7 @@ class AbliterationProcessor:
|
|
335 |
|
336 |
gen = self.model.generate(
|
337 |
toks.to(self.model.device),
|
338 |
-
max_new_tokens=
|
339 |
temperature=0.7,
|
340 |
do_sample=True,
|
341 |
pad_token_id=self.tokenizer.eos_token_id,
|
@@ -472,6 +472,16 @@ def create_interface():
|
|
472 |
org_token.render()
|
473 |
private_repo.render()
|
474 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
475 |
process_btn = gr.Button("π Start Processing", variant="primary")
|
476 |
process_output = gr.Markdown(label="Processing Result")
|
477 |
process_image = gr.Image(show_label=False)
|
@@ -538,18 +548,18 @@ def create_interface():
|
|
538 |
def user(user_message, history):
|
539 |
return "", history + [{"role": "user", "content": user_message}]
|
540 |
|
541 |
-
def bot(history):
|
542 |
if history and history[-1]["role"] == "user":
|
543 |
-
response, _ = processor.chat(history[-1]["content"], history[:-1])
|
544 |
history.append({"role": "assistant", "content": response})
|
545 |
return history
|
546 |
|
547 |
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
548 |
-
bot, chatbot, chatbot
|
549 |
)
|
550 |
|
551 |
send_btn.click(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
552 |
-
bot, chatbot, chatbot
|
553 |
)
|
554 |
|
555 |
clear.click(lambda: [], None, chatbot, queue=False)
|
|
|
288 |
modified_weight = down_proj_weight - scale_factor * torch.matmul(projection_matrix, down_proj_weight)
|
289 |
layer.mlp.down_proj.weight.data = modified_weight
|
290 |
|
291 |
+
def chat(self, message, history, max_new_tokens=2048):
|
292 |
"""Chat functionality"""
|
293 |
if self.model is None or self.tokenizer is None:
|
294 |
return "β οΈ Please load a model first!", history
|
|
|
335 |
|
336 |
gen = self.model.generate(
|
337 |
toks.to(self.model.device),
|
338 |
+
max_new_tokens=max_new_tokens,
|
339 |
temperature=0.7,
|
340 |
do_sample=True,
|
341 |
pad_token_id=self.tokenizer.eos_token_id,
|
|
|
472 |
org_token.render()
|
473 |
private_repo.render()
|
474 |
|
475 |
+
gr.Markdown("### π¬ Chat Settings")
|
476 |
+
max_new_tokens = gr.Number(
|
477 |
+
value=2048,
|
478 |
+
label="Max New Tokens",
|
479 |
+
minimum=1,
|
480 |
+
maximum=8192,
|
481 |
+
step=1,
|
482 |
+
info="Maximum number of tokens to generate in chat responses"
|
483 |
+
)
|
484 |
+
|
485 |
process_btn = gr.Button("π Start Processing", variant="primary")
|
486 |
process_output = gr.Markdown(label="Processing Result")
|
487 |
process_image = gr.Image(show_label=False)
|
|
|
548 |
def user(user_message, history):
|
549 |
return "", history + [{"role": "user", "content": user_message}]
|
550 |
|
551 |
+
def bot(history, max_new_tokens):
|
552 |
if history and history[-1]["role"] == "user":
|
553 |
+
response, _ = processor.chat(history[-1]["content"], history[:-1], max_new_tokens)
|
554 |
history.append({"role": "assistant", "content": response})
|
555 |
return history
|
556 |
|
557 |
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
558 |
+
bot, [chatbot, max_new_tokens], chatbot
|
559 |
)
|
560 |
|
561 |
send_btn.click(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
562 |
+
bot, [chatbot, max_new_tokens], chatbot
|
563 |
)
|
564 |
|
565 |
clear.click(lambda: [], None, chatbot, queue=False)
|