roberto ceraolo commited on
Commit
9f97eaa
1 Parent(s): 83a81f1

faiss handling

Browse files
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -3,6 +3,7 @@ import os
3
  import faiss
4
  import numpy as np
5
  from pathlib import Path
 
6
 
7
  # Constants
8
  DATA_DIR = "data"
@@ -20,9 +21,8 @@ def save_index(file_obj):
20
  return "⚠️ A FAISS index already exists in the data directory. Please remove it first."
21
 
22
  try:
23
- # Save the uploaded file
24
- with open(INDEX_PATH, 'wb') as f:
25
- f.write(file_obj)
26
 
27
  # Verify the saved file is a valid FAISS index
28
  faiss.read_index(INDEX_PATH)
@@ -41,6 +41,7 @@ demo = gr.Interface(
41
  outputs=gr.Textbox(label="Status"),
42
  title="FAISS Index Uploader",
43
  description="Upload a FAISS index file to store in the HuggingFace Space data directory.",
 
44
  )
45
 
46
  if __name__ == "__main__":
 
3
  import faiss
4
  import numpy as np
5
  from pathlib import Path
6
+ import shutil
7
 
8
  # Constants
9
  DATA_DIR = "data"
 
21
  return "⚠️ A FAISS index already exists in the data directory. Please remove it first."
22
 
23
  try:
24
+ # Copy the temporary file to our target location
25
+ shutil.copy2(file_obj.name, INDEX_PATH)
 
26
 
27
  # Verify the saved file is a valid FAISS index
28
  faiss.read_index(INDEX_PATH)
 
41
  outputs=gr.Textbox(label="Status"),
42
  title="FAISS Index Uploader",
43
  description="Upload a FAISS index file to store in the HuggingFace Space data directory.",
44
+ allow_flagging="never"
45
  )
46
 
47
  if __name__ == "__main__":