bhagyabonam commited on
Commit
b7a2630
·
verified ·
1 Parent(s): 93f396c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -2
app.py CHANGED
@@ -249,8 +249,16 @@ objection_embeddings = np.array(objection_embeddings, dtype="float32")
249
  print(f"Shape of objection_embeddings: {objection_embeddings.shape}")
250
 
251
  # Check if the embeddings dimensionality matches the expected dimension
252
- if objection_embeddings.shape[1] != expected_dim:
253
- raise ValueError(f"Dimensionality of embeddings {objection_embeddings.shape[1]} does not match expected dimension {expected_dim}.")
 
 
 
 
 
 
 
 
254
 
255
  # Add the embeddings to the Faiss index
256
  faiss_index.add(objection_embeddings)
 
249
  print(f"Shape of objection_embeddings: {objection_embeddings.shape}")
250
 
251
  # Check if the embeddings dimensionality matches the expected dimension
252
+ # If the shape is (1,), reshape it to (1, expected_dim)
253
+ if len(objection_embeddings.shape) == 1:
254
+ # Reshape for a single embedding, turn it into a 2D array
255
+ objection_embeddings = objection_embeddings.reshape(1, -1)
256
+ elif len(objection_embeddings.shape) == 2:
257
+ # Check if second dimension matches expected_dim
258
+ if objection_embeddings.shape[1] != expected_dim:
259
+ raise ValueError(f"Dimensionality of embeddings {objection_embeddings.shape[1]} does not match expected dimension {expected_dim}.")
260
+ else:
261
+ raise ValueError(f"Unexpected shape for objection embeddings: {objection_embeddings.shape}")
262
 
263
  # Add the embeddings to the Faiss index
264
  faiss_index.add(objection_embeddings)