Penality commited on
Commit
eadc267
·
verified ·
1 Parent(s): 9961d18

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -1
app.py CHANGED
@@ -58,13 +58,18 @@ def store_document_data(PDF_FILE):
58
  index = faiss.IndexFlatL2(embedding.shape[1])
59
  index.add(embedding) # Add embedding
60
  print(index, index.ntotal)
 
 
 
 
61
  index_file = "index.bin"
62
  faiss.write_index(index, index_file)
63
  doc_index = index.ntotal - 1
64
  with open(index_file, "rb") as f:
 
65
  response = requests.post(API_URL_EMBEDDINGS, files={"file": f})
66
 
67
- print("sent")
68
  except requests.exceptions.RequestException as e:
69
  return {"error": str(e)}
70
 
 
58
  index = faiss.IndexFlatL2(embedding.shape[1])
59
  index.add(embedding) # Add embedding
60
  print(index, index.ntotal)
61
+
62
+ if index.ntotal == 0:
63
+ raise ValueError("FAISS index is empty. No embeddings added.")
64
+
65
  index_file = "index.bin"
66
  faiss.write_index(index, index_file)
67
  doc_index = index.ntotal - 1
68
  with open(index_file, "rb") as f:
69
+ f.seek(0)
70
  response = requests.post(API_URL_EMBEDDINGS, files={"file": f})
71
 
72
+ print("sent", response.json())
73
  except requests.exceptions.RequestException as e:
74
  return {"error": str(e)}
75