Spaces:
Sleeping
Sleeping
feat: new generate plates method
Browse files
app.py
CHANGED
@@ -224,15 +224,19 @@ def generate_mesh(image, source_size=512, render_size=384, mesh_size=512, export
|
|
224 |
|
225 |
return None, None
|
226 |
|
227 |
-
def
|
|
|
|
|
|
|
|
|
228 |
mesh_path, _ = generate_mesh(image, export_mesh=True)
|
229 |
return mesh_path, mesh_path
|
230 |
|
231 |
-
def
|
232 |
_, video_path = generate_mesh(image, export_video=True)
|
233 |
return video_path
|
234 |
|
235 |
-
def
|
236 |
return mesh_file
|
237 |
|
238 |
# 从 assets 文件夹中设置示例文件,并限制最多读取 10 个文件
|
@@ -252,21 +256,23 @@ with gr.Blocks() as demo:
|
|
252 |
with gr.Row():
|
253 |
with gr.Column():
|
254 |
img_input = gr.Image(type="pil", label="输入图像")
|
255 |
-
examples_component = gr.Examples(examples=examples, inputs=img_input, outputs=None, examples_per_page=
|
|
|
256 |
generate_mesh_button = gr.Button("生成模型")
|
257 |
generate_video_button = gr.Button("生成视频")
|
258 |
with gr.Column():
|
|
|
259 |
model_output = LitModel3D(
|
260 |
clear_color=[0, 0, 0, 0], # 可调整背景颜色,以获得更好的对比度
|
261 |
label="模型可视化",
|
262 |
scale=1.0,
|
263 |
-
tonemapping="aces",
|
264 |
-
exposure=1.1,
|
265 |
-
contrast=1.1,
|
266 |
-
camera_position=(0, 0, 2),
|
267 |
-
zoom_speed=0.5,
|
268 |
-
pan_speed=0.5,
|
269 |
-
interactive=False
|
270 |
)
|
271 |
|
272 |
with gr.Row():
|
@@ -278,19 +284,16 @@ with gr.Blocks() as demo:
|
|
278 |
|
279 |
# 清除输出
|
280 |
def clear_model_viewer():
|
281 |
-
"""在加载新模型前重置
|
282 |
return gr.update(value=None)
|
283 |
|
284 |
-
def generate_and_visualize(image):
|
285 |
-
mesh_path = step_1_generate_obj(image)
|
286 |
-
return mesh_path, mesh_path
|
287 |
-
|
288 |
# 首先清除输出的 3D 模型
|
289 |
img_input.change(clear_model_viewer, inputs=None, outputs=model_output)
|
290 |
|
291 |
# 然后生成模型和视频
|
292 |
-
|
293 |
-
|
|
|
294 |
|
295 |
demo.launch(
|
296 |
auth=(os.environ.get('AUTH_USERNAME'), os.environ.get('AUTH_PASSWORD'))
|
|
|
224 |
|
225 |
return None, None
|
226 |
|
227 |
+
def step_1_generate_planes(image):
|
228 |
+
planes_path = generate_mesh(image)
|
229 |
+
return planes_path
|
230 |
+
|
231 |
+
def step_2_generate_obj(image):
|
232 |
mesh_path, _ = generate_mesh(image, export_mesh=True)
|
233 |
return mesh_path, mesh_path
|
234 |
|
235 |
+
def step_3_generate_video(image):
|
236 |
_, video_path = generate_mesh(image, export_video=True)
|
237 |
return video_path
|
238 |
|
239 |
+
def step_4_display_3d_model(mesh_file):
|
240 |
return mesh_file
|
241 |
|
242 |
# 从 assets 文件夹中设置示例文件,并限制最多读取 10 个文件
|
|
|
256 |
with gr.Row():
|
257 |
with gr.Column():
|
258 |
img_input = gr.Image(type="pil", label="输入图像")
|
259 |
+
examples_component = gr.Examples(examples=examples, inputs=img_input, outputs=None, examples_per_page=5)
|
260 |
+
generate_planes_button = gr.Button("生成平面图")
|
261 |
generate_mesh_button = gr.Button("生成模型")
|
262 |
generate_video_button = gr.Button("生成视频")
|
263 |
with gr.Column():
|
264 |
+
planes_output = gr.Image(label="平面图")
|
265 |
model_output = LitModel3D(
|
266 |
clear_color=[0, 0, 0, 0], # 可调整背景颜色,以获得更好的对比度
|
267 |
label="模型可视化",
|
268 |
scale=1.0,
|
269 |
+
tonemapping="aces", # 可使用 aces 色调映射,使灯光更逼真
|
270 |
+
exposure=1.1, # 可调节曝光以控制亮度
|
271 |
+
contrast=1.1, # 可略微增加对比度,以获得更好的深度
|
272 |
+
camera_position=(0, 0, 2), # 将设置初始摄像机位置,使模型居中
|
273 |
+
zoom_speed=0.5, # 将调整变焦速度,以便更好地控制
|
274 |
+
pan_speed=0.5, # 将调整摇摄速度,以便更好地控制
|
275 |
+
interactive=False # 这样用户就可以与模型进行交互
|
276 |
)
|
277 |
|
278 |
with gr.Row():
|
|
|
284 |
|
285 |
# 清除输出
|
286 |
def clear_model_viewer():
|
287 |
+
"""在加载新模型前重置 Gradio。"""
|
288 |
return gr.update(value=None)
|
289 |
|
|
|
|
|
|
|
|
|
290 |
# 首先清除输出的 3D 模型
|
291 |
img_input.change(clear_model_viewer, inputs=None, outputs=model_output)
|
292 |
|
293 |
# 然后生成模型和视频
|
294 |
+
generate_planes_button.click(step_1_generate_planes, input=img_input, outputs=planes_output)
|
295 |
+
generate_mesh_button.click(step_2_generate_obj, inputs=img_input, outputs=[obj_file_output, model_output])
|
296 |
+
generate_video_button.click(step_3_generate_video, inputs=img_input, outputs=video_file_output)
|
297 |
|
298 |
demo.launch(
|
299 |
auth=(os.environ.get('AUTH_USERNAME'), os.environ.get('AUTH_PASSWORD'))
|