Huiwenshi commited on
Commit
a0d4ef7
·
verified ·
1 Parent(s): 5e028db

Upload app_hg.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app_hg.py +29 -21
app_hg.py CHANGED
@@ -39,24 +39,32 @@ import sys
39
  import subprocess
40
  from glob import glob
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
- install_cuda_toolkit()
60
 
61
 
62
  from infer import seed_everything, save_gif
@@ -189,7 +197,7 @@ if BAKE_AVAILEBLE:
189
 
190
 
191
  ### functional modules
192
- @spaces.GPU
193
  def stage_0_t2i(text, image, seed, step):
194
  os.makedirs('./outputs/app_output', exist_ok=True)
195
  exists = set(int(_) for _ in os.listdir('./outputs/app_output') if not _.startswith("."))
@@ -222,7 +230,7 @@ def stage_1_xbg(image, save_folder, force_remove):
222
  rgba.save(dst)
223
  return dst
224
 
225
- @spaces.GPU
226
  def stage_2_i2v(image, seed, step, save_folder):
227
  if isinstance(image, str):
228
  image = Image.open(image)
@@ -260,7 +268,7 @@ def stage_3_v23(
260
  obj_dst = save_folder + '/mesh_vertex_colors.obj' # gradio just only can show vertex shading
261
  return obj_dst, glb_dst
262
 
263
- @spaces.GPU
264
  def stage_3p_baking(save_folder, color, bake):
265
  if color == "texture" and bake:
266
  obj_dst = worker_baker(save_folder)
@@ -269,7 +277,7 @@ def stage_3p_baking(save_folder, color, bake):
269
  else:
270
  return None
271
 
272
- @spaces.GPU
273
  def stage_4_gif(save_folder, color, bake, render):
274
  if not render: return None
275
  if os.path.exists(save_folder + '/view_1/bake/mesh.obj'):
 
39
  import subprocess
40
  from glob import glob
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
+ # install_cuda_toolkit()
60
+
61
+ def install_requirements():
62
+ # Install the packages listed in requirements.txt
63
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "git+https://github.com/NVlabs/nvdiffrast"])
64
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "git+https://github.com/facebookresearch/pytorch3d@stable"])
65
+
66
+ install_requirements()
67
 
 
68
 
69
 
70
  from infer import seed_everything, save_gif
 
197
 
198
 
199
  ### functional modules
200
+ @spaces.GPU(duration=140)
201
  def stage_0_t2i(text, image, seed, step):
202
  os.makedirs('./outputs/app_output', exist_ok=True)
203
  exists = set(int(_) for _ in os.listdir('./outputs/app_output') if not _.startswith("."))
 
230
  rgba.save(dst)
231
  return dst
232
 
233
+ @spaces.GPU(duration=110)
234
  def stage_2_i2v(image, seed, step, save_folder):
235
  if isinstance(image, str):
236
  image = Image.open(image)
 
268
  obj_dst = save_folder + '/mesh_vertex_colors.obj' # gradio just only can show vertex shading
269
  return obj_dst, glb_dst
270
 
271
+ @spaces.GPU(duration=40)
272
  def stage_3p_baking(save_folder, color, bake):
273
  if color == "texture" and bake:
274
  obj_dst = worker_baker(save_folder)
 
277
  else:
278
  return None
279
 
280
+ @spaces.GPU(duration=20)
281
  def stage_4_gif(save_folder, color, bake, render):
282
  if not render: return None
283
  if os.path.exists(save_folder + '/view_1/bake/mesh.obj'):