Update app.py
Browse files
app.py
CHANGED
@@ -37,12 +37,12 @@ def generate_displacement_map(image_a):
|
|
37 |
return displacement_map
|
38 |
|
39 |
# Function to warp and fit Image-B onto Image-A
|
40 |
-
def fit_and_warp_design(image_a, image_b,
|
41 |
displacement_map = generate_displacement_map(image_a)
|
42 |
|
43 |
# Extract bounding box coordinates
|
44 |
-
top_left = (int(
|
45 |
-
bottom_right = (int(
|
46 |
|
47 |
# Resize the design to fit within the specified bounding box
|
48 |
design_width = bottom_right[0] - top_left[0]
|
@@ -74,22 +74,25 @@ def fit_and_warp_design(image_a, image_b, design_bbox):
|
|
74 |
return final_image
|
75 |
|
76 |
# Gradio interface function
|
77 |
-
def process_images(image_a, image_b,
|
78 |
-
result = fit_and_warp_design(image_a, image_b,
|
79 |
return result
|
80 |
|
81 |
# Gradio UI components
|
82 |
image_input_a = gr.Image(label="Upload Clothing Image", type="pil")
|
83 |
image_input_b = gr.Image(label="Upload Design Image", type="pil")
|
84 |
-
|
|
|
|
|
|
|
85 |
|
86 |
# Define the Gradio interface
|
87 |
iface = gr.Interface(
|
88 |
fn=process_images,
|
89 |
-
inputs=[image_input_a, image_input_b,
|
90 |
outputs="image",
|
91 |
-
title="Clothing Design Fitting with
|
92 |
-
description="Upload a clothing image and a design image.
|
93 |
)
|
94 |
|
95 |
# Launch the interface
|
|
|
37 |
return displacement_map
|
38 |
|
39 |
# Function to warp and fit Image-B onto Image-A
|
40 |
+
def fit_and_warp_design(image_a, image_b, top_left_x, top_left_y, bottom_right_x, bottom_right_y):
|
41 |
displacement_map = generate_displacement_map(image_a)
|
42 |
|
43 |
# Extract bounding box coordinates
|
44 |
+
top_left = (int(top_left_x), int(top_left_y))
|
45 |
+
bottom_right = (int(bottom_right_x), int(bottom_right_y))
|
46 |
|
47 |
# Resize the design to fit within the specified bounding box
|
48 |
design_width = bottom_right[0] - top_left[0]
|
|
|
74 |
return final_image
|
75 |
|
76 |
# Gradio interface function
|
77 |
+
def process_images(image_a, image_b, top_left_x, top_left_y, bottom_right_x, bottom_right_y):
|
78 |
+
result = fit_and_warp_design(image_a, image_b, top_left_x, top_left_y, bottom_right_x, bottom_right_y)
|
79 |
return result
|
80 |
|
81 |
# Gradio UI components
|
82 |
image_input_a = gr.Image(label="Upload Clothing Image", type="pil")
|
83 |
image_input_b = gr.Image(label="Upload Design Image", type="pil")
|
84 |
+
top_left_x = gr.Slider(minimum=0, maximum=1000, label="Top-left X Coordinate", default=50)
|
85 |
+
top_left_y = gr.Slider(minimum=0, maximum=1000, label="Top-left Y Coordinate", default=100)
|
86 |
+
bottom_right_x = gr.Slider(minimum=0, maximum=1000, label="Bottom-right X Coordinate", default=300)
|
87 |
+
bottom_right_y = gr.Slider(minimum=0, maximum=1000, label="Bottom-right Y Coordinate", default=400)
|
88 |
|
89 |
# Define the Gradio interface
|
90 |
iface = gr.Interface(
|
91 |
fn=process_images,
|
92 |
+
inputs=[image_input_a, image_input_b, top_left_x, top_left_y, bottom_right_x, bottom_right_y],
|
93 |
outputs="image",
|
94 |
+
title="Clothing Design Fitting with Adjustable Bounding Box",
|
95 |
+
description="Upload a clothing image and a design image. Adjust the design's position and size using sliders to fit the design onto the clothing.",
|
96 |
)
|
97 |
|
98 |
# Launch the interface
|