Huiwenshi commited on
Commit
b0bacf1
·
verified ·
1 Parent(s): c13749f

Upload app_hg.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app_hg.py +58 -59
app_hg.py CHANGED
@@ -34,68 +34,67 @@ from PIL import Image
34
  from einops import rearrange
35
  import pandas as pd
36
 
37
- # import sys
38
- # import spaces
39
- # import subprocess
40
- # from huggingface_hub import snapshot_download
41
-
42
- # def install_cuda_toolkit():
43
- # # CUDA_TOOLKIT_URL = "https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run"
44
- # CUDA_TOOLKIT_URL = "https://developer.download.nvidia.com/compute/cuda/12.2.0/local_installers/cuda_12.2.0_535.54.03_linux.run"
45
- # CUDA_TOOLKIT_FILE = "/tmp/%s" % os.path.basename(CUDA_TOOLKIT_URL)
46
- # subprocess.call(["wget", "-q", CUDA_TOOLKIT_URL, "-O", CUDA_TOOLKIT_FILE])
47
- # subprocess.call(["chmod", "+x", CUDA_TOOLKIT_FILE])
48
- # subprocess.call([CUDA_TOOLKIT_FILE, "--silent", "--toolkit"])
49
-
50
- # os.environ["CUDA_HOME"] = "/usr/local/cuda"
51
- # os.environ["PATH"] = "%s/bin:%s" % (os.environ["CUDA_HOME"], os.environ["PATH"])
52
- # os.environ["LD_LIBRARY_PATH"] = "%s/lib:%s" % (
53
- # os.environ["CUDA_HOME"],
54
- # "" if "LD_LIBRARY_PATH" not in os.environ else os.environ["LD_LIBRARY_PATH"],
55
- # )
56
- # # Fix: arch_list[-1] += '+PTX'; IndexError: list index out of range
57
- # os.environ["TORCH_CUDA_ARCH_LIST"] = "8.0;8.6"
58
 
59
- # def install_requirements():
60
- # subprocess.check_call([sys.executable, "-m", "pip", "install", "git+https://github.com/NVlabs/nvdiffrast"])
61
- # subprocess.check_call([sys.executable, "-m", "pip", "install", "git+https://github.com/facebookresearch/pytorch3d@stable"])
62
-
63
 
64
- # def download_models():
65
- # os.makedirs("weights", exist_ok=True)
66
- # os.makedirs("weights/hunyuanDiT", exist_ok=True)
67
- # os.makedirs("third_party/weights/DUSt3R_ViTLarge_BaseDecoder_512_dpt", exist_ok=True)
68
- # try:
69
- # snapshot_download(
70
- # repo_id="tencent/Hunyuan3D-1",
71
- # local_dir="./weights",
72
- # resume_download=True
73
- # )
74
- # print("Successfully downloaded Hunyuan3D-1 model")
75
- # except Exception as e:
76
- # print(f"Error downloading Hunyuan3D-1: {e}")
77
- # try:
78
- # snapshot_download(
79
- # repo_id="Tencent-Hunyuan/HunyuanDiT-v1.1-Diffusers-Distilled",
80
- # local_dir="./weights/hunyuanDiT",
81
- # resume_download=True
82
- # )
83
- # print("Successfully downloaded HunyuanDiT model")
84
- # except Exception as e:
85
- # print(f"Error downloading HunyuanDiT: {e}")
86
- # try:
87
- # snapshot_download(
88
- # repo_id="naver/DUSt3R_ViTLarge_BaseDecoder_512_dpt",
89
- # local_dir="./third_party/weights/DUSt3R_ViTLarge_BaseDecoder_512_dpt",
90
- # resume_download=True
91
- # )
92
- # print("Successfully downloaded DUSt3R model")
93
- # except Exception as e:
94
- # print(f"Error downloading DUSt3R: {e}")
95
 
96
- # # install_cuda_toolkit()
97
- # install_requirements()
98
- # download_models() ### download weights !!!!
99
 
