NavyDevilDoc commited on
Commit
13a7929
·
verified ·
1 Parent(s): 9ea268c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -6
app.py CHANGED
@@ -17,7 +17,7 @@ META_FILE = "navy_metadata.pkl"
17
 
18
  st.set_page_config(page_title="Navy Policy Architect", layout="wide", page_icon="⚓")
19
 
20
- # --- CLOUD SYNC MANAGER (ROBUST) ---
21
  class SyncManager:
22
  """Handles downloading/uploading the Database & Index to Hugging Face"""
23
 
@@ -26,6 +26,7 @@ class SyncManager:
26
  if not HF_TOKEN: return []
27
  try:
28
  api = HfApi(token=HF_TOKEN)
 
29
  files = api.list_repo_files(repo_id=DATASET_REPO_ID, repo_type="dataset")
30
  dbs = [f for f in files if f.endswith(".db")]
31
  return dbs
@@ -38,20 +39,32 @@ class SyncManager:
38
  st.error("HF_TOKEN missing.")
39
  return False
40
  try:
41
- # FIX: Remove "if os.path.exists" check.
42
- # We ALWAYS let hf_hub_download check for updates/integrity.
43
  hf_hub_download(
44
  repo_id=DATASET_REPO_ID,
45
  filename=db_filename,
46
  local_dir=".",
47
  token=HF_TOKEN,
48
- force_download=False # It will only download if the cloud version is newer
 
49
  )
50
 
51
  # Download Index (Best effort)
52
  try:
53
- hf_hub_download(repo_id=DATASET_REPO_ID, filename=INDEX_FILE, local_dir=".", token=HF_TOKEN)
54
- hf_hub_download(repo_id=DATASET_REPO_ID, filename=META_FILE, local_dir=".", token=HF_TOKEN)
 
 
 
 
 
 
 
 
 
 
 
 
55
  except:
56
  pass
57
 
@@ -65,12 +78,15 @@ class SyncManager:
65
  if not HF_TOKEN: return
66
  api = HfApi(token=HF_TOKEN)
67
  try:
 
68
  api.upload_file(path_or_fileobj=db_filename, path_in_repo=db_filename, repo_id=DATASET_REPO_ID, repo_type="dataset")
69
  api.upload_file(path_or_fileobj=INDEX_FILE, path_in_repo=INDEX_FILE, repo_id=DATASET_REPO_ID, repo_type="dataset")
70
  api.upload_file(path_or_fileobj=META_FILE, path_in_repo=META_FILE, repo_id=DATASET_REPO_ID, repo_type="dataset")
71
  st.toast("Cloud Sync Complete!", icon="☁️")
72
  except Exception as e:
73
  st.error(f"Sync Error (Push): {e}")
 
 
74
  # --- SIDEBAR: KNOWLEDGE BASE SELECTOR ---
75
  with st.sidebar:
76
  st.header("🗄️ Knowledge Base")
 
17
 
18
  st.set_page_config(page_title="Navy Policy Architect", layout="wide", page_icon="⚓")
19
 
20
+ # --- CLOUD SYNC MANAGER (FIXED) ---
21
  class SyncManager:
22
  """Handles downloading/uploading the Database & Index to Hugging Face"""
23
 
 
26
  if not HF_TOKEN: return []
27
  try:
28
  api = HfApi(token=HF_TOKEN)
29
+ # This worked because we specified repo_type="dataset" here
30
  files = api.list_repo_files(repo_id=DATASET_REPO_ID, repo_type="dataset")
31
  dbs = [f for f in files if f.endswith(".db")]
32
  return dbs
 
39
  st.error("HF_TOKEN missing.")
40
  return False
41
  try:
42
+ # FIX: Added repo_type="dataset"
 
43
  hf_hub_download(
44
  repo_id=DATASET_REPO_ID,
45
  filename=db_filename,
46
  local_dir=".",
47
  token=HF_TOKEN,
48
+ repo_type="dataset", # <--- THE MISSING LINK
49
+ force_download=False
50
  )
51
 
52
  # Download Index (Best effort)
53
  try:
54
+ hf_hub_download(
55
+ repo_id=DATASET_REPO_ID,
56
+ filename=INDEX_FILE,
57
+ local_dir=".",
58
+ token=HF_TOKEN,
59
+ repo_type="dataset" # <--- Added here too
60
+ )
61
+ hf_hub_download(
62
+ repo_id=DATASET_REPO_ID,
63
+ filename=META_FILE,
64
+ local_dir=".",
65
+ token=HF_TOKEN,
66
+ repo_type="dataset" # <--- And here
67
+ )
68
  except:
69
  pass
70
 
 
78
  if not HF_TOKEN: return
79
  api = HfApi(token=HF_TOKEN)
80
  try:
81
+ # This was already working because we had repo_type="dataset"
82
  api.upload_file(path_or_fileobj=db_filename, path_in_repo=db_filename, repo_id=DATASET_REPO_ID, repo_type="dataset")
83
  api.upload_file(path_or_fileobj=INDEX_FILE, path_in_repo=INDEX_FILE, repo_id=DATASET_REPO_ID, repo_type="dataset")
84
  api.upload_file(path_or_fileobj=META_FILE, path_in_repo=META_FILE, repo_id=DATASET_REPO_ID, repo_type="dataset")
85
  st.toast("Cloud Sync Complete!", icon="☁️")
86
  except Exception as e:
87
  st.error(f"Sync Error (Push): {e}")
88
+
89
+
90
  # --- SIDEBAR: KNOWLEDGE BASE SELECTOR ---
91
  with st.sidebar:
92
  st.header("🗄️ Knowledge Base")