AkashKumarave commited on
Commit
68c6e14
·
verified ·
1 Parent(s): 5cf294a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -17
app.py CHANGED
@@ -14,23 +14,13 @@ os.environ["HF_HUB_OFFLINE"] = "1"
14
  device = "cpu"
15
  dtype = torch.float32
16
 
17
- # Set up InsightFace model directory
18
- insightface_model_dir = "/home/user/.insightface/models/buffalo_l"
19
- os.makedirs(insightface_model_dir, exist_ok=True)
20
- buffalo_l_zip = "./buffalo_l.zip"
21
-
22
- # Check and extract buffalo_l.zip (runtime download removed due to network issues)
23
- if not os.path.exists(buffalo_l_zip):
24
- raise FileNotFoundError(f"buffalo_l.zip not found at {buffalo_l_zip}. Preloading failed. Please check .env configuration.")
25
- if os.path.exists(buffalo_l_zip):
26
- import zipfile
27
- with zipfile.ZipFile(buffalo_l_zip, "r") as zip_ref:
28
- zip_ref.extractall(insightface_model_dir)
29
- print("Extracted buffalo_l.zip.")
30
-
31
- # Load face encoder
32
- face_app = FaceAnalysis(providers=["CPUExecutionProvider"], root="/home/user/.insightface/models")
33
- face_app.prepare(ctx_id=0, det_size=(480, 480))
34
 
35
  # Define paths for preloaded weights
36
  model_path = "./unet/" # Adjusted for preloaded Kolors weights
 
14
  device = "cpu"
15
  dtype = torch.float32
16
 
17
+ # Load face encoder (InsightFace will download buffalo_l if needed)
18
+ try:
19
+ face_app = FaceAnalysis(providers=["CPUExecutionProvider"])
20
+ face_app.prepare(ctx_id=0, det_size=(480, 480))
21
+ print("InsightFace model loaded successfully.")
22
+ except Exception as e:
23
+ raise RuntimeError(f"Failed to load InsightFace model: {e}. Ensure network access for initial download.")
 
 
 
 
 
 
 
 
 
 
24
 
25
  # Define paths for preloaded weights
26
  model_path = "./unet/" # Adjusted for preloaded Kolors weights