gaur3009 commited on
Commit
ffe5741
·
verified ·
1 Parent(s): 6a91eb0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
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, design_bbox):
41
  displacement_map = generate_displacement_map(image_a)
42
 
43
  # Extract bounding box coordinates
44
- top_left = (int(design_bbox[0]), int(design_bbox[1]))
45
- bottom_right = (int(design_bbox[2]), int(design_bbox[3]))
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, design_bbox):
78
- result = fit_and_warp_design(image_a, image_b, design_bbox)
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
- design_bbox_input = gr.Image(label="Adjust Design Position and Size", type="pil")
 
 
 
85
 
86
  # Define the Gradio interface
87
  iface = gr.Interface(
88
  fn=process_images,
89
- inputs=[image_input_a, image_input_b, design_bbox_input],
90
  outputs="image",
91
- title="Clothing Design Fitting with Drag-and-Drop",
92
- description="Upload a clothing image and a design image. Drag and resize the design onto the clothing using the cursor.",
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