sam-brause commited on
Commit
71e8593
·
1 Parent(s): 13bc754

Added Git LFS pull workaround

Browse files
Files changed (1) hide show
  1. handler.py +12 -63
handler.py CHANGED
@@ -1,13 +1,19 @@
 
 
1
  import torch
2
  import torchvision.transforms as transforms
3
  from PIL import Image
4
  import json
5
- import os
6
 
7
- # Load Model
8
  MODEL_PATH = "model_scripted_efficientnet.pt"
9
- device = "cuda" if torch.cuda.is_available() else "cpu"
10
 
 
 
 
 
 
 
11
  model = torch.jit.load(MODEL_PATH, map_location=device)
12
  model.eval()
13
 
@@ -18,64 +24,7 @@ transform = transforms.Compose([
18
  transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
19
  ])
20
 
21
- # Mappings
22
- issue_name_to_area_mapping = {
23
- "Forehead Wrinkles": "Skin",
24
- "Crow's Feet Wrinkles": "Skin",
25
- "Glabella Wrinkles": "Skin",
26
- "Under Eye Wrinkles": "Skin",
27
- "Perioral Wrinkles": "Skin",
28
- "Bunny Lines": "Skin",
29
- "Neck Lines": "Skin",
30
- "Dark Spots": "Skin",
31
- "Red Spots": "Skin",
32
- "Scars": "Skin",
33
- "Dry Skin": "Skin",
34
- "Whiteheads": "Skin",
35
- "Blackheads": "Skin",
36
- "Under Eye Dark Circles": "Skin",
37
- "Crepey Skin": "Skin",
38
- "Nasolabial Folds": "Skin",
39
- "Marionette Lines": "Skin",
40
- "Temporal Hollow": "Forehead",
41
- "Brow Asymmetry": "Forehead",
42
- "Flat Forehead": "Forehead",
43
- "Brow Ptosis": "Forehead",
44
- "Excess Upper Eyelid Skin": "Eyes",
45
- "Lower Eyelid - Excess Skin": "Eyes",
46
- "Upper Eyelid Droop": "Eyes",
47
- "Lower Eyelid Sag": "Eyes",
48
- "Lower Eyelid Bags": "Eyes",
49
- "Under Eye Hollow": "Eyes",
50
- "Upper Eye Hollow": "Eyes",
51
- "Mid Cheek Flattening": "Cheeks",
52
- "Cheekbone - Not Prominent": "Cheeks",
53
- "Heavy Lateral Cheek": "Cheeks",
54
- "Crooked Nose": "Nose",
55
- "Droopy Tip": "Nose",
56
- "Dorsal Hump": "Nose",
57
- "Tip Droop When Smiling": "Nose",
58
- "Thin Lips": "Lips",
59
- "Lacking Philtral Column": "Lips",
60
- "Long Philtral Column": "Lips",
61
- "Gummy Smile": "Lips",
62
- "Asymmetric Lips": "Lips",
63
- "Dry Lips": "Lips",
64
- "Lip Thinning When Smiling": "Lips",
65
- "Retruded Chin": "Jawline",
66
- "Over-Projected Chin": "Jawline",
67
- "Asymmetric Chin": "Jawline",
68
- "Jowls": "Jawline",
69
- "Lower Cheeks - Volume Depletion": "Jawline",
70
- "Ill-Defined Jawline": "Jawline",
71
- "Asymmetric Jawline": "Jawline",
72
- "Masseter Hypertrophy": "Jawline",
73
- "Prejowl Sulcus": "Jawline",
74
- "Loose Neck Skin": "Jawline",
75
- "Platysmal Bands": "Jawline",
76
- "Excess/Submental Fullness": "Jawline"
77
- }
78
-
79
  supported_issues = [
80
  "Dark Spots",
81
  "Dry Lips",
@@ -95,10 +44,10 @@ def predict(image_path):
95
 
96
  with torch.no_grad():
97
  outputs = model(image)
98
-
99
  predictions = outputs.squeeze().tolist()
100
  output_labels = [label for label, prob in zip(supported_issues, predictions) if prob > 0.5]
101
-
102
  return {"predictions": output_labels}
103
 
104
  # Hugging Face API Inference Handler
 
1
+ import os
2
+ import subprocess
3
  import torch
4
  import torchvision.transforms as transforms
5
  from PIL import Image
6
  import json
 
7
 
8
+ # Fetch model from Git LFS if not downloaded
9
  MODEL_PATH = "model_scripted_efficientnet.pt"
 
10
 
11
+ if not os.path.exists(MODEL_PATH):
12
+ print("Model file not found! Fetching from Git LFS...")
13
+ subprocess.run(["git", "lfs", "pull"], check=True)
14
+
15
+ # Load Model
16
+ device = "cuda" if torch.cuda.is_available() else "cpu"
17
  model = torch.jit.load(MODEL_PATH, map_location=device)
18
  model.eval()
19
 
 
24
  transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
25
  ])
26
 
27
+ # Supported labels
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  supported_issues = [
29
  "Dark Spots",
30
  "Dry Lips",
 
44
 
45
  with torch.no_grad():
46
  outputs = model(image)
47
+
48
  predictions = outputs.squeeze().tolist()
49
  output_labels = [label for label, prob in zip(supported_issues, predictions) if prob > 0.5]
50
+
51
  return {"predictions": output_labels}
52
 
53
  # Hugging Face API Inference Handler