Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -10,7 +10,7 @@ import torch
|
|
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 trellis.representations import Gaussian, MeshExtractResult
|
16 |
from trellis.utils import render_utils, postprocessing_utils
|
@@ -35,16 +35,6 @@ import cv2
|
|
35 |
import os
|
36 |
import random
|
37 |
|
38 |
-
js_func = """
|
39 |
-
function refresh() {
|
40 |
-
const url = new URL(window.location);
|
41 |
-
|
42 |
-
if (url.searchParams.get('__theme') !== 'dark') {
|
43 |
-
url.searchParams.set('__theme', 'dark');
|
44 |
-
window.location.href = url.href;
|
45 |
-
}
|
46 |
-
}
|
47 |
-
"""
|
48 |
|
49 |
style_list = [
|
50 |
{
|
@@ -145,6 +135,7 @@ def preprocess_image(image: Image.Image,
|
|
145 |
ratio = np.sqrt(1024. * 1024. / (width * height))
|
146 |
new_width, new_height = int(width * ratio), int(height * ratio)
|
147 |
image = image['composite'].resize((new_width, new_height))
|
|
|
148 |
|
149 |
print("image:",type(image))
|
150 |
|
@@ -178,7 +169,7 @@ def preprocess_images(images: List[Tuple[Image.Image, str]]) -> List[Image.Image
|
|
178 |
"""
|
179 |
images = [image[0] for image in images]
|
180 |
processed_images = [pipeline.preprocess_image(image) for image in images]
|
181 |
-
return processed_images
|
182 |
|
183 |
|
184 |
def pack_state(gs: Gaussian, mesh: MeshExtractResult) -> dict:
|
@@ -260,6 +251,7 @@ def image_to_3d(
|
|
260 |
str: The path to the video of the 3D model.
|
261 |
"""
|
262 |
user_dir = os.path.join(TMP_DIR, str(req.session_hash))
|
|
|
263 |
if not is_multiimage:
|
264 |
outputs = pipeline.run(
|
265 |
image,
|
@@ -379,10 +371,10 @@ def split_image(image: Image.Image) -> List[Image.Image]:
|
|
379 |
return [preprocess_image(image) for image in images]
|
380 |
|
381 |
|
382 |
-
with gr.Blocks(delete_cache=(600, 600)
|
383 |
gr.Markdown("""
|
384 |
## Sketch to 3D Asset with [TRELLIS](https://trellis3d.github.io/)
|
385 |
-
* draw or upload a sketch and click "Generate" to create a 3D asset.
|
386 |
""")
|
387 |
|
388 |
with gr.Row():
|
@@ -444,7 +436,7 @@ with gr.Blocks(delete_cache=(600, 600), js=js_func) as demo:
|
|
444 |
slat_sampling_steps = gr.Slider(1, 50, label="Sampling Steps", value=12, step=1)
|
445 |
multiimage_algo = gr.Radio(["stochastic", "multidiffusion"], label="Multi-image Algorithm", value="stochastic")
|
446 |
|
447 |
-
generate_btn = gr.Button("Generate")
|
448 |
|
449 |
with gr.Accordion(label="GLB Extraction Settings", open=False):
|
450 |
mesh_simplify = gr.Slider(0.9, 0.98, label="Simplify", value=0.95, step=0.01)
|
|
|
10 |
import numpy as np
|
11 |
import imageio
|
12 |
from easydict import EasyDict as edict
|
13 |
+
from PIL import Image, ImageOps
|
14 |
from trellis.pipelines import TrellisImageTo3DPipeline
|
15 |
from trellis.representations import Gaussian, MeshExtractResult
|
16 |
from trellis.utils import render_utils, postprocessing_utils
|
|
|
35 |
import os
|
36 |
import random
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
style_list = [
|
40 |
{
|
|
|
135 |
ratio = np.sqrt(1024. * 1024. / (width * height))
|
136 |
new_width, new_height = int(width * ratio), int(height * ratio)
|
137 |
image = image['composite'].resize((new_width, new_height))
|
138 |
+
image = ImageOps.invert(image)
|
139 |
|
140 |
print("image:",type(image))
|
141 |
|
|
|
169 |
"""
|
170 |
images = [image[0] for image in images]
|
171 |
processed_images = [pipeline.preprocess_image(image) for image in images]
|
172 |
+
return processed_images
|
173 |
|
174 |
|
175 |
def pack_state(gs: Gaussian, mesh: MeshExtractResult) -> dict:
|
|
|
251 |
str: The path to the video of the 3D model.
|
252 |
"""
|
253 |
user_dir = os.path.join(TMP_DIR, str(req.session_hash))
|
254 |
+
print("image 2", type(image))
|
255 |
if not is_multiimage:
|
256 |
outputs = pipeline.run(
|
257 |
image,
|
|
|
371 |
return [preprocess_image(image) for image in images]
|
372 |
|
373 |
|
374 |
+
with gr.Blocks(delete_cache=(600, 600)) as demo:
|
375 |
gr.Markdown("""
|
376 |
## Sketch to 3D Asset with [TRELLIS](https://trellis3d.github.io/)
|
377 |
+
* 🎨🖌️ draw or upload a sketch and click "Generate" to create a 3D asset.
|
378 |
""")
|
379 |
|
380 |
with gr.Row():
|
|
|
436 |
slat_sampling_steps = gr.Slider(1, 50, label="Sampling Steps", value=12, step=1)
|
437 |
multiimage_algo = gr.Radio(["stochastic", "multidiffusion"], label="Multi-image Algorithm", value="stochastic")
|
438 |
|
439 |
+
#generate_btn = gr.Button("Generate")
|
440 |
|
441 |
with gr.Accordion(label="GLB Extraction Settings", open=False):
|
442 |
mesh_simplify = gr.Slider(0.9, 0.98, label="Simplify", value=0.95, step=0.01)
|