florendrian commited on
Commit
4cd23fe
·
verified ·
1 Parent(s): c3cd32f

Update app.py Added Make3d with API Endpoint to upload iamges

Browse files
Files changed (1) hide show
  1. app.py +68 -30
app.py CHANGED
@@ -180,6 +180,8 @@ model = model.to(device)
180
 
181
  print('Loading Finished!')
182
 
 
 
183
 
184
  def check_input_image(input_image):
185
  if input_image is None:
@@ -332,6 +334,7 @@ If you have any questions, feel free to open a discussion or contact us at <b>bl
332
 
333
  with gr.Blocks() as demo:
334
  gr.Markdown(_HEADER_)
 
335
  with gr.Row(variant="panel"):
336
  with gr.Column():
337
  with gr.Row():
@@ -339,46 +342,55 @@ with gr.Blocks() as demo:
339
  label="Input Image",
340
  image_mode="RGBA",
341
  sources="upload",
342
- #width=256,
343
- #height=256,
344
  type="pil",
345
  elem_id="content_image",
346
  )
 
347
  processed_image = gr.Image(
348
- label="Processed Image",
349
- image_mode="RGBA",
350
- #width=256,
351
- #height=256,
352
- type="pil",
353
- interactive=False
354
  )
 
355
  with gr.Row():
356
  with gr.Group():
357
  do_remove_background = gr.Checkbox(
358
- label="Remove Background", value=True
 
 
 
 
 
 
 
359
  )
360
- sample_seed = gr.Number(value=42, label="Seed Value", precision=0)
361
 
362
  sample_steps = gr.Slider(
363
  label="Sample Steps",
364
  minimum=30,
365
  maximum=75,
366
  value=75,
367
- step=5
368
  )
369
 
370
  with gr.Row():
371
- submit = gr.Button("Generate", elem_id="generate", variant="primary")
 
 
 
 
372
 
373
  with gr.Row(variant="panel"):
374
  gr.Examples(
375
  examples=[
376
- os.path.join("examples", img_name) for img_name in sorted(os.listdir("examples"))
 
377
  ],
378
  inputs=[input_image],
379
  label="Examples",
380
  cache_examples=False,
381
- examples_per_page=16
382
  )
383
 
384
  with gr.Column():
@@ -390,51 +402,77 @@ with gr.Blocks() as demo:
390
  label="Generated Multi-views",
391
  type="pil",
392
  width=379,
393
- interactive=False
394
  )
395
 
396
- # with gr.Column():
397
- # output_video = gr.Video(
398
- # label="video", format="mp4",
399
- # width=379,
400
- # autoplay=True,
401
- # interactive=False
402
- # )
403
-
404
  with gr.Row():
405
  with gr.Tab("OBJ"):
406
  output_model_obj = gr.Model3D(
407
  label="Output Model (OBJ Format)",
408
  interactive=False,
409
  )
410
- gr.Markdown("Note: Downloaded .obj model will be flipped. Export .glb instead or manually flip it before usage.")
 
 
 
 
411
  with gr.Tab("GLB"):
412
  output_model_glb = gr.Model3D(
413
  label="Output Model (GLB Format)",
414
  interactive=False,
415
  )
416
- gr.Markdown("Note: The model shown here has a darker appearance. Download to get correct results.")
 
 
 
417
 
418
  with gr.Row():
419
- gr.Markdown('''Try a different <b>seed value</b> if the result is unsatisfying (Default: 42).''')
 
 
420
 
421
  gr.Markdown(_CITE_)
422
 
423
  mv_images = gr.State()
424
 
425
- submit.click(fn=check_input_image, inputs=[input_image]).success(
 
 
 
 
 
 
426
  fn=preprocess,
427
  inputs=[input_image, do_remove_background],
428
  outputs=[processed_image],
429
  ).success(
430
  fn=generate_mvs,
431
  inputs=[processed_image, sample_steps, sample_seed],
432
- outputs=[mv_images, mv_show_images]
433
-
434
  ).success(
435
  fn=make3d,
436
  inputs=[mv_images],
437
- outputs=[output_model_obj, output_model_glb]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
438
  )
439
 
440
  demo.launch()
 
180
 
181
  print('Loading Finished!')
182
 
