Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -18,6 +18,8 @@ model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16
|
|
18 |
model.load_adapter(adapter_model_id)
|
19 |
|
20 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
|
|
|
|
21 |
|
22 |
|
23 |
def get_base_prompt():
|
@@ -34,19 +36,17 @@ def format_prompt(base, user_message):
|
|
34 |
|
35 |
def predict(input, history=[]):
|
36 |
input = format_prompt(get_base_prompt(), input)
|
37 |
-
new_user_input_ids = tokenizer.encode(f"{tokenizer.eos_token}
|
38 |
bot_input_ids = torch.cat([torch.LongTensor(history), new_user_input_ids], dim=-1)
|
39 |
|
40 |
history = model.generate(
|
41 |
bot_input_ids,
|
42 |
-
max_length=
|
43 |
pad_token_id=tokenizer.eos_token_id
|
44 |
).tolist()
|
45 |
|
46 |
response = tokenizer.decode(history[0]).split("<|endoftext|>")
|
47 |
-
response = [
|
48 |
-
(response[i], response[i + 1]) for i in range(0, len(response) - 1, 2)
|
49 |
-
]
|
50 |
|
51 |
return response, history
|
52 |
|
|
|
18 |
model.load_adapter(adapter_model_id)
|
19 |
|
20 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
21 |
+
tokenizer.pad_token = tokenizer.eos_token
|
22 |
+
tokenizer.padding_side = "right"
|
23 |
|
24 |
|
25 |
def get_base_prompt():
|
|
|
36 |
|
37 |
def predict(input, history=[]):
|
38 |
input = format_prompt(get_base_prompt(), input)
|
39 |
+
new_user_input_ids = tokenizer.encode(f"{input}{tokenizer.eos_token}", return_tensors="pt")
|
40 |
bot_input_ids = torch.cat([torch.LongTensor(history), new_user_input_ids], dim=-1)
|
41 |
|
42 |
history = model.generate(
|
43 |
bot_input_ids,
|
44 |
+
max_length=2000,
|
45 |
pad_token_id=tokenizer.eos_token_id
|
46 |
).tolist()
|
47 |
|
48 |
response = tokenizer.decode(history[0]).split("<|endoftext|>")
|
49 |
+
response = [(response[i], response[i + 1]) for i in range(0, len(response) - 1, 2)]
|
|
|
|
|
50 |
|
51 |
return response, history
|
52 |
|