macadeliccc commited on
Commit
f7da2ba
·
1 Parent(s): f08d3be
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -22,12 +22,13 @@ def generate_response(user_input, chat_history):
22
  if chat_history:
23
  prompt = chat_history + prompt
24
  inputs = tokenizer(prompt, return_tensors="pt", padding=True, truncation=True, max_length=1024)
25
-
26
- # Move tensors to the same device as model
27
  inputs = {k: v.to(model.device) for k, v in inputs.items()}
28
 
29
  with torch.no_grad():
30
- output = model.generate(**inputs, max_length=512, num_return_sequences=1, pad_token_id=tokenizer.eos_token_id)
 
31
  response = tokenizer.decode(output[0], skip_special_tokens=True)
32
 
33
  # Update chat history
 
22
  if chat_history:
23
  prompt = chat_history + prompt
24
  inputs = tokenizer(prompt, return_tensors="pt", padding=True, truncation=True, max_length=1024)
25
+
26
+ # Ensure all tensors are moved to the model's device
27
  inputs = {k: v.to(model.device) for k, v in inputs.items()}
28
 
29
  with torch.no_grad():
30
+ # Generate the model's output
31
+ output = model.generate(**inputs, max_length=1024, num_return_sequences=1, pad_token_id=tokenizer.eos_token_id)
32
  response = tokenizer.decode(output[0], skip_special_tokens=True)
33
 
34
  # Update chat history