Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -13,9 +13,7 @@ garm_list_path = [os.path.join(example_path, "cloth", garm) for garm in garm_lis
|
|
13 |
human_list = os.listdir(os.path.join(example_path, "human"))
|
14 |
human_list_path = [os.path.join(example_path, "human", human) for human in human_list]
|
15 |
|
16 |
-
def mock_tryon(person_img, garment_img, seed, randomize_seed
|
17 |
-
progress(0, desc="Starting mock try-on...")
|
18 |
-
|
19 |
if person_img is None or garment_img is None:
|
20 |
gr.Warning("Please upload both images!")
|
21 |
return None, None, "Error: Empty image"
|
@@ -23,76 +21,58 @@ def mock_tryon(person_img, garment_img, seed, randomize_seed, progress=gr.Progre
|
|
23 |
if randomize_seed:
|
24 |
seed = random.randint(0, MAX_SEED)
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
def load_description(fp):
|
44 |
-
with open(fp, 'r', encoding='utf-8') as f:
|
45 |
-
return f.read()
|
46 |
|
47 |
css = """
|
48 |
-
#col-left { margin: 0 auto; max-width: 430px; }
|
49 |
-
#col-mid { margin: 0 auto; max-width: 430px; }
|
50 |
-
#col-right { margin: 0 auto; max-width: 430px; }
|
51 |
#col-showcase { margin: 0 auto; max-width: 1100px; }
|
52 |
#button { color: blue; }
|
53 |
"""
|
54 |
|
55 |
-
with gr.Blocks(css=css) as
|
56 |
-
gr.
|
57 |
-
|
58 |
with gr.Row():
|
59 |
with gr.Column(elem_id="col-left"):
|
60 |
-
gr.
|
61 |
-
|
62 |
-
gr.Examples(
|
63 |
|
64 |
with gr.Column(elem_id="col-mid"):
|
65 |
-
gr.
|
66 |
-
|
67 |
-
gr.Examples(
|
68 |
|
69 |
with gr.Column(elem_id="col-right"):
|
70 |
-
gr.
|
71 |
-
|
72 |
with gr.Row():
|
73 |
-
seed = gr.Slider(
|
74 |
-
|
75 |
with gr.Row():
|
76 |
-
seed_used = gr.Number(label="Seed
|
77 |
-
|
78 |
-
|
79 |
|
80 |
-
|
81 |
fn=mock_tryon,
|
82 |
-
inputs=[
|
83 |
-
outputs=[
|
84 |
-
concurrency_limit=5
|
85 |
)
|
86 |
|
87 |
-
|
88 |
-
gr.HTML("<div style='text-align: center; font-size: 20px;'>Examples</div>")
|
89 |
-
gr.Examples(
|
90 |
-
examples=[
|
91 |
-
[human_list_path[0], garm_list_path[0]], # First human + first garment
|
92 |
-
[human_list_path[1], garm_list_path[1]], # Second pair
|
93 |
-
],
|
94 |
-
inputs=[imgs, garm_img],
|
95 |
-
outputs=[image_out]
|
96 |
-
)
|
97 |
-
|
98 |
-
Tryon.queue().launch()
|
|
|
13 |
human_list = os.listdir(os.path.join(example_path, "human"))
|
14 |
human_list_path = [os.path.join(example_path, "human", human) for human in human_list]
|
15 |
|
16 |
+
def mock_tryon(person_img, garment_img, seed, randomize_seed):
|
|
|
|
|
17 |
if person_img is None or garment_img is None:
|
18 |
gr.Warning("Please upload both images!")
|
19 |
return None, None, "Error: Empty image"
|
|
|
21 |
if randomize_seed:
|
22 |
seed = random.randint(0, MAX_SEED)
|
23 |
|
24 |
+
# Simple mock processing
|
25 |
+
try:
|
26 |
+
# Convert person to grayscale
|
27 |
+
person_gray = cv2.cvtColor(person_img, cv2.COLOR_RGB2GRAY)
|
28 |
+
person_gray = cv2.cvtColor(person_gray, cv2.COLOR_GRAY2RGB)
|
29 |
+
|
30 |
+
# Resize garment
|
31 |
+
garment_resized = cv2.resize(garment_img, (person_img.shape[1], person_img.shape[0]))
|
32 |
+
|
33 |
+
# Blend images
|
34 |
+
result = cv2.addWeighted(person_gray, 0.3, garment_resized, 0.7, 0)
|
35 |
+
|
36 |
+
return result, seed, "Mock try-on complete"
|
37 |
+
except Exception as e:
|
38 |
+
gr.Error(f"Processing error: {str(e)}")
|
39 |
+
return None, seed, f"Error: {str(e)}"
|
|
|
|
|
|
|
|
|
40 |
|
41 |
css = """
|
42 |
+
#col-left, #col-mid, #col-right { margin: 0 auto; max-width: 430px; }
|
|
|
|
|
43 |
#col-showcase { margin: 0 auto; max-width: 1100px; }
|
44 |
#button { color: blue; }
|
45 |
"""
|
46 |
|
47 |
+
with gr.Blocks(css=css) as app:
|
48 |
+
gr.Markdown("# Virtual Try-On Demo (Mock)")
|
49 |
+
|
50 |
with gr.Row():
|
51 |
with gr.Column(elem_id="col-left"):
|
52 |
+
gr.Markdown("### Step 1: Upload Person Image")
|
53 |
+
person_img = gr.Image(label="Person", type="numpy")
|
54 |
+
gr.Examples(examples=human_list_path, inputs=person_img)
|
55 |
|
56 |
with gr.Column(elem_id="col-mid"):
|
57 |
+
gr.Markdown("### Step 2: Upload Garment")
|
58 |
+
garment_img = gr.Image(label="Garment", type="numpy")
|
59 |
+
gr.Examples(examples=garm_list_path, inputs=garment_img)
|
60 |
|
61 |
with gr.Column(elem_id="col-right"):
|
62 |
+
gr.Markdown("### Step 3: Get Result")
|
63 |
+
output_img = gr.Image(label="Result")
|
64 |
with gr.Row():
|
65 |
+
seed = gr.Slider(0, MAX_SEED, label="Seed", value=0)
|
66 |
+
random_seed = gr.Checkbox(label="Random Seed", value=True)
|
67 |
with gr.Row():
|
68 |
+
seed_used = gr.Number(label="Seed Used")
|
69 |
+
status = gr.Textbox(label="Status")
|
70 |
+
run_btn = gr.Button("Run", variant="primary")
|
71 |
|
72 |
+
run_btn.click(
|
73 |
fn=mock_tryon,
|
74 |
+
inputs=[person_img, garment_img, seed, random_seed],
|
75 |
+
outputs=[output_img, seed_used, status]
|
|
|
76 |
)
|
77 |
|
78 |
+
app.launch(share=True) # Critical fix: Added share=True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|