Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,172 +1,57 @@
|
|
1 |
import shlex
|
2 |
import subprocess
|
3 |
-
import os
|
4 |
-
import sys
|
5 |
-
import logging
|
6 |
-
from pathlib import Path
|
7 |
-
from huggingface_hub import snapshot_download
|
8 |
-
from huggingface_hub.utils import RepositoryNotFoundError
|
9 |
-
import torch
|
10 |
-
import fire
|
11 |
-
import gradio as gr
|
12 |
-
from gradio_app.gradio_3dgen import create_ui as create_3d_ui
|
13 |
-
from gradio_app.all_models import model_zoo
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
)
|
20 |
-
logger = logging.getLogger(__name__)
|
21 |
|
22 |
-
def install_requirements():
|
23 |
-
"""Install requirements from requirements.txt"""
|
24 |
-
requirements = """
|
25 |
-
pytorch3d @ https://dl.fbaipublicfiles.com/pytorch3d/packaging/wheels/py310_cu121_pyt221/pytorch3d-0.7.6-cp310-cp310-linux_x86_64.whl
|
26 |
-
ort_nightly_gpu @ https://aiinfra.pkgs.visualstudio.com/2692857e-05ef-43b4-ba9c-ccf1c22c437c/_packaging/d3daa2b0-aa56-45ac-8145-2c3dc0661c87/pypi/download/ort-nightly-gpu/1.17.dev20240118002/ort_nightly_gpu-1.17.0.dev20240118002-cp310-cp310-manylinux_2_28_x86_64.whl
|
27 |
-
onnxruntime_gpu @ https://pkgs.dev.azure.com/onnxruntime/2a773b67-e88b-4c7f-9fc0-87d31fea8ef2/_packaging/7fa31e42-5da1-4e84-a664-f2b4129c7d45/pypi/download/onnxruntime-gpu/1.17/onnxruntime_gpu-1.17.0-cp310-cp310-manylinux_2_28_x86_64.whl
|
28 |
-
torch==2.2.0
|
29 |
-
accelerate
|
30 |
-
datasets
|
31 |
-
diffusers>=0.26.3
|
32 |
-
fire
|
33 |
-
gradio
|
34 |
-
jax
|
35 |
-
typing
|
36 |
-
numba
|
37 |
-
numpy<2
|
38 |
-
omegaconf>=2.3.0
|
39 |
-
opencv_python
|
40 |
-
opencv_python_headless
|
41 |
-
peft
|
42 |
-
Pillow
|
43 |
-
pygltflib
|
44 |
-
pymeshlab>=2023.12
|
45 |
-
rembg[gpu]
|
46 |
-
torch_scatter @ https://data.pyg.org/whl/torch-2.2.0%2Bcu121/torch_scatter-2.1.2%2Bpt22cu121-cp310-cp310-linux_x86_64.whl
|
47 |
-
tqdm
|
48 |
-
transformers
|
49 |
-
trimesh
|
50 |
-
typeguard
|
51 |
-
wandb
|
52 |
-
xformers
|
53 |
-
ninja
|
54 |
-
""".strip()
|
55 |
-
|
56 |
-
# Write requirements to file
|
57 |
-
with open("requirements.txt", "w") as f:
|
58 |
-
f.write(requirements)
|
59 |
-
|
60 |
-
try:
|
61 |
-
logger.info("Installing requirements...")
|
62 |
-
subprocess.run(
|
63 |
-
[sys.executable, "-m", "pip", "install", "-r", "requirements.txt"],
|
64 |
-
check=True
|
65 |
-
)
|
66 |
-
logger.info("Requirements installed successfully")
|
67 |
-
except subprocess.CalledProcessError as e:
|
68 |
-
logger.error(f"Failed to install requirements: {str(e)}")
|
69 |
-
raise
|
70 |
|
71 |
-
|
72 |
-
|
73 |
-
try:
|
74 |
-
logger.info("Installing dependencies...")
|
75 |
-
install_requirements()
|
76 |
-
|
77 |
-
# Define package paths
|
78 |
-
packages = [
|
79 |
-
"package/onnxruntime_gpu-1.17.0-cp310-cp310-manylinux_2_28_x86_64.whl",
|
80 |
-
"package/nvdiffrast-0.3.1.torch-cp310-cp310-linux_x86_64.whl"
|
81 |
-
]
|
82 |
-
|
83 |
-
# Check if package files exist
|
84 |
-
for package in packages:
|
85 |
-
if not Path(package).exists():
|
86 |
-
raise FileNotFoundError(f"Package file not found: {package}")
|
87 |
-
|
88 |
-
logger.info(f"Installing {package}")
|
89 |
-
subprocess.run(
|
90 |
-
shlex.split(f"pip install {package} --force-reinstall --no-deps"),
|
91 |
-
check=True
|
92 |
-
)
|
93 |
-
|
94 |
-
logger.info("Dependencies installed successfully")
|
95 |
-
except subprocess.CalledProcessError as e:
|
96 |
-
logger.error(f"Failed to install dependencies: {str(e)}")
|
97 |
-
raise
|
98 |
-
except FileNotFoundError as e:
|
99 |
-
logger.error(str(e))
|
100 |
-
raise
|
101 |
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
snapshot_download(
|
117 |
-
"public-data/Unique3D",
|
118 |
-
repo_type="model",
|
119 |
-
local_dir=str(ckpt_dir),
|
120 |
-
token=os.getenv("HF_TOKEN"),
|
121 |
-
local_files_only=False
|
122 |
-
)
|
123 |
-
except Exception as e:
|
124 |
-
logger.error(f"Failed to download model: {str(e)}")
|
125 |
-
logger.info("Checking for local model files...")
|
126 |
-
if not (model_path / "config.json").exists():
|
127 |
-
raise RuntimeError(
|
128 |
-
"Model not found locally and download failed. "
|
129 |
-
"Please ensure you have the model files in ./ckpt/img2mvimg"
|
130 |
-
)
|
131 |
-
|
132 |
-
# Configure PyTorch settings
|
133 |
-
torch.set_float32_matmul_precision('medium')
|
134 |
-
torch.backends.cuda.matmul.allow_tf32 = True
|
135 |
-
torch.set_grad_enabled(False)
|
136 |
-
|
137 |
-
logger.info("Model setup completed successfully")
|
138 |
-
except Exception as e:
|
139 |
-
logger.error(f"Error during model setup: {str(e)}")
|
140 |
-
raise
|
141 |
|
142 |
-
|
143 |
-
_TITLE = 'Text to 3D'
|
|
|
|
|
144 |
|
145 |
def launch():
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
with gr.
|
153 |
-
with gr.
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
demo.queue().launch(share=True)
|
159 |
-
except Exception as e:
|
160 |
-
logger.error(f"Error launching application: {str(e)}")
|
161 |
-
raise
|
162 |
|
|
|
|
|
163 |
if __name__ == '__main__':
|
164 |
-
|
165 |
-
logger.info("Starting application setup...")
|
166 |
-
setup_dependencies()
|
167 |
-
sys.path.append(os.curdir)
|
168 |
-
setup_model()
|
169 |
-
fire.Fire(launch)
|
170 |
-
except Exception as e:
|
171 |
-
logger.error(f"Application startup failed: {str(e)}")
|
172 |
-
sys.exit(1)
|
|
|
1 |
import shlex
|
2 |
import subprocess
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
|
5 |
+
subprocess.run(shlex.split("pip install pip==24.0"), check=True)
|
6 |
+
subprocess.run(
|
7 |
+
shlex.split(
|
8 |
+
"pip install package/onnxruntime_gpu-1.17.0-cp310-cp310-manylinux_2_28_x86_64.whl --force-reinstall --no-deps"
|
9 |
+
), check=True
|
10 |
+
)
|
11 |
+
subprocess.run(
|
12 |
+
shlex.split(
|
13 |
+
"pip install package/nvdiffrast-0.3.1.torch-cp310-cp310-linux_x86_64.whl --force-reinstall --no-deps"
|
14 |
+
), check=True
|
15 |
)
|
|
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
+
if __name__ == "__main__":
|
19 |
+
from huggingface_hub import snapshot_download
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
snapshot_download("public-data/Unique3D", repo_type="model", local_dir="./ckpt")
|
22 |
+
|
23 |
+
import os
|
24 |
+
import sys
|
25 |
+
sys.path.append(os.curdir)
|
26 |
+
import torch
|
27 |
+
torch.set_float32_matmul_precision('medium')
|
28 |
+
torch.backends.cuda.matmul.allow_tf32 = True
|
29 |
+
torch.set_grad_enabled(False)
|
30 |
+
|
31 |
+
import fire
|
32 |
+
import gradio as gr
|
33 |
+
from gradio_app.gradio_3dgen import create_ui as create_3d_ui
|
34 |
+
from gradio_app.all_models import model_zoo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
+
|
37 |
+
_TITLE = '''Text to 3D'''
|
38 |
+
_DESCRIPTION = '''
|
39 |
+
Text to 3D'''
|
40 |
|
41 |
def launch():
|
42 |
+
model_zoo.init_models()
|
43 |
+
|
44 |
+
with gr.Blocks(
|
45 |
+
title=_TITLE,
|
46 |
+
# theme=gr.themes.Monochrome(),
|
47 |
+
) as demo:
|
48 |
+
with gr.Row():
|
49 |
+
with gr.Column(scale=1):
|
50 |
+
gr.Markdown('# ' + _TITLE)
|
51 |
+
gr.Markdown(_DESCRIPTION)
|
52 |
+
create_3d_ui("wkl")
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
+
demo.queue().launch(share=True)
|
55 |
+
|
56 |
if __name__ == '__main__':
|
57 |
+
fire.Fire(launch)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|