Spaces:
Sleeping
Sleeping
byeongjun-park
commited on
Commit
·
98975c0
1
Parent(s):
b785637
HarmonyView update
Browse files
app.py
CHANGED
@@ -80,7 +80,11 @@ def resize_inputs(original_image, sam_image, crop_size, background_removal):
|
|
80 |
results = add_margin(ref_img_, size=256)
|
81 |
return results
|
82 |
|
83 |
-
def generate(model,
|
|
|
|
|
|
|
|
|
84 |
if deployed:
|
85 |
assert isinstance(model, SyncMultiviewDiffusion)
|
86 |
seed=int(seed)
|
@@ -176,19 +180,20 @@ def run_demo():
|
|
176 |
|
177 |
# NOTE: Examples must match inputs
|
178 |
examples_full = [
|
179 |
-
['hf_demo/examples/monkey.png',30,200],
|
180 |
-
['hf_demo/examples/cat.png',30,200],
|
181 |
-
['hf_demo/examples/crab.png',30,200],
|
182 |
-
['hf_demo/examples/elephant.png',30,200],
|
183 |
-
['hf_demo/examples/flower.png',0,200],
|
184 |
-
['hf_demo/examples/forest.png',30,200],
|
185 |
-
['hf_demo/examples/teapot.png',20,200],
|
186 |
-
['hf_demo/examples/basket.png',30,200],
|
187 |
]
|
188 |
|
189 |
image_block = gr.Image(type='pil', image_mode='RGBA', height=256, label='Input image', tool=None, interactive=True)
|
190 |
elevation = gr.Slider(-10, 40, 30, step=5, label='Elevation angle of the input image', interactive=True)
|
191 |
crop_size = gr.Slider(120, 240, 200, step=10, label='Crop size', interactive=True)
|
|
|
192 |
|
193 |
# Compose demo layout & data flow.
|
194 |
with gr.Blocks(title=_TITLE, css="hf_demo/style.css") as demo:
|
@@ -202,8 +207,8 @@ def run_demo():
|
|
202 |
with gr.Column(scale=1.2):
|
203 |
gr.Examples(
|
204 |
examples=examples_full, # NOTE: elements must match inputs list!
|
205 |
-
inputs=[image_block, elevation, crop_size],
|
206 |
-
outputs=[image_block, elevation, crop_size],
|
207 |
cache_examples=False,
|
208 |
label='Examples (click one of the images below to start)',
|
209 |
examples_per_page=5,
|
@@ -224,8 +229,8 @@ def run_demo():
|
|
224 |
|
225 |
with gr.Column(scale=0.8):
|
226 |
input_block = gr.Image(type='pil', image_mode='RGBA', label="Input to HarmonyView", height=256, interactive=False)
|
227 |
-
|
228 |
-
|
229 |
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)
|
230 |
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)
|
231 |
seed = gr.Number(6033, label='Random seed', interactive=True)
|
@@ -233,17 +238,13 @@ def run_demo():
|
|
233 |
|
234 |
output_block = gr.Image(type='pil', image_mode='RGB', label="Outputs of HarmonyView", height=256, interactive=False)
|
235 |
|
236 |
-
|
237 |
image_block.change(fn=partial(sam_predict, mask_predictor, removal), inputs=[image_block], outputs=[sam_block], queue=True) \
|
238 |
.success(fn=resize_inputs, inputs=[image_block, sam_block, crop_size, background_removal], outputs=[input_block], queue=True)
|
239 |
|
240 |
background_removal.change(fn=resize_inputs, inputs=[image_block, sam_block, crop_size, background_removal], outputs=[input_block], queue=True)
|
241 |
crop_size.change(fn=resize_inputs, inputs=[image_block, sam_block, crop_size, background_removal], outputs=[input_block], queue=True)
|
242 |
|
243 |
-
|
244 |
-
sample_steps = 50
|
245 |
-
batch_view_num = 16
|
246 |
-
run_btn.click(partial(generate, model), inputs=[sample_steps, batch_view_num, sample_num, cfg_scale_1, cfg_scale_2, seed, input_block, elevation], outputs=[output_block], queue=True)
|
247 |
|
248 |
demo.queue().launch(share=False, max_threads=80) # auth=("admin", os.environ['PASSWD'])
|
249 |
|
|
|
80 |
results = add_margin(ref_img_, size=256)
|
81 |
return results
|
82 |
|
83 |
+
def generate(model, cfg_scale_1, cfg_scale_2, seed, image_input, elevation_input):
|
84 |
+
sample_num = 1
|
85 |
+
sample_steps = 50
|
86 |
+
batch_view_num = 16
|
87 |
+
|
88 |
if deployed:
|
89 |
assert isinstance(model, SyncMultiviewDiffusion)
|
90 |
seed=int(seed)
|
|
|
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.CheckboxGroup(["Original Image", "SAM Output"], value=["SAM Output"], label="Input to HarmonyView", info="Which image do you want for the input?")
|
197 |
|
198 |
# Compose demo layout & data flow.
|
199 |
with gr.Blocks(title=_TITLE, css="hf_demo/style.css") as demo:
|
|
|
207 |
with gr.Column(scale=1.2):
|
208 |
gr.Examples(
|
209 |
examples=examples_full, # NOTE: elements must match inputs list!
|
210 |
+
inputs=[image_block, elevation, crop_size, background_removal],
|
211 |
+
outputs=[image_block, elevation, crop_size, background_removal],
|
212 |
cache_examples=False,
|
213 |
label='Examples (click one of the images below to start)',
|
214 |
examples_per_page=5,
|
|
|
229 |
|
230 |
with gr.Column(scale=0.8):
|
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)
|
|
|
238 |
|
239 |
output_block = gr.Image(type='pil', image_mode='RGB', label="Outputs of HarmonyView", height=256, interactive=False)
|
240 |
|
|
|
241 |
image_block.change(fn=partial(sam_predict, mask_predictor, removal), inputs=[image_block], outputs=[sam_block], queue=True) \
|
242 |
.success(fn=resize_inputs, inputs=[image_block, sam_block, crop_size, background_removal], outputs=[input_block], queue=True)
|
243 |
|
244 |
background_removal.change(fn=resize_inputs, inputs=[image_block, sam_block, crop_size, background_removal], outputs=[input_block], queue=True)
|
245 |
crop_size.change(fn=resize_inputs, inputs=[image_block, sam_block, crop_size, background_removal], outputs=[input_block], queue=True)
|
246 |
|
247 |
+
run_btn.click(partial(generate, model), inputs=[cfg_scale_1, cfg_scale_2, seed, input_block, elevation], outputs=[output_block], queue=True)
|
|
|
|
|
|
|
248 |
|
249 |
demo.queue().launch(share=False, max_threads=80) # auth=("admin", os.environ['PASSWD'])
|
250 |
|