Upload demo.py with huggingface_hub
Browse files
demo.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
sys.path.insert(0, './hy3dshape')
|
| 3 |
+
sys.path.insert(0, './hy3dpaint')
|
| 4 |
+
|
| 5 |
+
from PIL import Image
|
| 6 |
+
from hy3dshape.rembg import BackgroundRemover
|
| 7 |
+
from hy3dshape.pipelines import Hunyuan3DDiTFlowMatchingPipeline
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
from textureGenPipeline import Hunyuan3DPaintPipeline, Hunyuan3DPaintConfig
|
| 11 |
+
|
| 12 |
+
try:
|
| 13 |
+
from torchvision_fix import apply_fix
|
| 14 |
+
apply_fix()
|
| 15 |
+
except ImportError:
|
| 16 |
+
print("Warning: torchvision_fix module not found, proceeding without compatibility fix")
|
| 17 |
+
except Exception as e:
|
| 18 |
+
print(f"Warning: Failed to apply torchvision fix: {e}")
|
| 19 |
+
|
| 20 |
+
# shape
|
| 21 |
+
model_path = 'tencent/Hunyuan3D-2.1'
|
| 22 |
+
pipeline_shapegen = Hunyuan3DDiTFlowMatchingPipeline.from_pretrained(model_path)
|
| 23 |
+
#
|
| 24 |
+
image_path = 'assets/demo.png'
|
| 25 |
+
image = Image.open(image_path).convert("RGBA")
|
| 26 |
+
if image.mode == 'RGB':
|
| 27 |
+
rembg = BackgroundRemover()
|
| 28 |
+
image = rembg(image)
|
| 29 |
+
|
| 30 |
+
mesh = pipeline_shapegen(image=image)[0]
|
| 31 |
+
mesh.export('demo.glb')
|
| 32 |
+
|
| 33 |
+
# paint
|
| 34 |
+
max_num_view = 6 # can be 6 to 9
|
| 35 |
+
resolution = 512 # can be 768 or 512
|
| 36 |
+
conf = Hunyuan3DPaintConfig(max_num_view, resolution)
|
| 37 |
+
conf.realesrgan_ckpt_path = "hy3dpaint/ckpt/RealESRGAN_x4plus.pth"
|
| 38 |
+
conf.multiview_cfg_path = "hy3dpaint/cfgs/hunyuan-paint-pbr.yaml"
|
| 39 |
+
conf.custom_pipeline = "hy3dpaint/hunyuanpaintpbr"
|
| 40 |
+
paint_pipeline = Hunyuan3DPaintPipeline(conf)
|
| 41 |
+
|
| 42 |
+
output_mesh_path = 'demo_textured.glb'
|
| 43 |
+
output_mesh_path = paint_pipeline(
|
| 44 |
+
mesh_path = "demo.glb",
|
| 45 |
+
image_path = 'assets/demo.png',
|
| 46 |
+
output_mesh_path = output_mesh_path
|
| 47 |
+
)
|