Spaces:
Runtime error
Runtime error
Mikhil-jivus
commited on
Commit
•
b7d6aa3
1
Parent(s):
c2a0993
Update app.py
Browse files
app.py
CHANGED
@@ -36,19 +36,16 @@ def respond(
|
|
36 |
|
37 |
messages.append({"role": "user", "content": message})
|
38 |
|
39 |
-
# Tokenize the input messages
|
40 |
input_text = system_message + " ".join([f"{msg['role']}: {msg['content']}" for msg in messages])
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
)
|
48 |
-
|
49 |
-
input_ids = inputs["input_ids"]
|
50 |
-
attention_mask = inputs["attention_mask"]
|
51 |
-
|
52 |
# Generate a response
|
53 |
chat_history_ids = model.generate(
|
54 |
input_ids,
|
@@ -57,9 +54,9 @@ def respond(
|
|
57 |
top_p=top_p,
|
58 |
pad_token_id=tokenizer.eos_token_id,
|
59 |
do_sample=True,
|
60 |
-
attention_mask=attention_mask,
|
61 |
)
|
62 |
-
|
63 |
# Decode the response
|
64 |
response = tokenizer.decode(chat_history_ids[:, input_ids.shape[-1]:][0], skip_special_tokens=True)
|
65 |
|
|
|
36 |
|
37 |
messages.append({"role": "user", "content": message})
|
38 |
|
39 |
+
# Tokenize the input messages
|
40 |
input_text = system_message + " ".join([f"{msg['role']}: {msg['content']}" for msg in messages])
|
41 |
+
input_ids = tokenizer.encode(input_text, return_tensors="pt")
|
42 |
+
|
43 |
+
# Move input_ids to the GPU
|
44 |
+
input_ids = input_ids.to("cuda")
|
45 |
+
|
46 |
+
# Create attention mask and move to GPU
|
47 |
+
attention_mask = input_ids.ne(tokenizer.pad_token_id).long().to("cuda")
|
48 |
+
|
|
|
|
|
|
|
49 |
# Generate a response
|
50 |
chat_history_ids = model.generate(
|
51 |
input_ids,
|
|
|
54 |
top_p=top_p,
|
55 |
pad_token_id=tokenizer.eos_token_id,
|
56 |
do_sample=True,
|
57 |
+
attention_mask=attention_mask,
|
58 |
)
|
59 |
+
|
60 |
# Decode the response
|
61 |
response = tokenizer.decode(chat_history_ids[:, input_ids.shape[-1]:][0], skip_special_tokens=True)
|
62 |
|