Josh Brown Kramer commited on
Commit
43eb44b
·
1 Parent(s): 5ccbb0b

Put things back that cursor screwed up

Browse files
Files changed (2) hide show
  1. app.py +1 -1
  2. faceparsing.py +3 -18
app.py CHANGED
@@ -4,7 +4,7 @@ from huggingface_hub import hf_hub_download
4
  import onnxruntime as ort
5
  import numpy as np
6
  from PIL import Image
7
- #from faceparsing import get_face_mask
8
 
9
  # import torch
10
  # from your_pix2pixhd_code import YourPix2PixHDModel, load_image, tensor2im # Adapt these imports
 
4
  import onnxruntime as ort
5
  import numpy as np
6
  from PIL import Image
7
+ from faceparsing import get_face_mask
8
 
9
  # import torch
10
  # from your_pix2pixhd_code import YourPix2PixHDModel, load_image, tensor2im # Adapt these imports
faceparsing.py CHANGED
@@ -21,27 +21,12 @@ device = (
21
  else "cpu"
22
  )
23
 
24
- def load_face_parsing_models():
25
- """Load face parsing models lazily"""
26
- global image_processor, model
27
-
28
- if image_processor is None or model is None:
29
- try:
30
- print(f"Loading face parsing models on device: {device}")
31
- image_processor = SegformerImageProcessor.from_pretrained("jonathandinu/face-parsing")
32
- model = SegformerForSemanticSegmentation.from_pretrained("jonathandinu/face-parsing")
33
- model.to(device)
34
- print("Face parsing models loaded successfully")
35
- except Exception as e:
36
- print(f"Error loading face parsing models: {e}")
37
- return False
38
-
39
- return True
40
 
41
  def get_face_mask(image):
42
  # Load models if not already loaded
43
- if not load_face_parsing_models():
44
- return "Error: Failed to load face parsing models"
45
 
46
  try:
47
  # run inference on image
 
21
  else "cpu"
22
  )
23
 
24
+ image_processor = SegformerImageProcessor.from_pretrained("jonathandinu/face-parsing")
25
+ model = SegformerForSemanticSegmentation.from_pretrained("jonathandinu/face-parsing")
26
+ model.to(device)
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
  def get_face_mask(image):
29
  # Load models if not already loaded
 
 
30
 
31
  try:
32
  # run inference on image