Spaces:
Running
on
Zero
Running
on
Zero
fix
Browse files
app.py
CHANGED
@@ -39,121 +39,121 @@ from step1x3d_texture.utils.shape_post_process import (
|
|
39 |
DegenerateFaceRemover,
|
40 |
)
|
41 |
|
42 |
-
if __name__ == "__main__":
|
43 |
-
parser = argparse.ArgumentParser()
|
44 |
-
parser.add_argument(
|
45 |
-
"--geometry_model", type=str, default="Step1X-3D-Geometry-Label-1300m"
|
46 |
-
)
|
47 |
-
parser.add_argument(
|
48 |
-
"--texture_model", type=str, default="Step1X-3D-Texture"
|
49 |
-
)
|
50 |
-
parser.add_argument("--cache_dir", type=str, default="cache")
|
51 |
-
args = parser.parse_args()
|
52 |
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
-
|
56 |
-
"stepfun-ai/Step1X-3D", subfolder=args.geometry_model
|
57 |
-
)
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
)
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
)
|
84 |
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
torch.cuda.empty_cache()
|
98 |
-
print("Generate finish")
|
99 |
-
return geometry_save_path, textured_save_path
|
100 |
-
|
101 |
-
|
102 |
-
with gr.Blocks(title="Step1X-3D demo") as demo:
|
103 |
-
gr.Markdown("# Step1X-3D")
|
104 |
-
with gr.Row():
|
105 |
-
with gr.Column(scale=2):
|
106 |
-
input_image = gr.Image(
|
107 |
-
label="Image", type="filepath", image_mode="RGBA"
|
108 |
-
)
|
109 |
-
guidance_scale = gr.Number(label="Guidance Scale", value="7.5")
|
110 |
-
inference_steps = gr.Slider(
|
111 |
-
label="Inferece Steps", minimum=1, maximum=100, value=50
|
112 |
-
)
|
113 |
-
max_facenum = gr.Number(label="Max Face Num", value="400000")
|
114 |
-
symmetry = gr.Radio(
|
115 |
-
choices=["symmetry", "asymmetry"],
|
116 |
-
label="Symmetry Type",
|
117 |
-
value="symmetry",
|
118 |
-
type="index",
|
119 |
-
)
|
120 |
-
edge_type = gr.Radio(
|
121 |
-
choices=["sharp", "normal", "smooth"],
|
122 |
-
label="Edge Type",
|
123 |
-
value="sharp",
|
124 |
-
type="value",
|
125 |
-
)
|
126 |
-
btn = gr.Button("Start")
|
127 |
-
with gr.Column(scale=4):
|
128 |
-
textured_preview = gr.Model3D(label="Textured", height=380)
|
129 |
-
geometry_preview = gr.Model3D(label="Geometry", height=380)
|
130 |
-
with gr.Column(scale=1):
|
131 |
-
gr.Examples(
|
132 |
-
examples=[
|
133 |
-
["examples/images/000.png"],
|
134 |
-
["examples/images/001.png"],
|
135 |
-
["examples/images/004.png"],
|
136 |
-
["examples/images/008.png"],
|
137 |
-
["examples/images/028.png"],
|
138 |
-
["examples/images/032.png"],
|
139 |
-
["examples/images/061.png"],
|
140 |
-
["examples/images/107.png"],
|
141 |
-
],
|
142 |
-
inputs=[input_image],
|
143 |
-
cache_examples=False,
|
144 |
-
)
|
145 |
-
|
146 |
-
btn.click(
|
147 |
-
generate_func,
|
148 |
-
inputs=[
|
149 |
-
input_image,
|
150 |
-
guidance_scale,
|
151 |
-
inference_steps,
|
152 |
-
max_facenum,
|
153 |
-
symmetry,
|
154 |
-
edge_type,
|
155 |
-
],
|
156 |
-
outputs=[geometry_preview, textured_preview],
|
157 |
-
)
|
158 |
|
159 |
-
|
|
|
39 |
DegenerateFaceRemover,
|
40 |
)
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
+
parser = argparse.ArgumentParser()
|
44 |
+
parser.add_argument(
|
45 |
+
"--geometry_model", type=str, default="Step1X-3D-Geometry-Label-1300m"
|
46 |
+
)
|
47 |
+
parser.add_argument(
|
48 |
+
"--texture_model", type=str, default="Step1X-3D-Texture"
|
49 |
+
)
|
50 |
+
parser.add_argument("--cache_dir", type=str, default="cache")
|
51 |
+
args = parser.parse_args()
|
52 |
|
53 |
+
os.makedirs(args.cache_dir, exist_ok=True)
|
|
|
|
|
54 |
|
55 |
+
geometry_model = Step1X3DGeometryPipeline.from_pretrained(
|
56 |
+
"stepfun-ai/Step1X-3D", subfolder=args.geometry_model
|
57 |
+
)
|
58 |
+
|
59 |
+
texture_model = Step1X3DTexturePipeline.from_pretrained("stepfun-ai/Step1X-3D", subfolder=args.texture_model)
|
60 |
+
|
61 |
+
|
62 |
+
@spaces.GPU(duration=240)
|
63 |
+
def generate_func(
|
64 |
+
input_image_path, guidance_scale, inference_steps, max_facenum, symmetry, edge_type
|
65 |
+
):
|
66 |
+
geometry_model = geometry_model.to("cuda")
|
67 |
+
if "Label" in args.geometry_model:
|
68 |
+
symmetry_values = ['x', 'asymmetry']
|
69 |
+
out = geometry_model(
|
70 |
+
input_image_path,
|
71 |
+
label={"symmetry": symmetry_values[int(symmetry)], "edge_type": edge_type},
|
72 |
+
guidance_scale=float(guidance_scale),
|
73 |
+
octree_resolution=384,
|
74 |
+
max_facenum=int(max_facenum),
|
75 |
+
num_inference_steps=int(inference_steps),
|
76 |
+
)
|
77 |
+
else:
|
78 |
+
out = geometry_model(
|
79 |
+
input_image_path,
|
80 |
+
guidance_scale=float(guidance_scale),
|
81 |
+
num_inference_steps=int(inference_steps),
|
82 |
+
max_facenum=int(max_facenum),
|
83 |
+
)
|
84 |
+
|
85 |
+
save_name = str(uuid.uuid4())
|
86 |
+
print(save_name)
|
87 |
+
geometry_save_path = f"{args.cache_dir}/{save_name}.glb"
|
88 |
+
geometry_mesh = out.mesh[0]
|
89 |
+
geometry_mesh.export(geometry_save_path)
|
90 |
+
|
91 |
+
geometry_mesh = DegenerateFaceRemover()(geometry_mesh)
|
92 |
+
geometry_mesh = FaceReducer()(geometry_mesh)
|
93 |
+
textured_mesh = texture_model(input_image_path, geometry_mesh)
|
94 |
+
textured_save_path = f"{args.cache_dir}/{save_name}-textured.glb"
|
95 |
+
textured_mesh.export(textured_save_path)
|
96 |
+
|
97 |
+
torch.cuda.empty_cache()
|
98 |
+
print("Generate finish")
|
99 |
+
return geometry_save_path, textured_save_path
|
100 |
+
|
101 |
+
|
102 |
+
with gr.Blocks(title="Step1X-3D demo") as demo:
|
103 |
+
gr.Markdown("# Step1X-3D")
|
104 |
+
with gr.Row():
|
105 |
+
with gr.Column(scale=2):
|
106 |
+
input_image = gr.Image(
|
107 |
+
label="Image", type="filepath", image_mode="RGBA"
|
108 |
)
|
109 |
+
guidance_scale = gr.Number(label="Guidance Scale", value="7.5")
|
110 |
+
inference_steps = gr.Slider(
|
111 |
+
label="Inferece Steps", minimum=1, maximum=100, value=50
|
112 |
+
)
|
113 |
+
max_facenum = gr.Number(label="Max Face Num", value="400000")
|
114 |
+
symmetry = gr.Radio(
|
115 |
+
choices=["symmetry", "asymmetry"],
|
116 |
+
label="Symmetry Type",
|
117 |
+
value="symmetry",
|
118 |
+
type="index",
|
119 |
+
)
|
120 |
+
edge_type = gr.Radio(
|
121 |
+
choices=["sharp", "normal", "smooth"],
|
122 |
+
label="Edge Type",
|
123 |
+
value="sharp",
|
124 |
+
type="value",
|
125 |
+
)
|
126 |
+
btn = gr.Button("Start")
|
127 |
+
with gr.Column(scale=4):
|
128 |
+
textured_preview = gr.Model3D(label="Textured", height=380)
|
129 |
+
geometry_preview = gr.Model3D(label="Geometry", height=380)
|
130 |
+
with gr.Column(scale=1):
|
131 |
+
gr.Examples(
|
132 |
+
examples=[
|
133 |
+
["examples/images/000.png"],
|
134 |
+
["examples/images/001.png"],
|
135 |
+
["examples/images/004.png"],
|
136 |
+
["examples/images/008.png"],
|
137 |
+
["examples/images/028.png"],
|
138 |
+
["examples/images/032.png"],
|
139 |
+
["examples/images/061.png"],
|
140 |
+
["examples/images/107.png"],
|
141 |
+
],
|
142 |
+
inputs=[input_image],
|
143 |
+
cache_examples=False,
|
144 |
)
|
145 |
|
146 |
+
btn.click(
|
147 |
+
generate_func,
|
148 |
+
inputs=[
|
149 |
+
input_image,
|
150 |
+
guidance_scale,
|
151 |
+
inference_steps,
|
152 |
+
max_facenum,
|
153 |
+
symmetry,
|
154 |
+
edge_type,
|
155 |
+
],
|
156 |
+
outputs=[geometry_preview, textured_preview],
|
157 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
|
159 |
+
demo.launch()
|