thechaiexperiment commited on
Commit
52b8a87
·
1 Parent(s): 7004832

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -37,19 +37,22 @@ def persistent_load(pers_id):
37
  raise HTTPException(status_code=500, detail=f"Unknown persistent ID: {pers_id}")
38
 
39
 
40
- # Function to load models
41
  def load_models():
42
  try:
43
- # Load embeddings data with custom persistent_load function
44
- with open("embeddings.pkl", "rb") as file:
45
- unpickler = pickle.Unpickler(file)
46
- unpickler.persistent_load = persistent_load
47
- global_models.embeddings_data = unpickler.load()
48
- print("Embeddings data loaded successfully.")
49
- except pickle.UnpicklingError as e:
50
- raise HTTPException(status_code=500, detail=f"Unpickling error: {e}")
 
 
 
51
  except Exception as e:
52
- raise HTTPException(status_code=500, detail=f"Failed to load models: {e}")
 
53
 
54
  app = FastAPI()
55
 
 
37
  raise HTTPException(status_code=500, detail=f"Unknown persistent ID: {pers_id}")
38
 
39
 
 
40
  def load_models():
41
  try:
42
+ with open('embeddings.pkl', 'rb') as f:
43
+ embeddings_data = pickle.load(f, encoding='latin1') # or 'bytes'
44
+
45
+ # If embeddings_data is a dictionary, check its content
46
+ if isinstance(embeddings_data, dict):
47
+ print("Loaded embeddings dictionary")
48
+
49
+ # Proceed with your logic using embeddings_data
50
+ # For example, assign to global models or something similar
51
+ global_models.embeddings_data = embeddings_data
52
+
53
  except Exception as e:
54
+ print(f"Error loading embeddings data: {e}")
55
+ raise HTTPException(status_code=500, detail="Failed to load embeddings data.")
56
 
57
  app = FastAPI()
58