primerz commited on
Commit
ee0b470
·
verified ·
1 Parent(s): 69f9498

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -11
app.py CHANGED
@@ -29,14 +29,22 @@ class RetroArtConverter:
29
  self.device = device
30
  self.dtype = dtype
31
 
32
- # Initialize face analysis for InstantID
33
  print("Loading face analysis model...")
34
- self.face_app = FaceAnalysis(
35
- name='antelopev2',
36
- root='./models/insightface',
37
- providers=['CUDAExecutionProvider', 'CPUExecutionProvider']
38
- )
39
- self.face_app.prepare(ctx_id=0, det_size=(640, 640))
 
 
 
 
 
 
 
 
40
 
41
  # Load ControlNet for depth
42
  print("Loading ControlNet depth model...")
@@ -151,9 +159,16 @@ class RetroArtConverter:
151
 
152
  def detect_faces(self, image):
153
  """Detect faces in the image using antelopev2"""
154
- img_array = np.array(image)
155
- faces = self.face_app.get(img_array)
156
- return faces
 
 
 
 
 
 
 
157
 
158
  def calculate_target_size(self, original_width, original_height, max_dimension=1024):
159
  """Calculate target size maintaining aspect ratio"""
@@ -350,4 +365,4 @@ if __name__ == "__main__":
350
  server_port=7860,
351
  share=False,
352
  show_api=True # Enable API
353
- )
 
29
  self.device = device
30
  self.dtype = dtype
31
 
32
+ # Initialize face analysis for InstantID (optional)
33
  print("Loading face analysis model...")
34
+ try:
35
+ self.face_app = FaceAnalysis(
36
+ name='antelopev2',
37
+ root='./models/insightface',
38
+ providers=['CUDAExecutionProvider', 'CPUExecutionProvider']
39
+ )
40
+ self.face_app.prepare(ctx_id=0, det_size=(640, 640))
41
+ print("✓ Face analysis model loaded successfully")
42
+ self.face_detection_enabled = True
43
+ except Exception as e:
44
+ print(f"⚠️ Face detection not available: {e}")
45
+ print("Continuing without face detection (will still work fine)")
46
+ self.face_app = None
47
+ self.face_detection_enabled = False
48
 
49
  # Load ControlNet for depth
50
  print("Loading ControlNet depth model...")
 
159
 
160
  def detect_faces(self, image):
161
  """Detect faces in the image using antelopev2"""
162
+ if not self.face_detection_enabled or self.face_app is None:
163
+ return []
164
+
165
+ try:
166
+ img_array = np.array(image)
167
+ faces = self.face_app.get(img_array)
168
+ return faces
169
+ except Exception as e:
170
+ print(f"Face detection error: {e}")
171
+ return []
172
 
173
  def calculate_target_size(self, original_width, original_height, max_dimension=1024):
174
  """Calculate target size maintaining aspect ratio"""
 
365
  server_port=7860,
366
  share=False,
367
  show_api=True # Enable API
368
+ )