Steven18 commited on
Commit
ab26631
·
1 Parent(s): f0c50fc

add quick_generate_gs

Browse files
Files changed (1) hide show
  1. app.py +66 -18
app.py CHANGED
@@ -294,12 +294,33 @@ def quick_generate_glb(
294
  )
295
  return extract_glb(state, mesh_simplify=mesh_simplify, texture_size=texture_size, req=req)
296
 
297
- @spaces.GPU(api_name="quick_glb_dl")
298
- def quick_glb_dl(image: Image.Image, req: gr.Request) -> str:
299
- seed = get_seed(True, 0)
300
- state, _ = image_to_3d(image, [], False, seed, 7.5, 12, 3.0, 12, "stochastic", req)
301
- glb_path, _ = extract_glb(state, 0.95, 1024, req)
302
- return glb_path
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
303
 
304
  def test_for_api_gen(image: Image.Image) -> Image.Image:
305
  """
@@ -318,10 +339,26 @@ def test_for_api_gen(image: Image.Image) -> Image.Image:
318
  with gr.Blocks(delete_cache=(600, 600)) as demo:
319
  gr.Markdown("""
320
  ## Image to 3D Asset with [TRELLIS](https://trellis3d.github.io/)
321
- * Upload an image and click "Generate" to create a 3D asset. If the image has alpha channel, it be used as the mask. Otherwise, we use `rembg` to remove the background.
322
- * If you find the generated 3D asset satisfactory, click "Extract GLB" to extract the GLB file and download it.
323
-
324
- ✨New: 1) Experimental multi-image support. 2) Gaussian file extraction.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
325
  """)
326
 
327
  with gr.Row():
@@ -360,8 +397,11 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
360
  extract_glb_btn = gr.Button("Extract GLB", interactive=False)
361
  extract_gs_btn = gr.Button("Extract Gaussian", interactive=False)
362
  generate_glb_btn = gr.Button("Quick Generate GLB in layout")
363
- quick_generate_glb_btn = gr.Button("Quick Generate GLB with download")
364
- quick_generate_glb_easy_btn = gr.Button("Easy Quick Generate GLB with download")
 
 
 
365
  gr.Markdown("""
366
  *NOTE: Gaussian file can be very large (~50MB), it will take a while to display and download.*
367
  """)
@@ -511,14 +551,22 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
511
  outputs=[model_output, download_glb],
512
  )
513
 
514
- quick_generate_glb_easy_btn.click(
515
- fn=quick_glb_dl,
516
- inputs=[image_prompt],
517
- outputs=[download_glb],
 
 
 
 
 
 
 
 
 
 
518
  )
519
 
520
-
521
-
522
 
523
 
524
  # Launch the Gradio app
 
294
  )
295
  return extract_glb(state, mesh_simplify=mesh_simplify, texture_size=texture_size, req=req)
296
 
297
+
298
+ @spaces.GPU(api_name="quick_generate_gs")
299
+ def quick_generate_gs(
300
+ image: Image.Image,
301
+ multiimages: List[Tuple[Image.Image, str]],
302
+ is_multiimage: bool,
303
+ seed: int,
304
+ ss_guidance_strength: float,
305
+ ss_sampling_steps: int,
306
+ slat_guidance_strength: float,
307
+ slat_sampling_steps: int,
308
+ multiimage_algo: Literal["multidiffusion", "stochastic"],
309
+ req: gr.Request,
310
+ ) -> Tuple[str, str]:
311
+ state, _ = image_to_3d(
312
+ image=image,
313
+ multiimages=multiimages,
314
+ is_multiimage=is_multiimage,
315
+ seed=seed,
316
+ ss_guidance_strength=ss_guidance_strength,
317
+ ss_sampling_steps=ss_sampling_steps,
318
+ slat_guidance_strength=slat_guidance_strength,
319
+ slat_sampling_steps=slat_sampling_steps,
320
+ multiimage_algo=multiimage_algo,
321
+ req=req
322
+ )
323
+ return extract_gaussian(state, req=req)
324
 
325
  def test_for_api_gen(image: Image.Image) -> Image.Image:
326
  """
 
339
  with gr.Blocks(delete_cache=(600, 600)) as demo:
340
  gr.Markdown("""
341
  ## Image to 3D Asset with [TRELLIS](https://trellis3d.github.io/)
342
+
343
+ Thanks to the incredible work of [JeffreyXiang/TRELLIS-image-large](https://huggingface.co/JeffreyXiang/TRELLIS-image-large) for providing such a stunning implementation of the TRELLIS 3D pipeline.
344
+
345
+ During my usage, I noticed that many users had questions regarding API access. I've spent some time refactoring the `image_to_3d` pipeline and adding two new endpoints:
346
+
347
+ - 🔁 `quick_generate_glb`: Directly generate and download a `.glb` 3D asset.
348
+ - 🌐 `quick_generate_gs`: Directly generate and download the Gaussian `.ply` file.
349
+ - 🧩 Both functions are exposed as Hugging Face API endpoints and can be called via `gradio_client` or any HTTP client.
350
+
351
+ ### How to Use:
352
+ - Upload an image and click **"Generate"** to create a 3D asset. If the image has an alpha channel, it will be used as a mask. Otherwise, `rembg` will automatically remove the background.
353
+ - If you're satisfied with the result, click **"Extract GLB"** or **"Extract Gaussian"** to download the 3D file.
354
+
355
+ ### Features:
356
+ - ✅ Single-image and experimental multi-image generation
357
+ - ✅ `.glb` extraction with mesh simplification and texturing
358
+ - ✅ `.ply` (Gaussian) extraction
359
+ - ✅ Public API endpoints for one-click asset generation and download
360
+
361
+ Feel free to try it out and send feedback — I'm happy to keep improving it based on your suggestions!
362
  """)
363
 
364
  with gr.Row():
 
397
  extract_glb_btn = gr.Button("Extract GLB", interactive=False)
398
  extract_gs_btn = gr.Button("Extract Gaussian", interactive=False)
399
  generate_glb_btn = gr.Button("Quick Generate GLB in layout")
400
+
401
+ with gr.Row():
402
+ quick_generate_glb_btn = gr.Button("Quick Generate GLB")
403
+ quick_generate_gs_btn = gr.Button("Quick Generate Gaussian")
404
+
405
  gr.Markdown("""
406
  *NOTE: Gaussian file can be very large (~50MB), it will take a while to display and download.*
407
  """)
 
551
  outputs=[model_output, download_glb],
552
  )
553
 
554
+ quick_generate_gs_btn.click(
555
+ fn=quick_generate_gs,
556
+ inputs=[
557
+ image_prompt,
558
+ multiimage_prompt,
559
+ is_multiimage,
560
+ seed,
561
+ ss_guidance_strength,
562
+ ss_sampling_steps,
563
+ slat_guidance_strength,
564
+ slat_sampling_steps,
565
+ multiimage_algo,
566
+ ],
567
+ outputs=[model_output, download_gs],
568
  )
569
 
 
 
570
 
571
 
572
  # Launch the Gradio app