Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
@@ -11,9 +11,10 @@ import numpy as np
|
|
11 |
import imageio
|
12 |
from easydict import EasyDict as edict
|
13 |
from PIL import Image
|
|
|
14 |
from trellis.pipelines import TrellisImageTo3DPipeline
|
15 |
-
from
|
16 |
-
from
|
17 |
|
18 |
|
19 |
MAX_SEED = np.iinfo(np.int32).max
|
@@ -31,16 +32,16 @@ def end_session(req: gr.Request):
|
|
31 |
shutil.rmtree(user_dir)
|
32 |
|
33 |
|
34 |
-
def preprocess_image(image: Image.Image) -> Image.Image:
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
|
45 |
|
46 |
def preprocess_images(images: List[Tuple[Image.Image, str]]) -> List[Image.Image]:
|
@@ -108,6 +109,7 @@ def get_seed(randomize_seed: bool, seed: int) -> int:
|
|
108 |
@spaces.GPU
|
109 |
def image_to_3d(
|
110 |
image: Image.Image,
|
|
|
111 |
seed: int,
|
112 |
ss_guidance_strength: float,
|
113 |
ss_sampling_steps: int,
|
@@ -135,6 +137,7 @@ def image_to_3d(
|
|
135 |
user_dir = os.path.join(TMP_DIR, str(req.session_hash))
|
136 |
outputs = pipeline.run_multi_image(
|
137 |
[image],
|
|
|
138 |
seed=seed,
|
139 |
formats=["gaussian", "mesh"],
|
140 |
preprocess_image=False,
|
@@ -283,8 +286,8 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
|
|
283 |
with gr.Row():
|
284 |
with gr.Column():
|
285 |
with gr.Tabs() as input_tabs:
|
286 |
-
|
287 |
-
|
288 |
|
289 |
with gr.Accordion(label="Generation Settings", open=False):
|
290 |
seed = gr.Slider(0, MAX_SEED, label="Seed", value=0, step=1)
|
@@ -328,11 +331,12 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
|
|
328 |
demo.unload(end_session)
|
329 |
|
330 |
|
331 |
-
image_prompt.upload(
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
)
|
|
|
336 |
|
337 |
generate_btn.click(
|
338 |
get_seed,
|
@@ -340,7 +344,7 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
|
|
340 |
outputs=[seed],
|
341 |
).then(
|
342 |
image_to_3d,
|
343 |
-
inputs=[image_prompt,
|
344 |
outputs=[output_buf, video_output],
|
345 |
).then(
|
346 |
lambda: tuple([gr.Button(interactive=True), gr.Button(interactive=True)]),
|
@@ -378,7 +382,7 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
|
|
378 |
|
379 |
# Launch the Gradio app
|
380 |
if __name__ == "__main__":
|
381 |
-
pipeline =
|
382 |
pipeline.cuda()
|
383 |
try:
|
384 |
pipeline.preprocess_image(Image.fromarray(np.zeros((512, 512, 3), dtype=np.uint8))) # Preload rembg
|
|
|
11 |
import imageio
|
12 |
from easydict import EasyDict as edict
|
13 |
from PIL import Image
|
14 |
+
from Amodal3R.pipelines import Amodal3RImageTo3DPipeline
|
15 |
from trellis.pipelines import TrellisImageTo3DPipeline
|
16 |
+
from Amodal3R.representations import Gaussian, MeshExtractResult
|
17 |
+
from Amodal3R.utils import render_utils, postprocessing_utils
|
18 |
|
19 |
|
20 |
MAX_SEED = np.iinfo(np.int32).max
|
|
|
32 |
shutil.rmtree(user_dir)
|
33 |
|
34 |
|
35 |
+
# def preprocess_image(image: Image.Image) -> Image.Image:
|
36 |
+
# """
|
37 |
+
# Preprocess the input image.
|
38 |
+
# Args:
|
39 |
+
# image (Image.Image): The input image.
|
40 |
+
# Returns:
|
41 |
+
# Image.Image: The preprocessed image.
|
42 |
+
# """
|
43 |
+
# processed_image = pipeline.preprocess_image(image)
|
44 |
+
# return processed_image
|
45 |
|
46 |
|
47 |
def preprocess_images(images: List[Tuple[Image.Image, str]]) -> List[Image.Image]:
|
|
|
109 |
@spaces.GPU
|
110 |
def image_to_3d(
|
111 |
image: Image.Image,
|
112 |
+
mask: Image.Image,
|
113 |
seed: int,
|
114 |
ss_guidance_strength: float,
|
115 |
ss_sampling_steps: int,
|
|
|
137 |
user_dir = os.path.join(TMP_DIR, str(req.session_hash))
|
138 |
outputs = pipeline.run_multi_image(
|
139 |
[image],
|
140 |
+
[mask],
|
141 |
seed=seed,
|
142 |
formats=["gaussian", "mesh"],
|
143 |
preprocess_image=False,
|
|
|
286 |
with gr.Row():
|
287 |
with gr.Column():
|
288 |
with gr.Tabs() as input_tabs:
|
289 |
+
image_prompt = gr.Image(label="Image Prompt", format="png", image_mode="RGBA", type="pil", height=300)
|
290 |
+
mask_prompt = gr.Image(label="Mask Prompt", format="png", image_mode="L", type="pil", height=300)
|
291 |
|
292 |
with gr.Accordion(label="Generation Settings", open=False):
|
293 |
seed = gr.Slider(0, MAX_SEED, label="Seed", value=0, step=1)
|
|
|
331 |
demo.unload(end_session)
|
332 |
|
333 |
|
334 |
+
# image_prompt.upload(
|
335 |
+
# lambda x:x,
|
336 |
+
# inputs=[image_prompt],
|
337 |
+
# outputs=[image_prompt],
|
338 |
+
# )
|
339 |
+
|
340 |
|
341 |
generate_btn.click(
|
342 |
get_seed,
|
|
|
344 |
outputs=[seed],
|
345 |
).then(
|
346 |
image_to_3d,
|
347 |
+
inputs=[image_prompt, mask_prompt, seed, ss_guidance_strength, ss_sampling_steps, slat_guidance_strength, slat_sampling_steps, multiimage_algo],
|
348 |
outputs=[output_buf, video_output],
|
349 |
).then(
|
350 |
lambda: tuple([gr.Button(interactive=True), gr.Button(interactive=True)]),
|
|
|
382 |
|
383 |
# Launch the Gradio app
|
384 |
if __name__ == "__main__":
|
385 |
+
pipeline = pipeline = Amodal3RImageTo3DPipeline.from_pretrained("Sm0kyWu/Amodal3R")
|
386 |
pipeline.cuda()
|
387 |
try:
|
388 |
pipeline.preprocess_image(Image.fromarray(np.zeros((512, 512, 3), dtype=np.uint8))) # Preload rembg
|