Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -59,9 +59,9 @@ def generate_response(user_query, relevant_segment):
|
|
| 59 |
|
| 60 |
# Encode the input and generate a response
|
| 61 |
input_ids = tokenizer.encode(user_message, return_tensors='pt')
|
| 62 |
-
|
| 63 |
-
# Create attention mask (1 for real tokens, 0 for padding tokens)
|
| 64 |
-
attention_mask = (input_ids
|
| 65 |
|
| 66 |
# Generate the response using the model
|
| 67 |
output = model.generate(
|
|
@@ -77,7 +77,7 @@ def generate_response(user_query, relevant_segment):
|
|
| 77 |
# Append assistant's message to messages list for context
|
| 78 |
messages.append({"role": "assistant", "content": output_text})
|
| 79 |
return output_text
|
| 80 |
-
|
| 81 |
except Exception as e:
|
| 82 |
print(f"Error in generating response: {e}")
|
| 83 |
return f"Error in generating response: {e}"
|
|
|
|
| 59 |
|
| 60 |
# Encode the input and generate a response
|
| 61 |
input_ids = tokenizer.encode(user_message, return_tensors='pt')
|
| 62 |
+
|
| 63 |
+
# Create the attention mask (1 for real tokens, 0 for padding tokens)
|
| 64 |
+
attention_mask = torch.ones(input_ids.shape, dtype=torch.long) # Create a tensor of ones
|
| 65 |
|
| 66 |
# Generate the response using the model
|
| 67 |
output = model.generate(
|
|
|
|
| 77 |
# Append assistant's message to messages list for context
|
| 78 |
messages.append({"role": "assistant", "content": output_text})
|
| 79 |
return output_text
|
| 80 |
+
|
| 81 |
except Exception as e:
|
| 82 |
print(f"Error in generating response: {e}")
|
| 83 |
return f"Error in generating response: {e}"
|