Vo Minh Vu commited on
Commit
e44bcf0
·
1 Parent(s): 2bb1610

Fix No @spaces.GPU function detected during startup when deploy on hugging face

Browse files
Files changed (5) hide show
  1. .hf-space +12 -0
  2. hg_app.py +21 -2
  3. requirements-hf.txt +7 -0
  4. run_in_hf.sh +22 -0
  5. setup.py +9 -1
.hf-space ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ title: Hunyuan 3D Generator
2
+ emoji: 🧊
3
+ colorFrom: blue
4
+ colorTo: indigo
5
+ sdk: gradio
6
+ sdk_version: 4.44.1
7
+ app_file: hg_app.py
8
+ pinned: false
9
+ license: apache-2.0
10
+ python_version: 3.10
11
+ hf_oauth: false
12
+ hardware: gpu
hg_app.py CHANGED
@@ -10,10 +10,24 @@ args = parser.parse_args()
10
  print(f"Running on {'local' if args.local else 'huggingface'}")
11
  if not args.local:
12
  import os
13
- import spaces
14
  import subprocess
15
  import sys
16
  import shlex
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  print("cd /home/user/app/hy3dgen/texgen/differentiable_renderer/ && bash compile_mesh_painter.sh")
19
  os.system("cd /home/user/app/hy3dgen/texgen/differentiable_renderer/ && bash compile_mesh_painter.sh")
@@ -30,8 +44,10 @@ else:
30
  class GPU:
31
  def __init__(self, duration=60):
32
  self.duration = duration
 
33
  def __call__(self, func):
34
- return func
 
35
 
36
  import os
37
  import shutil
@@ -128,6 +144,7 @@ def _gen_shape(
128
  check_box_rembg: bool,
129
  req: gr.Request,
130
  ):
 
131
  if caption: print('prompt is', caption)
132
  save_folder = os.path.join(SAVE_DIR, str(req.session_hash))
133
  os.makedirs(save_folder, exist_ok=True)
@@ -192,6 +209,7 @@ def generation_all(
192
  check_box_rembg: bool,
193
  req: gr.Request,
194
  ):
 
195
  mesh, save_folder, image = _gen_shape(
196
  caption,
197
  image,
@@ -228,6 +246,7 @@ def shape_generation(
228
  check_box_rembg: bool,
229
  req: gr.Request,
230
  ):
 
231
  mesh, save_folder, image = _gen_shape(
232
  caption,
233
  image,
 
10
  print(f"Running on {'local' if args.local else 'huggingface'}")
11
  if not args.local:
12
  import os
 
13
  import subprocess
14
  import sys
15
  import shlex
16
+
17
+ # Try to import spaces, create a fallback if not available
18
+ try:
19
+ import spaces
20
+ print("Successfully imported Hugging Face spaces module")
21
+ except ImportError:
22
+ print("WARNING: Could not import Hugging Face spaces module, using fallback implementation")
23
+ class spaces:
24
+ class GPU:
25
+ def __init__(self, duration=60):
26
+ self.duration = duration
27
+ print(f"Created mock GPU decorator with duration {duration}")
28
+ def __call__(self, func):
29
+ print(f"Applied mock GPU decorator to {func.__name__}")
30
+ return func
31
 
32
  print("cd /home/user/app/hy3dgen/texgen/differentiable_renderer/ && bash compile_mesh_painter.sh")
33
  os.system("cd /home/user/app/hy3dgen/texgen/differentiable_renderer/ && bash compile_mesh_painter.sh")
 
44
  class GPU:
45
  def __init__(self, duration=60):
46
  self.duration = duration
47
+ print(f"Created local mock GPU decorator with duration {duration}")
48
  def __call__(self, func):
49
+ print(f"Applied local mock GPU decorator to {func.__name__}")
50
+ return func
51
 
52
  import os
53
  import shutil
 
144
  check_box_rembg: bool,
145
  req: gr.Request,
146
  ):
147
+ print(f"Starting _gen_shape with GPU acceleration, prompt: '{caption}', seed: {seed}")
148
  if caption: print('prompt is', caption)
149
  save_folder = os.path.join(SAVE_DIR, str(req.session_hash))
150
  os.makedirs(save_folder, exist_ok=True)
 
209
  check_box_rembg: bool,
210
  req: gr.Request,
211
  ):
212
+ print(f"Starting generation_all with GPU acceleration, seed: {seed}")
213
  mesh, save_folder, image = _gen_shape(
214
  caption,
215
  image,
 
246
  check_box_rembg: bool,
247
  req: gr.Request,
248
  ):
249
+ print(f"Starting shape_generation with GPU acceleration, seed: {seed}")
250
  mesh, save_folder, image = _gen_shape(
251
  caption,
252
  image,
requirements-hf.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ gradio==4.44.1
2
+ huggingface_hub>=0.16.4
3
+ torch>=2.0.0
4
+ pillow>=9.0.0
5
+ fastapi
6
+ uvicorn
7
+ spaces
run_in_hf.sh ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ echo "Setting up Hunyuan3D-2.0 environment..."
3
+
4
+ # Install custom dependencies
5
+ cd /home/user/app
6
+
7
+ # Print diagnostic information
8
+ echo "Python version:"
9
+ python --version
10
+
11
+ echo "CUDA availability:"
12
+ python -c "import torch; print(f'CUDA available: {torch.cuda.is_available()}')"
13
+ python -c "import torch; print(f'CUDA device count: {torch.cuda.device_count()}')"
14
+ python -c "import torch; print(f'CUDA device name: {torch.cuda.get_device_name(0) if torch.cuda.is_available() else \"N/A\"}')"
15
+
16
+ # Install the required packages
17
+ pip install -r requirements-hf.txt
18
+
19
+ # Install the package in development mode
20
+ pip install -e .
21
+
22
+ echo "Environment setup completed."
setup.py CHANGED
@@ -28,5 +28,13 @@ setup(
28
  name="hy3dgen",
29
  version="2.0.0",
30
  packages=find_packages(),
31
-
 
 
 
 
 
 
 
 
32
  )
 
28
  name="hy3dgen",
29
  version="2.0.0",
30
  packages=find_packages(),
31
+ install_requires=[
32
+ "gradio>=4.0.0",
33
+ "huggingface_hub>=0.16.4",
34
+ "torch>=2.0.0",
35
+ "pillow>=9.0.0",
36
+ "fastapi",
37
+ "uvicorn",
38
+ ],
39
+ python_requires=">=3.8",
40
  )