Jaimodiji commited on
Commit
cdd3652
·
1 Parent(s): 7a709ef

Upload hf_sync.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. hf_sync.py +30 -3
hf_sync.py CHANGED
@@ -1,12 +1,36 @@
1
  import os
2
  import sys
3
  import shutil
 
4
  from huggingface_hub import snapshot_download, HfApi
5
 
6
  # Configuration
7
  REPO_ID = os.environ.get("DATASET_REPO_ID")
8
  HF_TOKEN = os.environ.get("HF_TOKEN")
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  def download():
11
  if not REPO_ID:
12
  print("DATASET_REPO_ID not set, skipping download.")
@@ -23,6 +47,7 @@ def download():
23
  max_workers=8
24
  )
25
  print("Download successful.")
 
26
  except Exception as e:
27
  print(f"Download failed: {e}")
28
 
@@ -41,7 +66,7 @@ def upload():
41
  folder_path="data_repo",
42
  repo_id=REPO_ID,
43
  repo_type="dataset",
44
- # This handles large folders by committing in chunks if necessary
45
  )
46
  print("Upload successful.")
47
  except Exception as e:
@@ -55,7 +80,7 @@ def init_local():
55
 
56
  if __name__ == "__main__":
57
  if len(sys.argv) < 2:
58
- print("Usage: python hf_sync.py [download|upload|init]")
59
  sys.exit(1)
60
 
61
  action = sys.argv[1]
@@ -65,5 +90,7 @@ if __name__ == "__main__":
65
  upload()
66
  elif action == "init":
67
  init_local()
 
 
68
  else:
69
- print(f"Unknown action: {action}")
 
1
  import os
2
  import sys
3
  import shutil
4
+ import sqlite3
5
  from huggingface_hub import snapshot_download, HfApi
6
 
7
  # Configuration
8
  REPO_ID = os.environ.get("DATASET_REPO_ID")
9
  HF_TOKEN = os.environ.get("HF_TOKEN")
10
 
11
+ def verify_data():
12
+ db_path = "data_repo/database.db"
13
+ if not os.path.exists(db_path):
14
+ print(f"VERIFICATION FAILED: {db_path} does not exist.")
15
+ return False
16
+
17
+ try:
18
+ conn = sqlite3.connect(db_path)
19
+ cursor = conn.cursor()
20
+ cursor.execute("SELECT username FROM users WHERE username = ?", ("akshit",))
21
+ row = cursor.fetchone()
22
+ conn.close()
23
+
24
+ if row:
25
+ print("VERIFICATION SUCCESS: User 'akshit' found in database.")
26
+ return True
27
+ else:
28
+ print("VERIFICATION FAILED: User 'akshit' NOT found in database.")
29
+ return False
30
+ except Exception as e:
31
+ print(f"VERIFICATION ERROR: {e}")
32
+ return False
33
+
34
  def download():
35
  if not REPO_ID:
36
  print("DATASET_REPO_ID not set, skipping download.")
 
47
  max_workers=8
48
  )
49
  print("Download successful.")
50
+ verify_data()
51
  except Exception as e:
52
  print(f"Download failed: {e}")
53
 
 
66
  folder_path="data_repo",
67
  repo_id=REPO_ID,
68
  repo_type="dataset",
69
+ delete_patterns="*", # Optional: sync deletion if needed
70
  )
71
  print("Upload successful.")
72
  except Exception as e:
 
80
 
81
  if __name__ == "__main__":
82
  if len(sys.argv) < 2:
83
+ print("Usage: python hf_sync.py [download|upload|init|verify]")
84
  sys.exit(1)
85
 
86
  action = sys.argv[1]
 
90
  upload()
91
  elif action == "init":
92
  init_local()
93
+ elif action == "verify":
94
+ verify_data()
95
  else:
96
+ print(f"Unknown action: {action}")