byeongjun-park commited on
Commit
cc3abfa
1 Parent(s): 514b6ee

HarmonyView update

Browse files
Files changed (1) hide show
  1. app.py +14 -14
app.py CHANGED
@@ -24,14 +24,14 @@ Given a single-view image, HarmonyView is able to generate multiview-consistent
24
 
25
  Procedure: </br>
26
  **Step 1**. Upload an image or select an example. ==> The foreground is masked out by SAM and we crop it as inputs. </br>
27
- **Step 2**. Select "Elevation angle "and click "Run generation". ==> Generate multiview images. The **Elevation angle** is the elevation of the input image. (This costs about 45s.) </br>
28
  You may adjust the **Crop size** and **Elevation angle** to get a better result! <br>
29
  To reconstruct a NeRF or a 3D mesh from the generated images, please refer to our [github repository](https://github.com/byeongjun-park/HarmonyView). <br>
30
  We have heavily borrowed codes from [Syncdreamer](https://huggingface.co/spaces/liuyuan-pal/SyncDreamer), which is an our strong baseline.
31
  '''
32
  _USER_GUIDE0 = "Step1: Please upload an image in the block above (or choose an example shown in the left)."
33
  # _USER_GUIDE1 = "Step1: Please select a **Crop size** and click **Crop it**."
34
- _USER_GUIDE2 = "Step2: Please choose a **Elevation angle** and click **Run Generate**. The **Elevation angle** is the elevation of the input image. This costs about 45s."
35
  _USER_GUIDE3 = "Generated multiview images are shown below! (You may adjust the **Crop size** and **Elevation angle** to get a better result!)"
36
 
37
  others = '''**Step 1**. Select "Crop size" and click "Crop it". ==> The foreground object is centered and resized. </br>'''
@@ -66,7 +66,7 @@ class BackgroundRemoval:
66
  return image
67
 
68
  def resize_inputs(original_image, sam_image, crop_size, background_removal):
69
- image_input = original_image if background_removal == "Input Image" else sam_image
70
  if image_input is None: return None
71
  alpha_np = np.asarray(image_input)[:, :, 3]
72
  coords = np.stack(np.nonzero(alpha_np), 1)[:, (1, 0)]
@@ -180,20 +180,20 @@ def run_demo():
180
 
181
  # NOTE: Examples must match inputs
182
  examples_full = [
183
- ['hf_demo/examples/monkey.png',30,200,"SAM Output"],
184
- ['hf_demo/examples/cat.png',30,200,"SAM Output"],
185
- ['hf_demo/examples/crab.png',30,200,"SAM Output"],
186
- ['hf_demo/examples/elephant.png',30,200,"SAM Output"],
187
- ['hf_demo/examples/flower.png',0,200,"SAM Output"],
188
- ['hf_demo/examples/forest.png',30,200,"SAM Output"],
189
- ['hf_demo/examples/teapot.png',20,200,"SAM Output"],
190
- ['hf_demo/examples/basket.png',30,200,"SAM Output"],
191
  ]
192
 
193
  image_block = gr.Image(type='pil', image_mode='RGBA', height=256, label='Input image', tool=None, interactive=True)
194
- elevation = gr.Slider(-10, 40, 30, step=5, label='Elevation angle of the input image', interactive=True)
195
  crop_size = gr.Slider(120, 240, 200, step=10, label='Crop size', interactive=True)
196
- background_removal = gr.Radio(["Input Image", "SAM Output"], value=["SAM Output"], label="Input to HarmonyView", info="Which image do you want for the input to HarmonyView?")
197
 
198
  # Compose demo layout & data flow.
199
  with gr.Blocks(title=_TITLE, css="hf_demo/style.css") as demo:
@@ -231,7 +231,7 @@ def run_demo():
231
  input_block = gr.Image(type='pil', image_mode='RGBA', label="Input to HarmonyView", height=256, interactive=False)
232
  background_removal.render()
233
  with gr.Accordion('Advanced options', open=False):
234
- cfg_scale_1 = gr.Slider(1.0, 5.0, 2.0, step=0.1, label='Classifier free guidance 1', info='How consistent to be with the input image', interactive=True)
235
  cfg_scale_2 = gr.Slider(0.5, 1.5, 1.0, step=0.1, label='Classifier free guidance 2', info='How diverse a novel view to create', interactive=True)
236
  seed = gr.Number(6033, label='Random seed', interactive=True)
237
  run_btn = gr.Button('Run generation', variant='primary', interactive=True)
 
24
 
25
  Procedure: </br>
26
  **Step 1**. Upload an image or select an example. ==> The foreground is masked out by SAM and we crop it as inputs. </br>
27
+ **Step 2**. Select "Elevation angle "and click "Run generation". ==> Generate multiview images. The **Elevation angle** is the elevation of the Input image. (This costs about 45s.) </br>
28
  You may adjust the **Crop size** and **Elevation angle** to get a better result! <br>
29
  To reconstruct a NeRF or a 3D mesh from the generated images, please refer to our [github repository](https://github.com/byeongjun-park/HarmonyView). <br>
30
  We have heavily borrowed codes from [Syncdreamer](https://huggingface.co/spaces/liuyuan-pal/SyncDreamer), which is an our strong baseline.
31
  '''
32
  _USER_GUIDE0 = "Step1: Please upload an image in the block above (or choose an example shown in the left)."
33
  # _USER_GUIDE1 = "Step1: Please select a **Crop size** and click **Crop it**."
34
+ _USER_GUIDE2 = "Step2: Please choose a **Elevation angle** and click **Run Generate**. The **Elevation angle** is the elevation of the Input image. This costs about 45s."
35
  _USER_GUIDE3 = "Generated multiview images are shown below! (You may adjust the **Crop size** and **Elevation angle** to get a better result!)"
36
 
37
  others = '''**Step 1**. Select "Crop size" and click "Crop it". ==> The foreground object is centered and resized. </br>'''
 
66
  return image
67
 
68
  def resize_inputs(original_image, sam_image, crop_size, background_removal):
69
+ image_input = original_image if background_removal == "Input image" else sam_image
70
  if image_input is None: return None
71
  alpha_np = np.asarray(image_input)[:, :, 3]
72
  coords = np.stack(np.nonzero(alpha_np), 1)[:, (1, 0)]
 
180
 
181
  # NOTE: Examples must match inputs
182
  examples_full = [
183
+ ['hf_demo/examples/monkey.png',30,200,"SAM output"],
184
+ ['hf_demo/examples/cat.png',30,200,"SAM output"],
185
+ ['hf_demo/examples/crab.png',30,200,"SAM output"],
186
+ ['hf_demo/examples/elephant.png',30,200,"SAM output"],
187
+ ['hf_demo/examples/flower.png',0,200,"SAM output"],
188
+ ['hf_demo/examples/forest.png',30,200,"SAM output"],
189
+ ['hf_demo/examples/teapot.png',20,200,"SAM output"],
190
+ ['hf_demo/examples/basket.png',30,200,"SAM output"],
191
  ]
192
 
193
  image_block = gr.Image(type='pil', image_mode='RGBA', height=256, label='Input image', tool=None, interactive=True)
194
+ elevation = gr.Slider(-10, 40, 30, step=5, label='Elevation angle', interactive=True)
195
  crop_size = gr.Slider(120, 240, 200, step=10, label='Crop size', interactive=True)
196
+ background_removal = gr.Radio(["Input image", "SAM output"], value=["SAM output"], label="Input to HarmonyView", info="Which image do you want for the input to HarmonyView?")
197
 
198
  # Compose demo layout & data flow.
199
  with gr.Blocks(title=_TITLE, css="hf_demo/style.css") as demo:
 
231
  input_block = gr.Image(type='pil', image_mode='RGBA', label="Input to HarmonyView", height=256, interactive=False)
232
  background_removal.render()
233
  with gr.Accordion('Advanced options', open=False):
234
+ cfg_scale_1 = gr.Slider(1.0, 5.0, 2.0, step=0.1, label='Classifier free guidance 1', info='How consistent to be with the Input image', interactive=True)
235
  cfg_scale_2 = gr.Slider(0.5, 1.5, 1.0, step=0.1, label='Classifier free guidance 2', info='How diverse a novel view to create', interactive=True)
236
  seed = gr.Number(6033, label='Random seed', interactive=True)
237
  run_btn = gr.Button('Run generation', variant='primary', interactive=True)