jayman commited on
Commit
33cd669
·
verified ·
1 Parent(s): 66eec22

Update hy3dgen/texgen/pipelines.py

Browse files
Files changed (1) hide show
  1. hy3dgen/texgen/pipelines.py +25 -27
hy3dgen/texgen/pipelines.py CHANGED
@@ -1,18 +1,17 @@
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
4
- # in the repsective licenses of these third-party components.
5
  # Users must comply with all terms and conditions of original licenses of these third-party
6
  # components and must ensure that the usage of the third party components adheres to
7
  # all relevant laws and regulations.
8
 
9
  # For avoidance of doubts, Hunyuan 3D means the large language models and
10
- # their software and algorithms, including trained model weights, parameters (including
11
- # optimizer states), machine-learning model code, inference-enabling code, training-enabling code,
12
  # fine-tuning enabling code and other elements of the foregoing made publicly available
13
  # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
14
 
15
-
16
  import logging
17
  import numpy as np
18
  import os
@@ -49,35 +48,34 @@ class Hunyuan3DTexGenConfig:
49
  class Hunyuan3DPaintPipeline:
50
  @classmethod
51
  def from_pretrained(cls, model_path):
 
 
52
  original_model_path = model_path
 
53
  if not os.path.exists(model_path):
54
- # try local path
55
  base_dir = os.environ.get('HY3DGEN_MODELS', '~/.cache/hy3dgen')
56
- model_path = os.path.expanduser(os.path.join(base_dir, model_path))
57
-
 
 
 
 
 
 
 
 
 
 
 
58
  delight_model_path = os.path.join(model_path, 'hunyuan3d-delight-v2-0')
59
  multiview_model_path = os.path.join(model_path, 'hunyuan3d-paint-v2-0')
60
 
61
- if not os.path.exists(delight_model_path) or not os.path.exists(multiview_model_path):
62
- try:
63
- import huggingface_hub
64
- # download from huggingface
65
- model_path = huggingface_hub.snapshot_download(repo_id=original_model_path,
66
- allow_patterns=["hunyuan3d-delight-v2-0/*"])
67
- model_path = huggingface_hub.snapshot_download(repo_id=original_model_path,
68
- allow_patterns=["hunyuan3d-paint-v2-0/*"])
69
- delight_model_path = os.path.join(model_path, 'hunyuan3d-delight-v2-0')
70
- multiview_model_path = os.path.join(model_path, 'hunyuan3d-paint-v2-0')
71
- return cls(Hunyuan3DTexGenConfig(delight_model_path, multiview_model_path))
72
- except ImportError:
73
- logger.warning(
74
- "You need to install HuggingFace Hub to load models from the hub."
75
- )
76
- raise RuntimeError(f"Model path {model_path} not found")
77
- else:
78
- return cls(Hunyuan3DTexGenConfig(delight_model_path, multiview_model_path))
79
-
80
- raise FileNotFoundError(f"Model path {original_model_path} not found and we could not find it at huggingface")
81
 
82
  def __init__(self, config):
83
  self.config = config
 
1
  # Hunyuan 3D is licensed under the TENCENT HUNYUAN NON-COMMERCIAL LICENSE AGREEMENT
2
  # except for the third-party components listed below.
3
  # Hunyuan 3D does not impose any additional limitations beyond what is outlined
4
+ # in the repsective licenses of third-party components.
5
  # Users must comply with all terms and conditions of original licenses of these third-party
6
  # components and must ensure that the usage of the third party components adheres to
7
  # all relevant laws and regulations.
8
 
9
  # For avoidance of doubts, Hunyuan 3D means the large language models and
10
+ # their software and algorithms, including trained model weights, parameters including
11
+ # optimizer states, machine-learning model code, inference-enabling code, training-enabling code,
12
  # fine-tuning enabling code and other elements of the foregoing made publicly available
13
  # by Tencent in accordance with TENCENT HUNYUAN COMMUNITY LICENSE AGREEMENT.
14
 
 
15
  import logging
16
  import numpy as np
17
  import os
 
48
  class Hunyuan3DPaintPipeline:
49
  @classmethod
50
  def from_pretrained(cls, model_path):
51
+ from huggingface_hub import snapshot_download
52
+
53
  original_model_path = model_path
54
+
55
  if not os.path.exists(model_path):
 
56
  base_dir = os.environ.get('HY3DGEN_MODELS', '~/.cache/hy3dgen')
57
+ model_path = os.path.expanduser(os.path.join(base_dir, original_model_path))
58
+
59
+ delight_model_path = os.path.join(model_path, 'hunyuan3d-delight-v2-0')
60
+ multiview_model_path = os.path.join(model_path, 'hunyuan3d-paint-v2-0')
61
+
62
+ if not os.path.exists(delight_model_path) or not os.path.exists(multiview_model_path):
63
+ model_path = snapshot_download(
64
+ repo_id=original_model_path,
65
+ allow_patterns=[
66
+ "hunyuan3d-delight-v2-0/*",
67
+ "hunyuan3d-paint-v2-0/*",
68
+ ],
69
+ )
70
  delight_model_path = os.path.join(model_path, 'hunyuan3d-delight-v2-0')
71
  multiview_model_path = os.path.join(model_path, 'hunyuan3d-paint-v2-0')
72
 
73
+ if not os.path.exists(delight_model_path):
74
+ raise FileNotFoundError(f"Texture delight model folder not found: {delight_model_path}")
75
+ if not os.path.exists(multiview_model_path):
76
+ raise FileNotFoundError(f"Texture paint model folder not found: {multiview_model_path}")
77
+
78
+ return cls(Hunyuan3DTexGenConfig(delight_model_path, multiview_model_path))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
 
80
  def __init__(self, config):
81
  self.config = config