183
+ def generate_mesh_from_mvs(mvs):
184
+ return make3d(mvs)
185
 
186
  def check_input_image(input_image):
187
  if input_image is None:
 
334
 
335
  with gr.Blocks() as demo:
336
  gr.Markdown(_HEADER_)
337
+
338
  with gr.Row(variant="panel"):
339
  with gr.Column():
340
  with gr.Row():
 
342
  label="Input Image",
343
  image_mode="RGBA",
344
  sources="upload",
 
 
345
  type="pil",
346
  elem_id="content_image",
347
  )
348
+
349
  processed_image = gr.Image(
350
+ label="Processed Image",
351
+ image_mode="RGBA",
352
+ type="pil",
353
+ interactive=False,
 
 
354
  )
355
+
356
  with gr.Row():
357
  with gr.Group():
358
  do_remove_background = gr.Checkbox(
359
+ label="Remove Background",
360
+ value=True,
361
+ )
362
+
363
+ sample_seed = gr.Number(
364
+ value=42,
365
+ label="Seed Value",
366
+ precision=0,
367
  )
 
368
 
369
  sample_steps = gr.Slider(
370
  label="Sample Steps",
371
  minimum=30,
372
  maximum=75,
373
  value=75,
374
+ step=5,
375
  )
376
 
377
  with gr.Row():
378
+ submit = gr.Button(
379
+ "Generate",
380
+ elem_id="generate",
381
+ variant="primary",
382
+ )
383
 
384
  with gr.Row(variant="panel"):
385
  gr.Examples(
386
  examples=[
387
+ os.path.join("examples", img_name)
388
+ for img_name in sorted(os.listdir("examples"))
389
  ],
390
  inputs=[input_image],
391
  label="Examples",
392
  cache_examples=False,
393
+ examples_per_page=16,
394
  )
395
 
396
  with gr.Column():
 
402
  label="Generated Multi-views",
403
  type="pil",
404
  width=379,
405
+ interactive=False,
406
  )
407
 
 
 
 
 
 
 
 
 
408
  with gr.Row():
409
  with gr.Tab("OBJ"):
410
  output_model_obj = gr.Model3D(
411
  label="Output Model (OBJ Format)",
412
  interactive=False,
413
  )
414
+
415
+ gr.Markdown(
416
+ "Note: Downloaded .obj model will be flipped. Export .glb instead or manually flip it before usage."
417
+ )
418
+
419
  with gr.Tab("GLB"):
420
  output_model_glb = gr.Model3D(
421
  label="Output Model (GLB Format)",
422
  interactive=False,
423
  )
424
+
425
+ gr.Markdown(
426
+ "Note: The model shown here has a darker appearance. Download to get correct results."
427
+ )
428
 
429
  with gr.Row():
430
+ gr.Markdown(
431
+ "Try a different <b>seed value</b> if the result is unsatisfying (Default: 42)."
432
+ )
433
 
434
  gr.Markdown(_CITE_)
435
 
436
  mv_images = gr.State()
437
 
438
+ # -----------------------------
439
+ # Standard Workflow
440
+ # -----------------------------
441
+ submit.click(
442
+ fn=check_input_image,
443
+ inputs=[input_image],
444
+ ).success(
445
  fn=preprocess,
446
  inputs=[input_image, do_remove_background],
447
  outputs=[processed_image],
448
  ).success(
449
  fn=generate_mvs,
450
  inputs=[processed_image, sample_steps, sample_seed],
451
+ outputs=[mv_images, mv_show_images],
 
452
  ).success(
453
  fn=make3d,
454
  inputs=[mv_images],
455
+ outputs=[output_model_obj, output_model_glb],
456
+ api_name="generate_mesh",
457
+ )
458
+
459
+ # -----------------------------
460
+ # API: fertiges MVS -> Mesh
461
+ # -----------------------------
462
+ mvs_input = gr.Image(
463
+ type="pil",
464
+ visible=False,
465
+ )
466
+
467
+ api_btn = gr.Button(
468
+ visible=False,
469
+ )
470
+
471
+ api_btn.click(
472
+ fn=make3d,
473
+ inputs=[mvs_input],
474
+ outputs=[output_model_obj, output_model_glb],
475
+ api_name="make3d_from_mvs",
476
  )
477
 
478
  demo.launch()