sandrawang1031 commited on
Commit
30e735a
1 Parent(s): 95b7555

add backyard

Browse files
Files changed (3) hide show
  1. app.py +32 -13
  2. examples/backyard_additions.jpg +0 -0
  3. model.py +10 -3
app.py CHANGED
@@ -4,13 +4,17 @@ import os
4
  from model import VirtualStagingToolV2
5
 
6
 
7
- def predict(image, style, color_preference):
8
  init_image = image.convert("RGB").resize((512, 512))
9
 
10
  vs_tool = VirtualStagingToolV2(diffusion_version="stabilityai/stable-diffusion-2-inpainting")
 
 
 
11
  output_images, transparent_mask_image = vs_tool.virtual_stage(
12
  image=init_image, style=style, color_preference=color_preference, number_images=1)
13
- return output_images[0], transparent_mask_image, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
 
14
 
15
 
16
  image_blocks = gr.Blocks()
@@ -31,21 +35,34 @@ with image_blocks as demo:
31
  ["Bohemian", "Coastal", "Contemporary", "Farmhouse", "French country",
32
  "Glam", "Industrial", "Japandi", "Mid-century modern", "Minimal", "Modern",
33
  "Rustic", "Scandinavian", "Traditional", "Transitional", ],
34
- label="Design theme", elem_id="input-style"
 
35
  )
36
 
37
- color_preference = gr.Textbox(placeholder='Enter color preference',
38
- label="Color preference", elem_id="input-color")
39
- btn = gr.Button("Inpaint!").style(
40
- margin=False,
41
- rounded=(False, True, True, False),
42
- full_width=False,
 
 
 
 
43
  )
 
 
 
 
 
 
 
 
44
  with gr.Column():
45
- mask_image = gr.Image(label="Mask image", elem_id="mask-img").style(height=400)
46
- image_out = gr.Image(label="Output", elem_id="output-img").style(height=400)
47
 
48
- btn.click(fn=predict, inputs=[image, style, color_preference], outputs=[image_out, mask_image])
49
 
50
  gr.Markdown("## Image Examples")
51
  gr.Examples(
@@ -56,7 +73,9 @@ with image_blocks as demo:
56
  os.path.join(os.path.dirname(__file__),
57
  "examples/oct-2019-idh-bathroom-reno-ideas-new-gallery-2.jpg"),
58
  os.path.join(os.path.dirname(__file__),
59
- "examples/tips-for-decorating-a-beautiful-bedroom-1976169-hero-e960fbb8311c4b9b875a1813962d34eb.jpg")
 
 
60
  ],
61
  inputs=image
62
  )
 
4
  from model import VirtualStagingToolV2
5
 
6
 
7
+ def predict(image, style, backyard_style, color_preference):
8
  init_image = image.convert("RGB").resize((512, 512))
9
 
10
  vs_tool = VirtualStagingToolV2(diffusion_version="stabilityai/stable-diffusion-2-inpainting")
11
+ if backyard_style:
12
+ style = backyard_style
13
+
14
  output_images, transparent_mask_image = vs_tool.virtual_stage(
15
  image=init_image, style=style, color_preference=color_preference, number_images=1)
16
+
17
+ return output_images[0], transparent_mask_image
18
 
19
 
20
  image_blocks = gr.Blocks()
 
35
  ["Bohemian", "Coastal", "Contemporary", "Farmhouse", "French country",
36
  "Glam", "Industrial", "Japandi", "Mid-century modern", "Minimal", "Modern",
37
  "Rustic", "Scandinavian", "Traditional", "Transitional", ],
38
+ label="Design theme", elem_id="input-style",
39
+ info="only select if the image is NOT a backyard"
40
  )
41
 
42
+ backyard_style = gr.Dropdown(
43
+ ["Beautiful garden", "Charming playhouse garden landscaping",
44
+ "Cottage garden's colorful planting palette", "Cozy corner with fire pit and seating",
45
+ "Garden landscaping with gravel landscaping", "Hip california garden landscaping",
46
+ "Lush green lawn", "Mediterranean garden landscaping",
47
+ "Moss garden", "Outdoor dining and sitting area",
48
+ "Party-ready outdoor space with pool, spa, and fire feature",
49
+ "Resort-style landscaping and pool", "Round swimming pool with lawn and pool house"],
50
+ label="Backyard design theme", elem_id="input-backyard-style",
51
+ info="only select if the image is a backyard"
52
  )
53
+
54
+ color_preference = gr.Textbox(placeholder='Enter color preference',
55
+ label="Color preference", elem_id="input-color")
56
+ btn = gr.Button("Inpaint!").style(
57
+ margin=False,
58
+ rounded=(False, True, True, False),
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
 
67
  gr.Markdown("## Image Examples")
68
  gr.Examples(
 
73
  os.path.join(os.path.dirname(__file__),
74
  "examples/oct-2019-idh-bathroom-reno-ideas-new-gallery-2.jpg"),
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
  )
examples/backyard_additions.jpg ADDED
model.py CHANGED
@@ -120,8 +120,8 @@ class VirtualStagingToolV2():
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 not color_preference:
124
- raise ValueError('color_preference not provided.')
125
 
126
  if room == 'kitchen':
127
  items = [i for i in items if i in ['kitchen island', 'cabinet', 'shelf', 'counter', 'countertop', 'stool']]
@@ -130,9 +130,16 @@ class VirtualStagingToolV2():
130
  elif room == 'bathroom':
131
  items = [i for i in items if
132
  i in ['shower', 'bathtub', 'chest of drawers', 'counter', 'countertop', 'sink']]
 
 
 
133
 
134
  items = ', '.join(items)
135
- prompt = f'{items}, high resolution, in the {style} style {room} in {color_preference}'
 
 
 
 
136
  print(prompt)
137
 
138
  output_images = self._edit_image(init_image, mask_image, prompt, number_images)
 
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']]
 
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)