sandrawang1031 commited on
Commit
726ebdf
1 Parent(s): 30e735a
app.py CHANGED
@@ -59,8 +59,8 @@ with image_blocks as demo:
59
  full_width=False,
60
  )
61
  with gr.Column():
62
- mask_image = gr.Image(label="Mask image", elem_id="mask-img", type="pil").style(height=400)
63
- image_out = gr.Image(label="Output", elem_id="output-img", type="pil").style(height=400)
64
 
65
  btn.click(fn=predict, inputs=[image, style, backyard_style, color_preference], outputs=[image_out, mask_image])
66
 
@@ -75,7 +75,11 @@ with image_blocks as demo:
75
  os.path.join(os.path.dirname(__file__),
76
  "examples/tips-for-decorating-a-beautiful-bedroom-1976169-hero-e960fbb8311c4b9b875a1813962d34eb.jpg"),
77
  os.path.join(os.path.dirname(__file__),
78
- "examples/backyard_additions.jpg")
 
 
 
 
79
  ],
80
  inputs=image
81
  )
 
59
  full_width=False,
60
  )
61
  with gr.Column():
62
+ mask_image = gr.Image(label="Mask image", elem_id="mask-img", type="pil").style(height=800)
63
+ image_out = gr.Image(label="Output", elem_id="output-img", type="pil").style(height=800)
64
 
65
  btn.click(fn=predict, inputs=[image, style, backyard_style, color_preference], outputs=[image_out, mask_image])
66
 
 
75
  os.path.join(os.path.dirname(__file__),
76
  "examples/tips-for-decorating-a-beautiful-bedroom-1976169-hero-e960fbb8311c4b9b875a1813962d34eb.jpg"),
77
  os.path.join(os.path.dirname(__file__),
78
+ "examples/backyard_additions.jpg"),
79
+ os.path.join(os.path.dirname(__file__),
80
+ "examples/living-room-gallery-shelves-l-shaped-couch-ELeyNpyyqpZ8hosOG3EG1X-b5a39646574544e8a75f2961332cd89a.jpg"),
81
+ os.path.join(os.path.dirname(__file__),
82
+ "examples/modern-dining-room-ideas-4147451-hero-d6333998f8b34620adfd4d99ac732586.jpg"),
83
  ],
84
  inputs=image
85
  )
examples/living-room-gallery-shelves-l-shaped-couch-ELeyNpyyqpZ8hosOG3EG1X-b5a39646574544e8a75f2961332cd89a.jpg ADDED
examples/modern-dining-room-ideas-4147451-hero-d6333998f8b34620adfd4d99ac732586.jpg ADDED
model.py CHANGED
@@ -27,9 +27,9 @@ class VirtualStagingToolV2():
27
 
28
  self.diffution_pipeline = StableDiffusionInpaintPipeline.from_pretrained(
29
  self.diffusion_version,
30
- torch_dtype=torch.float32,
31
  )
32
- self.diffution_pipeline = self.diffution_pipeline.to("cpu")
33
 
34
  def _predict(self, image):
35
  inputs = self.feature_extractor(images=image, return_tensors="pt")
@@ -94,6 +94,8 @@ class VirtualStagingToolV2():
94
  room = 'bedroom'
95
  elif 23 in label_ids or 49 in label_ids:
96
  room = 'living room'
 
 
97
 
98
  label_ids_without_mask = [i for i in label_ids if i not in mask_items]
99
 
@@ -116,30 +118,38 @@ class VirtualStagingToolV2():
116
  # display(output_image)
117
  return output_images
118
 
119
- def virtual_stage(self, image_path=None, image=None, style=None, color_preference=None, number_images=1):
 
120
  mask_image, transparent_mask_image, init_image, items, room = self.get_mask(image_path, image)
121
  if not style:
122
  raise ValueError('style not provided.')
123
- if color_preference:
124
- color_preference = f"in {color_preference}"
125
 
126
  if room == 'kitchen':
127
  items = [i for i in items if i in ['kitchen island', 'cabinet', 'shelf', 'counter', 'countertop', 'stool']]
128
  elif room == 'bedroom':
129
- items = [i for i in items if i in ['bed', 'table', 'chest of drawers', 'desk', 'armchair', 'wardrobe']]
130
  elif room == 'bathroom':
131
  items = [i for i in items if
132
  i in ['shower', 'bathtub', 'chest of drawers', 'counter', 'countertop', 'sink']]
133
- elif room == 'livingroom':
134
  items = [i for i in items if
135
  i in ['table', 'sofa', 'chest of drawers', 'armchair', 'cabinet', 'fireplace', 'coffee table']]
 
 
136
 
137
  items = ', '.join(items)
138
 
139
  if room == 'backyard':
140
- prompt = f'realistic, high resolution, {room} with {style}'
141
  else:
142
- prompt = f'realistic {items}, high resolution, in the {style} style {room} {color_preference}'
 
 
 
 
 
 
143
  print(prompt)
144
 
145
  output_images = self._edit_image(init_image, mask_image, prompt, number_images)
 
27
 
28
  self.diffution_pipeline = StableDiffusionInpaintPipeline.from_pretrained(
29
  self.diffusion_version,
30
+ torch_dtype=torch.float16,
31
  )
32
+ self.diffution_pipeline = self.diffution_pipeline.to("cuda")
33
 
34
  def _predict(self, image):
35
  inputs = self.feature_extractor(images=image, return_tensors="pt")
 
94
  room = 'bedroom'
95
  elif 23 in label_ids or 49 in label_ids:
96
  room = 'living room'
97
+ elif 15 in label_ids and 19 in label_ids:
98
+ room = 'dining room'
99
 
100
  label_ids_without_mask = [i for i in label_ids if i not in mask_items]
101
 
 
118
  # display(output_image)
119
  return output_images
120
 
121
+ def virtual_stage(self, image_path=None, image=None, style=None,
122
+ color_preference=None, additional_info=None, number_images=1):
123
  mask_image, transparent_mask_image, init_image, items, room = self.get_mask(image_path, image)
124
  if not style:
125
  raise ValueError('style not provided.')
126
+
 
127
 
128
  if room == 'kitchen':
129
  items = [i for i in items if i in ['kitchen island', 'cabinet', 'shelf', 'counter', 'countertop', 'stool']]
130
  elif room == 'bedroom':
131
+ items = [i for i in items if i in ['bed ', 'table', 'chest of drawers', 'desk', 'armchair', 'wardrobe']]
132
  elif room == 'bathroom':
133
  items = [i for i in items if
134
  i in ['shower', 'bathtub', 'chest of drawers', 'counter', 'countertop', 'sink']]
135
+ elif room == 'living room':
136
  items = [i for i in items if
137
  i in ['table', 'sofa', 'chest of drawers', 'armchair', 'cabinet', 'fireplace', 'coffee table']]
138
+ elif room == 'dining room':
139
+ items = [i for i in items if i in ['table', 'chair', 'cabinet']]
140
 
141
  items = ', '.join(items)
142
 
143
  if room == 'backyard':
144
+ prompt = f'Realistic, high resolution, {room} with {style}'
145
  else:
146
+ prompt = f'Realistic {items}, high resolution, in the {style} style {room}'
147
+
148
+ if color_preference:
149
+ prompt = f"{prompt} in {color_preference}"
150
+
151
+ if additional_info:
152
+ prompt = f'{prompt}. {additional_info}'
153
  print(prompt)
154
 
155
  output_images = self._edit_image(init_image, mask_image, prompt, number_images)