Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,13 +22,8 @@ tokenizer, model = load_model()
|
|
| 22 |
|
| 23 |
|
| 24 |
@spaces.GPU
|
| 25 |
-
def generate(
|
| 26 |
-
conversation = []
|
| 27 |
-
for message in history:
|
| 28 |
-
conversation.append({
|
| 29 |
-
"role": message["role"],
|
| 30 |
-
"content": message["content"]
|
| 31 |
-
})
|
| 32 |
|
| 33 |
inputs = tokenizer.apply_chat_template(
|
| 34 |
conversation,
|
|
@@ -41,7 +36,7 @@ def generate(prompt, history):
|
|
| 41 |
with torch.no_grad():
|
| 42 |
outputs = model.generate(
|
| 43 |
**inputs,
|
| 44 |
-
max_new_tokens=
|
| 45 |
)
|
| 46 |
|
| 47 |
generated_tokens = outputs[0, inputs.input_ids.shape[1]:]
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
@spaces.GPU
|
| 25 |
+
def generate(message, history):
|
| 26 |
+
conversation = history + [message]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
inputs = tokenizer.apply_chat_template(
|
| 29 |
conversation,
|
|
|
|
| 36 |
with torch.no_grad():
|
| 37 |
outputs = model.generate(
|
| 38 |
**inputs,
|
| 39 |
+
max_new_tokens=512,
|
| 40 |
)
|
| 41 |
|
| 42 |
generated_tokens = outputs[0, inputs.input_ids.shape[1]:]
|