girish00 commited on
Commit
89a3adc
·
verified ·
1 Parent(s): 48ea9da

make project runnable and endpoint-ready

Browse files
Files changed (1) hide show
  1. upload_to_hf.py +34 -9
upload_to_hf.py CHANGED
@@ -1,14 +1,29 @@
1
- import argparse
2
- import os
3
- from huggingface_hub import upload_folder
 
 
 
 
 
 
 
 
 
 
4
 
5
 
6
  def main():
7
  parser = argparse.ArgumentParser()
8
- parser.add_argument("--force", action="store_true")
9
- parser.add_argument("--model-dir", type=str, default="./model")
10
- parser.add_argument("--repo-id", type=str, required=True)
11
- args = parser.parse_args()
 
 
 
 
 
12
 
13
  if not os.path.exists(args.model_dir):
14
  raise FileNotFoundError(
@@ -20,9 +35,19 @@ def main():
20
  repo_id=args.repo_id,
21
  repo_type="model",
22
  commit_message="update model",
23
- ignore_patterns=[] # ensures upload always checks properly
24
  )
25
- print(f"Uploaded model to: {args.repo_id}")
 
 
 
 
 
 
 
 
 
 
26
 
27
 
28
  if __name__ == "__main__":
 
1
+ import argparse
2
+ import os
3
+ from huggingface_hub import upload_file, upload_folder
4
+
5
+
6
+ PROJECT_FILES = [
7
+ "handler.py",
8
+ "infer_local.py",
9
+ "infer_cloud.py",
10
+ "requirements.txt",
11
+ "README.md",
12
+ "IMPLEMENTATION.md",
13
+ ]
14
 
15
 
16
  def main():
17
  parser = argparse.ArgumentParser()
18
+ parser.add_argument("--force", action="store_true")
19
+ parser.add_argument("--model-dir", type=str, default="./model")
20
+ parser.add_argument("--repo-id", type=str, required=True)
21
+ parser.add_argument(
22
+ "--model-only",
23
+ action="store_true",
24
+ help="Upload only model artifacts and skip endpoint/helper project files.",
25
+ )
26
+ args = parser.parse_args()
27
 
28
  if not os.path.exists(args.model_dir):
29
  raise FileNotFoundError(
 
35
  repo_id=args.repo_id,
36
  repo_type="model",
37
  commit_message="update model",
38
+ ignore_patterns=["checkpoint-*"] if not args.force else [],
39
  )
40
+ if not args.model_only:
41
+ for path in PROJECT_FILES:
42
+ if os.path.exists(path):
43
+ upload_file(
44
+ path_or_fileobj=path,
45
+ path_in_repo=path,
46
+ repo_id=args.repo_id,
47
+ repo_type="model",
48
+ commit_message="update endpoint helper files",
49
+ )
50
+ print(f"Uploaded model to: {args.repo_id}")
51
 
52
 
53
  if __name__ == "__main__":