Emmanuel Frimpong Asante commited on
Commit
f4756d6
·
1 Parent(s): fbbb3f7

"Update space"

Browse files

Signed-off-by: Emmanuel Frimpong Asante <[email protected]>

Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -105,9 +105,17 @@ generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
105
  # Define Mistral-based response generation with streaming support
106
  def mistral_response_stream(user_input):
107
  try:
108
- inputs = tokenizer(user_input, return_tensors="pt", truncation=True)
109
- outputs = model.generate(inputs["input_ids"], max_length=150, do_sample=True, temperature=0.7,
110
- pad_token_id=tokenizer.eos_token_id)
 
 
 
 
 
 
 
 
111
 
112
  # Stream the response token by token
113
  for output in outputs:
 
105
  # Define Mistral-based response generation with streaming support
106
  def mistral_response_stream(user_input):
107
  try:
108
+ # Set truncation and max_length explicitly and pass attention_mask
109
+ inputs = tokenizer(user_input, return_tensors="pt", truncation=True, max_length=150, padding=True)
110
+ attention_mask = inputs["attention_mask"]
111
+ outputs = model.generate(
112
+ inputs["input_ids"],
113
+ max_length=150,
114
+ do_sample=True,
115
+ temperature=0.7,
116
+ pad_token_id=tokenizer.eos_token_id,
117
+ attention_mask=attention_mask
118
+ )
119
 
120
  # Stream the response token by token
121
  for output in outputs: