Blackwolf2 commited on
Commit
aae0d40
·
1 Parent(s): cc5d442

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +112 -0
app.py ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+ import platform
3
+ import subprocess
4
+
5
+
6
+ def pip_install_packages(packages, extra_index_url=None, verbose=False, pre=False):
7
+ for package in packages:
8
+ try:
9
+ print(f"..installing {package}")
10
+
11
+ # base command
12
+ cmd = ["pip", "install"]
13
+
14
+ if pre:
15
+ cmd.append("--pre")
16
+
17
+ # add '-q' if not verbose
18
+ if not verbose:
19
+ cmd.append("-q")
20
+
21
+ # add package name
22
+ cmd.append(package)
23
+
24
+ # add extra_index_url if it exists
25
+ if extra_index_url:
26
+ cmd.extend(["--extra-index-url", extra_index_url])
27
+
28
+ if verbose:
29
+ print(cmd)
30
+
31
+ # run the command and capture output
32
+ result = subprocess.run(cmd, capture_output=not verbose, text=True)
33
+
34
+ if verbose:
35
+ # print stdout and stderr if verbose
36
+ print(result.stdout)
37
+ print(result.stderr)
38
+
39
+ except Exception as e:
40
+ print(f"failed to install {package}: {e}")
41
+ return
42
+
43
+
44
+ def install_requirements(verbose=False):
45
+
46
+ # Detect System
47
+ os_system = platform.system()
48
+ print(f"system detected: {os_system}")
49
+
50
+ # Install pytorch
51
+ torch = [
52
+ "torch",
53
+ "torchvision",
54
+ "torchaudio"
55
+ ]
56
+ extra_index_url = "https://download.pytorch.org/whl/nightly/cu121"
57
+ pip_install_packages(torch, extra_index_url=extra_index_url, verbose=verbose, pre=True)
58
+
59
+ # List of common packages to install
60
+ common = [
61
+ "clean-fid",
62
+ "colab-convert",
63
+ "einops",
64
+ "ftfy",
65
+ "ipython",
66
+ "ipywidgets",
67
+ "jsonmerge",
68
+ "jupyterlab",
69
+ "jupyter_http_over_ws",
70
+ "kornia",
71
+ "matplotlib",
72
+ "notebook",
73
+ "numexpr",
74
+ "omegaconf",
75
+ "opencv-python",
76
+ "pandas",
77
+ "pytorch_lightning==1.7.7",
78
+ "resize-right",
79
+ "scikit-image==0.19.3",
80
+ "scikit-learn",
81
+ "timm",
82
+ "torchdiffeq",
83
+ "transformers==4.19.2",
84
+ "safetensors",
85
+ "albumentations",
86
+ "more_itertools",
87
+ "devtools",
88
+ "validators",
89
+ "numpngw",
90
+ "open-clip-torch",
91
+ "torchsde",
92
+ "ninja",
93
+ "pydantic",
94
+ ]
95
+ pip_install_packages(common)
96
+
97
+ # Xformers install
98
+ linux_xformers = [
99
+ "triton",
100
+ "xformers==0.0.21.dev546",
101
+ ]
102
+ windows_xformers = [
103
+ "xformers==0.0.21.dev546",
104
+ ]
105
+ xformers = windows_xformers if os_system == 'Windows' else linux_xformers
106
+ pip_install_packages(xformers)
107
+
108
+ if __name__ == "__main__":
109
+ parser = argparse.ArgumentParser()
110
+ parser.add_argument('--verbose', action='store_true', help='print pip install stuff')
111
+ args = parser.parse_args()
112
+ install_requirements(verbose=args.verbose)