Yoxas commited on
Commit
259ef44
·
verified ·
1 Parent(s): 75e6466

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -2
app.py CHANGED
@@ -6,11 +6,23 @@ import faiss
6
  import torch
7
  import json
8
  import spaces
 
9
  # Load CSV data
10
  data = pd.read_csv('RBD10kstats.csv')
11
 
12
- # Convert embedding column from JSON string to numpy array
13
- data['embedding'] = data['embedding'].apply(lambda x: np.array(json.loads(x)))
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  # Initialize FAISS index
16
  dimension = len(data['embedding'][0])
 
6
  import torch
7
  import json
8
  import spaces
9
+
10
  # Load CSV data
11
  data = pd.read_csv('RBD10kstats.csv')
12
 
13
+ # Function to safely convert JSON strings to numpy arrays
14
+ def safe_json_loads(x):
15
+ try:
16
+ return np.array(json.loads(x))
17
+ except json.JSONDecodeError as e:
18
+ print(f"Error decoding JSON: {e}")
19
+ return np.array([]) # Return an empty array or handle it as appropriate
20
+
21
+ # Apply the safe_json_loads function to the embedding column
22
+ data['embedding'] = data['embedding'].apply(safe_json_loads)
23
+
24
+ # Filter out any rows with empty embeddings
25
+ data = data[data['embedding'].apply(lambda x: x.size > 0)]
26
 
27
  # Initialize FAISS index
28
  dimension = len(data['embedding'][0])