FabIndy commited on
Commit
302d68d
·
1 Parent(s): 914170f

Download FAISS index at runtime (robust HF setup)

Browse files
Files changed (2) hide show
  1. .gitignore +4 -0
  2. app.py +28 -0
.gitignore CHANGED
@@ -19,3 +19,7 @@ models/*.gguf
19
 
20
  # OS
21
  .DS_Store
 
 
 
 
 
19
 
20
  # OS
21
  .DS_Store
22
+
23
+ #faiss et pkl
24
+ db/faiss_code_edu_by_article/index.faiss
25
+ db/faiss_code_edu_by_article/index.pkl
app.py CHANGED
@@ -9,6 +9,34 @@ import sys
9
  import traceback
10
  import gradio as gr
11
  from huggingface_hub import hf_hub_download
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
 
14
  def ensure_model_present():
 
9
  import traceback
10
  import gradio as gr
11
  from huggingface_hub import hf_hub_download
12
+ import os, shutil
13
+
14
+ def ensure_faiss_index_present():
15
+ base_dir = "db/faiss_code_edu_by_article"
16
+ os.makedirs(base_dir, exist_ok=True)
17
+
18
+ faiss_path = os.path.join(base_dir, "index.faiss")
19
+ pkl_path = os.path.join(base_dir, "index.pkl")
20
+
21
+ if os.path.exists(faiss_path) and os.path.exists(pkl_path):
22
+ return
23
+
24
+ repo_id = os.environ.get("INDEX_REPO_ID")
25
+ if not repo_id:
26
+ raise RuntimeError(
27
+ "INDEX_REPO_ID non défini (repo HF contenant l’index FAISS)."
28
+ )
29
+
30
+ token = os.environ.get("HF_TOKEN")
31
+
32
+ f_faiss = hf_hub_download(repo_id=repo_id, filename="index.faiss", token=token)
33
+ f_pkl = hf_hub_download(repo_id=repo_id, filename="index.pkl", token=token)
34
+
35
+ shutil.copyfile(f_faiss, faiss_path)
36
+ shutil.copyfile(f_pkl, pkl_path)
37
+
38
+ ensure_faiss_index_present()
39
+
40
 
41
 
42
  def ensure_model_present():