jree423 commited on
Commit
d8d7713
·
verified ·
1 Parent(s): 5216f49

Upload DiffSketcher/setup.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. DiffSketcher/setup.py +184 -0
DiffSketcher/setup.py ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright (c) XiMing Xing. All rights reserved.
3
+ # Author: XiMing Xing
4
+
5
+ import os
6
+ import subprocess
7
+ import sys
8
+ from setuptools import setup, find_packages
9
+ from setuptools.command.install import install
10
+ from setuptools.command.develop import develop
11
+ from setuptools.command.egg_info import egg_info
12
+
13
+
14
+ class CustomInstallCommand(install):
15
+ """Custom installation command to handle dependencies and CUDA setup"""
16
+
17
+ def run(self):
18
+ self.install_dependencies()
19
+ install.run(self)
20
+
21
+ def install_dependencies(self):
22
+ try:
23
+ self._check_requirements()
24
+ self._setup_cuda()
25
+ self._install_pytorch()
26
+ self._install_python_deps()
27
+ self._install_diffvg()
28
+ except Exception as e:
29
+ print(f"\033[91mError during installation: {str(e)}\033[0m")
30
+ sys.exit(1)
31
+
32
+ def _check_requirements(self):
33
+ """Check system requirements"""
34
+ print("\033[92mChecking system requirements...\033[0m")
35
+
36
+ # Check conda
37
+ try:
38
+ import conda
39
+ except ImportError:
40
+ raise RuntimeError("Conda is required. Please install Conda first.")
41
+
42
+ # Check git
43
+ if subprocess.call(['which', 'git'], stdout=subprocess.PIPE) != 0:
44
+ raise RuntimeError("Git is required. Please install Git first.")
45
+
46
+ def _setup_cuda(self):
47
+ """Check CUDA availability"""
48
+ print("\033[92mChecking CUDA availability...\033[0m")
49
+
50
+ try:
51
+ subprocess.check_output(['nvidia-smi'])
52
+ self.cuda_available = True
53
+ print("CUDA is available")
54
+ except:
55
+ self.cuda_available = False
56
+ print("\033[93mCUDA not available. Installing CPU-only version.\033[0m")
57
+
58
+ def _install_pytorch(self):
59
+ """Install PyTorch and related packages"""
60
+ print("\033[92mInstalling PyTorch...\033[0m")
61
+
62
+ if self.cuda_available:
63
+ pytorch_cmd = [
64
+ 'conda', 'install', '-y',
65
+ 'pytorch==1.12.1',
66
+ 'torchvision==0.13.1',
67
+ 'torchaudio==0.12.1',
68
+ 'cudatoolkit=11.3',
69
+ '-c', 'pytorch'
70
+ ]
71
+ else:
72
+ pytorch_cmd = [
73
+ 'conda', 'install', '-y',
74
+ 'pytorch==1.12.1',
75
+ 'torchvision==0.13.1',
76
+ 'torchaudio==0.12.1',
77
+ 'cpuonly',
78
+ '-c', 'pytorch'
79
+ ]
80
+
81
+ subprocess.check_call(pytorch_cmd)
82
+
83
+ try:
84
+ subprocess.check_call([
85
+ 'conda', 'install', '-y', 'xformers',
86
+ '-c', 'xformers'
87
+ ])
88
+ except:
89
+ print("\033[93mWarning: Failed to install xformers\033[0m")
90
+
91
+ def _install_python_deps(self):
92
+ """Install Python dependencies"""
93
+ print("\033[92mInstalling Python dependencies...\033[0m")
94
+
95
+ pip_packages = [
96
+ 'hydra-core', 'omegaconf',
97
+ 'freetype-py', 'shapely', 'svgutils',
98
+ 'opencv-python', 'scikit-image', 'matplotlib', 'visdom', 'wandb', 'beautifulsoup4',
99
+ 'triton', 'numba',
100
+ 'numpy', 'scipy', 'scikit-fmm', 'einops', 'timm', 'fairscale==0.4.13',
101
+ 'accelerate', 'transformers', 'safetensors', 'datasets',
102
+ 'easydict', 'scikit-learn', 'pytorch_lightning==2.1.0', 'webdataset',
103
+ 'ftfy', 'regex', 'tqdm',
104
+ 'diffusers==0.20.2',
105
+ 'svgwrite', 'svgpathtools', 'cssutils', 'torch-tools'
106
+ ]
107
+
108
+ for package in pip_packages:
109
+ try:
110
+ subprocess.check_call([sys.executable, '-m', 'pip', 'install', package])
111
+ except:
112
+ print(f"\033[93mWarning: Failed to install {package}\033[0m")
113
+
114
+ # Install CLIP
115
+ try:
116
+ subprocess.check_call([
117
+ sys.executable, '-m', 'pip', 'install',
118
+ 'git+https://github.com/openai/CLIP.git'
119
+ ])
120
+ except:
121
+ print("\033[93mWarning: Failed to install CLIP\033[0m")
122
+
123
+ def _install_diffvg(self):
124
+ """Install DiffVG"""
125
+ print("\033[92mInstalling DiffVG...\033[0m")
126
+
127
+ if not os.path.exists('diffvg'):
128
+ subprocess.check_call(['git', 'clone', 'https://github.com/BachiLi/diffvg.git'])
129
+
130
+ os.chdir('diffvg')
131
+ subprocess.check_call(['git', 'submodule', 'update', '--init', '--recursive'])
132
+
133
+ # Install system dependencies on Linux
134
+ if sys.platform.startswith('linux'):
135
+ try:
136
+ subprocess.check_call([
137
+ 'sudo', 'apt', 'update'
138
+ ])
139
+ subprocess.check_call([
140
+ 'sudo', 'apt', 'install', '-y',
141
+ 'cmake', 'ffmpeg', 'build-essential',
142
+ 'libjpeg-dev', 'libpng-dev', 'libtiff-dev'
143
+ ])
144
+ except:
145
+ print("\033[93mWarning: Failed to install system dependencies\033[0m")
146
+
147
+ # Install conda dependencies
148
+ subprocess.check_call(['conda', 'install', '-y', '-c', 'anaconda', 'cmake'])
149
+ subprocess.check_call(['conda', 'install', '-y', '-c', 'conda-forge', 'ffmpeg'])
150
+
151
+ # Build and install DiffVG
152
+ subprocess.check_call([sys.executable, 'setup.py', 'install'])
153
+ os.chdir('..')
154
+
155
+
156
+ setup(
157
+ name="DiffSketcher",
158
+ version="0.1.0",
159
+ packages=find_packages(),
160
+ install_requires=[
161
+ # Base dependencies will be handled by custom install command
162
+ ],
163
+ python_requires=">=3.7",
164
+ cmdclass={
165
+ 'install': CustomInstallCommand,
166
+ },
167
+ # Metadata
168
+ author='XiMing Xing',
169
+ author_email='[email protected]',
170
+ description="DiffSketcher: Text Guided Vector Sketch Synthesis through Latent Diffusion Models",
171
+ long_description=open("README.md").read() if os.path.exists("README.md") else "",
172
+ long_description_content_type="text/markdown",
173
+ keywords="svg, rendering, diffvg",
174
+ url='https://github.com/ximinng/DiffSketcher',
175
+ classifiers=[
176
+ "Development Status :: 3 - Alpha",
177
+ "Intended Audience :: Developers",
178
+ "Programming Language :: Python :: 3",
179
+ "Programming Language :: Python :: 3.7",
180
+ "Programming Language :: Python :: 3.8",
181
+ "Programming Language :: Python :: 3.9",
182
+ "Programming Language :: Python :: 3.10",
183
+ ],
184
+ )