budijuarto commited on
Commit
1f37d1f
·
verified ·
1 Parent(s): 7ddbe00

Restore chunked PyTorch models at startup

Browse files
Files changed (1) hide show
  1. app.py +15 -0
app.py CHANGED
@@ -11,6 +11,21 @@ from egg_damage.config import load_config
11
  from egg_damage.gradio_app import build_app
12
 
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  config = load_config(ROOT / "configs" / "space.yaml")
15
  demo = build_app(config)
16
 
 
11
  from egg_damage.gradio_app import build_app
12
 
13
 
14
+ def restore_chunked_model(filename: str) -> None:
15
+ target = ROOT / "models" / filename
16
+ parts_dir = ROOT / "models" / f"{filename}.parts"
17
+ if target.exists() or not parts_dir.exists():
18
+ return
19
+ part_paths = sorted(parts_dir.glob("*.part"))
20
+ if not part_paths:
21
+ return
22
+ with target.open("wb") as output:
23
+ for part_path in part_paths:
24
+ output.write(part_path.read_bytes())
25
+
26
+
27
+ restore_chunked_model("mobilenet_v3.pt")
28
+ restore_chunked_model("xception.pt")
29
  config = load_config(ROOT / "configs" / "space.yaml")
30
  demo = build_app(config)
31