Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +2 -2
- generator.py +39 -45
app.py
CHANGED
|
@@ -106,7 +106,7 @@ def get_model_status():
|
|
| 106 |
status_text += f"- Custom Checkpoint (Horizon): {'[OK] Loaded' if converter.models_loaded['custom_checkpoint'] else '[OK] Using SDXL base'}\n"
|
| 107 |
status_text += f"- LORA (RetroArt): {'[OK] Loaded' if converter.models_loaded['lora'] else ' Disabled'}\n"
|
| 108 |
status_text += f"- InstantID: {'[OK] Loaded' if converter.models_loaded['instantid'] else ' Disabled'}\n"
|
| 109 |
-
status_text += f"-
|
| 110 |
status_text += f"- IP-Adapter (Face Embeddings): {'[OK] Loaded' if converter.models_loaded.get('ip_adapter', False) else ' Keypoints only'}\n"
|
| 111 |
return status_text
|
| 112 |
return "**Model status unavailable**"
|
|
@@ -452,4 +452,4 @@ if __name__ == "__main__":
|
|
| 452 |
server_port=7860,
|
| 453 |
share=True,
|
| 454 |
show_api=True
|
| 455 |
-
)
|
|
|
|
| 106 |
status_text += f"- Custom Checkpoint (Horizon): {'[OK] Loaded' if converter.models_loaded['custom_checkpoint'] else '[OK] Using SDXL base'}\n"
|
| 107 |
status_text += f"- LORA (RetroArt): {'[OK] Loaded' if converter.models_loaded['lora'] else ' Disabled'}\n"
|
| 108 |
status_text += f"- InstantID: {'[OK] Loaded' if converter.models_loaded['instantid'] else ' Disabled'}\n"
|
| 109 |
+
status_text += f"- Depth: Grayscale (simple & reliable)\n"
|
| 110 |
status_text += f"- IP-Adapter (Face Embeddings): {'[OK] Loaded' if converter.models_loaded.get('ip_adapter', False) else ' Keypoints only'}\n"
|
| 111 |
return status_text
|
| 112 |
return "**Model status unavailable**"
|
|
|
|
| 452 |
server_port=7860,
|
| 453 |
share=True,
|
| 454 |
show_api=True
|
| 455 |
+
)
|
generator.py
CHANGED
|
@@ -40,9 +40,9 @@ class RetroArtConverter:
|
|
| 40 |
# Initialize face analysis
|
| 41 |
self.face_app, self.face_detection_enabled = load_face_analysis()
|
| 42 |
|
| 43 |
-
#
|
| 44 |
-
self.leres_depth
|
| 45 |
-
self.models_loaded['leres_depth'] =
|
| 46 |
|
| 47 |
# Load ControlNets
|
| 48 |
controlnet_depth, self.controlnet_instantid, instantid_success = load_controlnets()
|
|
@@ -151,37 +151,24 @@ class RetroArtConverter:
|
|
| 151 |
print("============================\n")
|
| 152 |
|
| 153 |
def get_depth_map(self, image):
|
| 154 |
-
"""Generate depth map using
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
else:
|
| 173 |
-
detect_image = image
|
| 174 |
-
|
| 175 |
-
# Generate depth map with Leres (better quality than Zoe)
|
| 176 |
-
with torch.no_grad():
|
| 177 |
-
depth_image = self.leres_depth(detect_image)
|
| 178 |
-
|
| 179 |
-
# Resize back to original dimensions
|
| 180 |
-
if depth_image.size != (orig_width, orig_height):
|
| 181 |
-
depth_image = depth_image.resize((orig_width, orig_height), Image.LANCZOS)
|
| 182 |
-
|
| 183 |
-
print(f"[DEPTH] Leres depth map generated: {orig_width}x{orig_height}")
|
| 184 |
-
return depth_image
|
| 185 |
|
| 186 |
except Exception as e:
|
| 187 |
print(f"[DEPTH] LeresDetector failed ({e}), falling back to grayscale depth")
|
|
@@ -466,7 +453,7 @@ class RetroArtConverter:
|
|
| 466 |
resized_image = input_image.resize((int(target_width), int(target_height)), Image.LANCZOS)
|
| 467 |
|
| 468 |
# Generate depth map
|
| 469 |
-
print("Generating
|
| 470 |
depth_image = self.get_depth_map(resized_image)
|
| 471 |
if depth_image.size != (target_width, target_height):
|
| 472 |
depth_image = depth_image.resize((int(target_width), int(target_height)), Image.LANCZOS)
|
|
@@ -547,17 +534,24 @@ class RetroArtConverter:
|
|
| 547 |
print(f"Face info: bbox={face.bbox}, age={age if age else 'N/A'}, gender={gender_str}")
|
| 548 |
print(f"Face crop size: {face_crop.size}, enhanced: {face_crop_enhanced.size if face_crop_enhanced else 'N/A'}")
|
| 549 |
|
| 550 |
-
# Set LORA scale
|
| 551 |
-
if hasattr(self.pipe, '
|
| 552 |
try:
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 561 |
|
| 562 |
except Exception as e:
|
| 563 |
print(f"[WARNING] LORA set_adapters failed: {e}")
|
|
|
|
| 40 |
# Initialize face analysis
|
| 41 |
self.face_app, self.face_detection_enabled = load_face_analysis()
|
| 42 |
|
| 43 |
+
# Skip depth detector - using grayscale conversion instead
|
| 44 |
+
self.leres_depth = None
|
| 45 |
+
self.models_loaded['leres_depth'] = False
|
| 46 |
|
| 47 |
# Load ControlNets
|
| 48 |
controlnet_depth, self.controlnet_instantid, instantid_success = load_controlnets()
|
|
|
|
| 151 |
print("============================\n")
|
| 152 |
|
| 153 |
def get_depth_map(self, image):
|
| 154 |
+
"""Generate depth map using grayscale conversion for reliability"""
|
| 155 |
+
try:
|
| 156 |
+
# Ensure RGB mode
|
| 157 |
+
if image.mode != 'RGB':
|
| 158 |
+
image = image.convert('RGB')
|
| 159 |
+
|
| 160 |
+
# Convert to grayscale for depth
|
| 161 |
+
gray = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2GRAY)
|
| 162 |
+
|
| 163 |
+
# Apply some enhancement to make depth more pronounced
|
| 164 |
+
gray = cv2.equalizeHist(gray)
|
| 165 |
+
|
| 166 |
+
# Convert back to RGB format (ControlNet expects RGB)
|
| 167 |
+
depth_colored = cv2.cvtColor(gray, cv2.COLOR_GRAY2RGB)
|
| 168 |
+
depth_image = Image.fromarray(depth_colored)
|
| 169 |
+
|
| 170 |
+
print(f"[DEPTH] Grayscale depth map generated: {image.size}")
|
| 171 |
+
return depth_image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
except Exception as e:
|
| 174 |
print(f"[DEPTH] LeresDetector failed ({e}), falling back to grayscale depth")
|
|
|
|
| 453 |
resized_image = input_image.resize((int(target_width), int(target_height)), Image.LANCZOS)
|
| 454 |
|
| 455 |
# Generate depth map
|
| 456 |
+
print("Generating grayscale depth map...")
|
| 457 |
depth_image = self.get_depth_map(resized_image)
|
| 458 |
if depth_image.size != (target_width, target_height):
|
| 459 |
depth_image = depth_image.resize((int(target_width), int(target_height)), Image.LANCZOS)
|
|
|
|
| 534 |
print(f"Face info: bbox={face.bbox}, age={age if age else 'N/A'}, gender={gender_str}")
|
| 535 |
print(f"Face crop size: {face_crop.size}, enhanced: {face_crop_enhanced.size if face_crop_enhanced else 'N/A'}")
|
| 536 |
|
| 537 |
+
# Set LORA scale - use fuse_lora for immediate effect
|
| 538 |
+
if hasattr(self.pipe, 'fuse_lora') and self.models_loaded['lora']:
|
| 539 |
try:
|
| 540 |
+
self.pipe.fuse_lora(lora_scale=lora_scale)
|
| 541 |
+
print(f"[LORA] Fused with scale: {lora_scale}")
|
| 542 |
+
except Exception as e:
|
| 543 |
+
print(f"[WARNING] LORA fuse failed: {e}")
|
| 544 |
+
# Try set_adapters as fallback
|
| 545 |
+
try:
|
| 546 |
+
for adapter_name in ["retroart", "default_0"]:
|
| 547 |
+
try:
|
| 548 |
+
self.pipe.set_adapters([adapter_name], adapter_weights=[lora_scale])
|
| 549 |
+
print(f"[LORA] Set adapter '{adapter_name}' with scale: {lora_scale}")
|
| 550 |
+
break
|
| 551 |
+
except:
|
| 552 |
+
continue
|
| 553 |
+
except Exception as e2:
|
| 554 |
+
print(f"[WARNING] LORA set_adapters also failed: {e2}")
|
| 555 |
|
| 556 |
except Exception as e:
|
| 557 |
print(f"[WARNING] LORA set_adapters failed: {e}")
|