100
  from infer import seed_everything, save_gif
101
  from infer import Text2Image, Removebg, Image2Views, Views2Mesh, GifRenderer
 
34
  from einops import rearrange
35
  import pandas as pd
36
 
37
+ import sys
38
+ import spaces
39
+ import subprocess
40
+ from huggingface_hub import snapshot_download
41
+
42
+ def install_cuda_toolkit():
43
+ # CUDA_TOOLKIT_URL = "https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run"
44
+ CUDA_TOOLKIT_URL = "https://developer.download.nvidia.com/compute/cuda/12.2.0/local_installers/cuda_12.2.0_535.54.03_linux.run"
45
+ CUDA_TOOLKIT_FILE = "/tmp/%s" % os.path.basename(CUDA_TOOLKIT_URL)
46
+ subprocess.call(["wget", "-q", CUDA_TOOLKIT_URL, "-O", CUDA_TOOLKIT_FILE])
47
+ subprocess.call(["chmod", "+x", CUDA_TOOLKIT_FILE])
48
+ subprocess.call([CUDA_TOOLKIT_FILE, "--silent", "--toolkit"])
49
+
50
+ os.environ["CUDA_HOME"] = "/usr/local/cuda"
51
+ os.environ["PATH"] = "%s/bin:%s" % (os.environ["CUDA_HOME"], os.environ["PATH"])
52
+ os.environ["LD_LIBRARY_PATH"] = "%s/lib:%s" % (
53
+ os.environ["CUDA_HOME"],
54
+ "" if "LD_LIBRARY_PATH" not in os.environ else os.environ["LD_LIBRARY_PATH"],
55
+ )
56
+ # Fix: arch_list[-1] += '+PTX'; IndexError: list index out of range
57
+ os.environ["TORCH_CUDA_ARCH_LIST"] = "8.0;8.6"
58
 
59
+ def install_requirements():
60
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "git+https://github.com/NVlabs/nvdiffrast"])
61
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "git+https://github.com/facebookresearch/pytorch3d@stable"])
 
62
 
63
+ def download_models():
64
+ os.makedirs("weights", exist_ok=True)
65
+ os.makedirs("weights/hunyuanDiT", exist_ok=True)
66
+ os.makedirs("third_party/weights/DUSt3R_ViTLarge_BaseDecoder_512_dpt", exist_ok=True)
67
+ try:
68
+ snapshot_download(
69
+ repo_id="tencent/Hunyuan3D-1",
70
+ local_dir="./weights",
71
+ resume_download=True
72
+ )
73
+ print("Successfully downloaded Hunyuan3D-1 model")
74
+ except Exception as e:
75
+ print(f"Error downloading Hunyuan3D-1: {e}")
76
+ try:
77
+ snapshot_download(
78
+ repo_id="Tencent-Hunyuan/HunyuanDiT-v1.1-Diffusers-Distilled",
79
+ local_dir="./weights/hunyuanDiT",
80
+ resume_download=True
81
+ )
82
+ print("Successfully downloaded HunyuanDiT model")
83
+ except Exception as e:
84
+ print(f"Error downloading HunyuanDiT: {e}")
85
+ try:
86
+ snapshot_download(
87
+ repo_id="naver/DUSt3R_ViTLarge_BaseDecoder_512_dpt",
88
+ local_dir="./third_party/weights/DUSt3R_ViTLarge_BaseDecoder_512_dpt",
89
+ resume_download=True
90
+ )
91
+ print("Successfully downloaded DUSt3R model")
92
+ except Exception as e:
93
+ print(f"Error downloading DUSt3R: {e}")
94
 
95
+ # install_cuda_toolkit()
96
+ install_requirements()
97
+ download_models() ### download weights !!!!
98
 
99
  from infer import seed_everything, save_gif
100
  from infer import Text2Image, Removebg, Image2Views, Views2Mesh, GifRenderer