Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -44,19 +44,6 @@ def load_models():
|
|
| 44 |
device='cuda'
|
| 45 |
)
|
| 46 |
|
| 47 |
-
# CRITICAL FIX: Disable NSFW filter
|
| 48 |
-
if hasattr(pipeline, 'safety_checker'):
|
| 49 |
-
pipeline.safety_checker = None
|
| 50 |
-
print("β
NSFW filter disabled", file=sys.stderr)
|
| 51 |
-
|
| 52 |
-
# Alternative: Replace safety checker with dummy function
|
| 53 |
-
# Alternative: Replace safety checker with dummy function
|
| 54 |
-
if hasattr(pipeline, 'run_safety_checker'):
|
| 55 |
-
def dummy_safety_checker(image, *args, **kwargs):
|
| 56 |
-
return image, False
|
| 57 |
-
pipeline.run_safety_checker = dummy_safety_checker
|
| 58 |
-
print("β
Safety checker replaced with dummy", file=sys.stderr)
|
| 59 |
-
|
| 60 |
automasker = AutoMasker(
|
| 61 |
densepose_ckpt=os.path.join(repo_path, "DensePose"),
|
| 62 |
schp_ckpt=os.path.join(repo_path, "SCHP"),
|
|
@@ -66,20 +53,21 @@ def load_models():
|
|
| 66 |
print("β
Models loaded!", file=sys.stderr)
|
| 67 |
|
| 68 |
except Exception as e:
|
| 69 |
-
print(f"β Error
|
| 70 |
traceback.print_exc()
|
| 71 |
raise
|
| 72 |
|
| 73 |
def generate_tryon(person_img, cloth_img):
|
| 74 |
-
"""Generate virtual try-on"""
|
| 75 |
-
|
| 76 |
print("="*50, file=sys.stderr)
|
| 77 |
-
print(f"
|
| 78 |
|
| 79 |
if person_img is None or cloth_img is None:
|
| 80 |
raise gr.Error("Both images required!")
|
| 81 |
|
| 82 |
try:
|
|
|
|
|
|
|
|
|
|
| 83 |
load_models()
|
| 84 |
|
| 85 |
target_height = 1024
|
|
@@ -90,7 +78,6 @@ def generate_tryon(person_img, cloth_img):
|
|
| 90 |
mask = automasker(person_img, "upper")['mask']
|
| 91 |
gc.collect()
|
| 92 |
|
| 93 |
-
print("Running pipeline...", file=sys.stderr)
|
| 94 |
result = pipeline(
|
| 95 |
image=person_img,
|
| 96 |
condition_image=cloth_img,
|
|
@@ -102,7 +89,7 @@ def generate_tryon(person_img, cloth_img):
|
|
| 102 |
width=target_width
|
| 103 |
)[0]
|
| 104 |
|
| 105 |
-
print(
|
| 106 |
return result
|
| 107 |
|
| 108 |
except Exception as e:
|
|
@@ -110,13 +97,14 @@ def generate_tryon(person_img, cloth_img):
|
|
| 110 |
traceback.print_exc()
|
| 111 |
raise gr.Error(str(e))
|
| 112 |
|
|
|
|
| 113 |
demo = gr.Interface(
|
| 114 |
fn=generate_tryon,
|
| 115 |
inputs=[
|
| 116 |
-
gr.Image(label="Person Image", type="pil"),
|
| 117 |
-
gr.Image(label="Garment Image", type="pil")
|
| 118 |
],
|
| 119 |
-
outputs=gr.Image(label="Result", type="pil"),
|
| 120 |
title="Try-Space Virtual Try-On",
|
| 121 |
description="Upload person and garment images. Processing takes 2-3 minutes on GPU T4.",
|
| 122 |
api_name="generate_tryon",
|
|
|
|
| 44 |
device='cuda'
|
| 45 |
)
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
automasker = AutoMasker(
|
| 48 |
densepose_ckpt=os.path.join(repo_path, "DensePose"),
|
| 49 |
schp_ckpt=os.path.join(repo_path, "SCHP"),
|
|
|
|
| 53 |
print("β
Models loaded!", file=sys.stderr)
|
| 54 |
|
| 55 |
except Exception as e:
|
| 56 |
+
print(f"β Error: {e}", file=sys.stderr)
|
| 57 |
traceback.print_exc()
|
| 58 |
raise
|
| 59 |
|
| 60 |
def generate_tryon(person_img, cloth_img):
|
|
|
|
|
|
|
| 61 |
print("="*50, file=sys.stderr)
|
| 62 |
+
print(f"Received - Person: {type(person_img)}, Cloth: {type(cloth_img)}", file=sys.stderr)
|
| 63 |
|
| 64 |
if person_img is None or cloth_img is None:
|
| 65 |
raise gr.Error("Both images required!")
|
| 66 |
|
| 67 |
try:
|
| 68 |
+
# person_img and cloth_img are already PIL Images, no conversion needed
|
| 69 |
+
print("Images received as PIL", file=sys.stderr)
|
| 70 |
+
|
| 71 |
load_models()
|
| 72 |
|
| 73 |
target_height = 1024
|
|
|
|
| 78 |
mask = automasker(person_img, "upper")['mask']
|
| 79 |
gc.collect()
|
| 80 |
|
|
|
|
| 81 |
result = pipeline(
|
| 82 |
image=person_img,
|
| 83 |
condition_image=cloth_img,
|
|
|
|
| 89 |
width=target_width
|
| 90 |
)[0]
|
| 91 |
|
| 92 |
+
print("β
Success!", file=sys.stderr)
|
| 93 |
return result
|
| 94 |
|
| 95 |
except Exception as e:
|
|
|
|
| 97 |
traceback.print_exc()
|
| 98 |
raise gr.Error(str(e))
|
| 99 |
|
| 100 |
+
# CRITICAL: Use gr.Interface instead of gr.Blocks for better API support
|
| 101 |
demo = gr.Interface(
|
| 102 |
fn=generate_tryon,
|
| 103 |
inputs=[
|
| 104 |
+
gr.Image(label="Person Image", type="pil"), # Changed from "filepath" to "pil"
|
| 105 |
+
gr.Image(label="Garment Image", type="pil") # Changed from "filepath" to "pil"
|
| 106 |
],
|
| 107 |
+
outputs=gr.Image(label="Result", type="pil"), # Changed from "filepath" to "pil"
|
| 108 |
title="Try-Space Virtual Try-On",
|
| 109 |
description="Upload person and garment images. Processing takes 2-3 minutes on GPU T4.",
|
| 110 |
api_name="generate_tryon",
|