-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·282 lines (240 loc) · 10.5 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
import chalk from 'chalk';
import { execSync } from 'child_process';
import fse from 'fs-extra';
import path from 'path';
import utils from './utils.js';
import autoInstaller from './workers/auto111Installer.js';
import comfyInstaller from './workers/comfyInstaller.js';
import largeInstaller from './workers/largeInstaller.js';
global.prefs = {
"rootPath": null,
"dataPath": null,
"autoPort": 7860,
"comfyPort": 7861,
"useNVidia": true
}
const directories = [
"custom_nodes",
"output",
"workflows",
"models/checkpoints",
"models/checkpoints/sd",
"models/checkpoints/sdxl",
"models/classifiers",
"models/clip",
"models/clip_vision",
"models/codeformer",
"models/configs",
"models/controlnet",
"models/diffusers",
"models/embeddings",
"models/esrgan",
"models/gfpgan",
"models/hypernetworks",
"models/ipadapter",
"models/ldsr",
"models/loras",
"models/loras/sd",
"models/loras/sdxl",
"models/lycoris",
"models/style_models",
"models/swinir",
"models/realesrgan",
"models/upscale_models",
"models/unet",
"models/vae",
"models/vae_approx"]
// ------------------------------------------------------------------
const onyxFix = async () => {
if(!global.prefs.useNVidia) {
console.log(chalk.magenta("\nUser selected non-nvidia install, skipping cuda driver check.\n"));
return
}
const output = execSync(`"${global.pythonPath}" -c "import torch; print(torch.__version__); print(torch.version.cuda)"`, { encoding: 'utf8' });
if(output.includes("11.8")){
console.log(chalk.magenta(`\nThe proper version of ${chalk.yellow("Cuda for OnyxRuntime")} is installed.\n`));
return;
}
const performFix = await utils.promptConfirmation(`\nFix the ${chalk.yellow("Cuda for OnyxRuntime")} to compatible versions (${chalk.yellow("2.1.1+cu118 and 11.8")})?`);
console.log("");
if(performFix){
console.log("Fixing Cuda and OnyxRuntime...");
execSync(`"${global.pythonPath}" -m pip uninstall torch torchvision torchaudio -y`, { encoding: 'utf8' });
execSync(`"${global.pythonPath}" -m pip install torch==2.1.1+cu118 torchvision==0.16.1+cu118 torchaudio==2.1.1+cu118 -f https://download.pytorch.org/whl/torch_stable.html`, { encoding: 'utf8' });
execSync(`"${global.pythonPath}" -m pip install onnxruntime-gpu`, { encoding: 'utf8' });
await onyxFix();
}
}
// ------------------------------------------------------------------
const prepareEnvironment = async () => {
global.currentPath = process.cwd();
global.prefs = await utils.fetchJson('prefs.json') || global.prefs;
global.jsonData = await utils.fetchJson('config.json');
global.prefs.rootPath = global.prefs.rootPath || path.join(global.currentPath,'genai');
global.prefs.dataPath = global.prefs.dataPath || path.join(global.currentPath,'genai_data');
global.prefs.rootPath = await utils.promptUser(`\nEnter an ${chalk.yellow("absolute")} path for ${chalk.yellow("GenAI Applications")}`, global.prefs.rootPath);
global.prefs.rootPath = global.prefs.rootPath.replace(/["']/g, "");
console.log(`GenAI Path: ${global.prefs.rootPath}`);
global.prefs.dataPath = await utils.promptUser(`\nEnter an ${chalk.yellow("absolute")} path for ${chalk.yellow("GenAI Data")} (large file storage)`, global.prefs.dataPath);
global.prefs.dataPath = global.prefs.dataPath.replace(/["']/g, "");
console.log(`GenAI Data Path: ${global.prefs.dataPath}`);
global.prefs.useNVidia = await utils.promptConfirmation(`\nAre you using an NVidia GPU?`);
console.log(`NVidia GPU Enabled: ${global.prefs.useNVidia}\n`);
global.autoPath = path.join(global.prefs.rootPath, "auto1111")
global.comfyPath = path.join(global.prefs.rootPath, "comfyui")
global.pythonPath = path.join(global.comfyPath,"python_embeded/python.exe");
const prefsString = JSON.stringify(global.prefs, null, 4);
utils.saveFile('prefs.json', prefsString);
utils.makeDir(global.prefs.rootPath);
directories.forEach((item) => {
let myPath = path.join(global.prefs.dataPath, item);
utils.makeDir(myPath);
});
}
// ------------------------------------------------------------------
const installFFMpeg = async () => {
if(utils.ffmpegExists()){
console.log(chalk.yellow("\nFFMpeg already installed."));
if(await utils.promptConfirmation(`Do you want to reinstall ${chalk.yellow("FFMpeg")}?`)){
fse.emptyDirSync(path.join(global.prefs.rootPath, 'ffmpeg'));
}
else {
return;
}
}
console.log("\nFFMpeg not installed. Downloading and installing FFMpeg...");
await utils.downloadFile(global.jsonData.ffmpegInstallUrl, global.currentPath)
.then(filePath => utils.extractZip(filePath, global.currentPath))
.catch(error => console.error(error));
let ffmpegPath = await utils.searchFor(global.currentPath, "ffmpeg")
ffmpegPath = ffmpegPath[0];
await utils.moveItem(path.join(global.currentPath, ffmpegPath, 'bin'), path.join(global.prefs.rootPath, 'ffmpeg'));
fse.removeSync(path.join(global.currentPath, ffmpegPath));
utils.addToSystemPath(path.join(global.prefs.rootPath, 'ffmpeg'));
console.log(`Install complete: ${chalk.yellow("FFMpeg")}`);
}
// ------------------------------------------------------------------
const loadModels = async () => {
let defaultModels = ["embeddings","workflows","vae"];
const sdModels = ["controlnets","checkpoints","loras"];
const sdxlModels = ["controlnetsXL","checkpointsXL","lorasXL"];
showModelMenu();
let input = await utils.promptUser('Enter your choice');
switch(input){
case '1' :
defaultModels = [...defaultModels, ...sdModels];
break;
case '2' :
defaultModels = [...defaultModels, ...sdxlModels];
break;
case '3' :
defaultModels = [...defaultModels, ...sdModels, ...sdxlModels];
break;
default: return;
}
for (const item of defaultModels) {
console.log(chalk.cyan("\nLoading " + item.toLocaleUpperCase()));
try{
await utils.fetchData(global.jsonData[item]);
}
catch(error){
console.log(error);
}
}
console.log(`Install complete: ${chalk.yellow("Model Data")}`);
}
// ------------------------------------------------------------------
const showModelMenu = () => {
console.log(`\nChoose an Option: ${chalk.yellow('(Model Data)')}`);
console.log(`${chalk.yellow('1')}. SD`);
console.log(`${chalk.yellow('2')}. SDXL`);
console.log(`${chalk.yellow('3')}. SD and SDXL`);
console.log(`${chalk.yellow('4')}. Back`);
}
// ------------------------------------------------------------------
const showMainMenu = () => {
const autoMessage = autoInstaller.isInstalled() ? `${chalk.green('Re-Install')}` : `Install`;
const comfyMessage = comfyInstaller.isInstalled() ? `${chalk.green('Re-Install')}` : `Install`;
const nodeMessage = comfyInstaller.nodesInstalled() ? `${chalk.green('Re-Install')}` : `Install`;
const ffmpegMessage = utils.ffmpegExists() ? `${chalk.green('Re-Install')}` : `Install`;
console.log(chalk.gray("\nData from config.json"));
console.log(`\nChoose an Option:`);
console.log(`${chalk.yellow('1')}. ${autoMessage} Automatic1111`);
console.log(`${chalk.yellow('2')}. ${comfyMessage} ComfyUI`);
console.log(`${chalk.yellow('3')}. ${nodeMessage} Custom Nodes`);
console.log(`${chalk.yellow('4')}. Load Models...`);
console.log(`${chalk.yellow('5')}. Large Installs...`);
console.log(`${chalk.yellow('6')}. ${ffmpegMessage} FFMpeg (admin)`);
console.log(`${chalk.yellow('7')}. Onyx Runtime Fix`);
console.log(`${chalk.yellow('8')}. Create ComfyUI Symlinks (needed after update)`);
console.log(`${chalk.yellow('9')}. Exit`);
}
// ------------------------------------------------------------------
const handleUserInput = async (input) => {
const admin = ['6'];
input = input.trim();
if(admin.includes(input) && !utils.isAdministrator()){
console.log(chalk.red(`This command requires ${chalk.yellow("administrative privileges")}. Please rerun this script as ${chalk.yellow("administrator")}.`))
input = 'admin';
}
if(input!='8' && !admin.includes(input) && utils.isAdministrator()){
console.log(chalk.red(`This command should be run as a normal user. Please rerun this script without ${chalk.yellow("administrative privileges")}.`))
input = 'admin';
}
switch (input) {
case '1':
await autoInstaller.install();
break;
case '2':
await comfyInstaller.install();
break;
case '3':
await comfyInstaller.installCustomNodes();
break;
case '4':
await loadModels();
break;
case '5':
await largeInstaller.install();
break;
case '6':
await installFFMpeg();
break;
case '7':
await onyxFix();
break;
case '8':
comfyInstaller.makeSymlinks();
break;
case '9':
return;
case 'admin':
// Empty Case, used to recover after administrative messages
break;
default:
console.log('Invalid option, please enter 1-9');
}
showMainMenu();
await waitForUserInput();
}
// ------------------------------------------------------------------
const waitForUserInput = async () => {
const input = await utils.promptUser('Enter your choice')
await handleUserInput(input);
}
// ------------------------------------------------------------------
await prepareEnvironment();
// await utils.fetchData(global.jsonData["embeddings"]);
// await utils.fetchJson(`https://civitai.com/api/v1/models/257448`)
// import nodeInstaller from './workers/nodeInstaller.js';
// await nodeInstaller.install("custom");
// const item = {
// "type": "civitai",
// "path": "models/checkpoints/sd",
// "note": "Analog Madness",
// "modelId": 8030
// }
// utils.downloadCivitai(item);
showMainMenu();
await waitForUserInput();
console.log("Happy Generating\n");