-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoRA_inspector.bat
329 lines (246 loc) · 6.85 KB
/
LoRA_inspector.bat
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
@ECHO OFF
IF NOT EXIST "lora-inspector.py" (
ECHO[
ECHO File does not exist, or this batch was ran from another folder:
ECHO lora-inspector.py
ECHO[
PAUSE
GOTO endOfLine
)
IF NOT EXIST "LoRA_inspector_helper.vbs" (
ECHO[
ECHO File does not exist, or this batch was ran from another folder:
ECHO LoRA_inspector_helper.vbs
ECHO[
PAUSE
GOTO endOfLine
)
IF NOT EXIST "%UserProfile%\AppData\Local\RTools" MKDIR "%UserProfile%\AppData\Local\RTools"
IF EXIST "%UserProfile%\AppData\Local\RTools\Booted.txt" GOTO BOOTED
Start /Separate conhost LoRA_inspector.bat
> "%UserProfile%\AppData\Local\RTools\Booted.txt" ECHO booted
EXIT
:BOOTED
TITLE LoRA_inspector
Set folderPath=NULL
:ROOT
Set afterFolderAsk=ROOT
cls
ECHO[
ECHO LoRA inspector -^> ROOT MENU
ECHO[
ECHO LoRA path:
ECHO %folderPath%
ECHO[
ECHO f. Set/change the path to the LoRA file or folder with LoRA's
ECHO[
ECHO 1. Inspect (find the average weights)
ECHO 2. Inspect (find the average weights) ^> THEN EXIT SO YOU CAN COPY-PASTE
ECHO 3. Save Metadata to JSON file^(s^)
ECHO[
Set Choice=
Set /p Choice=Type the option and press enter (exit to quit):
IF /I "%Choice%"=="exit" GOTO endOfLine
Set exitAfter=False
IF /I "%Choice%"=="f" GOTO rootGetFolderPath
IF /I "%Choice%"=="1" GOTO inspectLoras
IF /I "%Choice%"=="2" GOTO inspectLorasCheckExisting
IF /I "%Choice%"=="3" GOTO saveMetadataToFiles
ECHO[
ECHO "%Choice%" is invalid. Please try again.
ECHO[
PAUSE
GOTO ROOT
:rootGetFolderPath
cls
ECHO[
ECHO LoRA inspector -^> GET LORA PATH OR FOLDER WITH LoRA FILE^(S^)
ECHO[
ECHO Enter the full path to the Lora File, or the folder with LoRA files.
ECHO ^*^*^*^*^* make sure there are no double-quotes! ^*^*^*^*^*
ECHO enter x or ROOT to go to ROOT MENU
ECHO enter exit to go to quit
ECHO[
Set /P Choice=:
IF /I "%Choice%"=="x" GOTO ROOT
IF /I "%Choice%"=="root" GOTO ROOT
IF /I "%Choice%"=="exit" GOTO endOfLine
IF NOT EXIST "%Choice%" GOTO rootNofolderPath
Set folderPath=%Choice%
Set Choice=
GOTO %afterFolderAsk%
:rootNofolderPath
ECHO[
ECHO ERROR: Could not find a file or folder with this path:
ECHO %Choice%
Set Choice=
ECHO[
PAUSE
GOTO rootGetFolderPath
REM *****************************************************************************
REM ***** INSPECT LORAS *****
:inspectLorasCheckExisting
REM @ECHO ON
cls
ECHO[
ECHO LoRA inspector -^> INSPECT LORA^(s^)
ECHO[
set X=0
IF EXIST "LoRA_average_weights.txt" set /a X+=1
IF EXIST "LoRA_average_weights.csv" set /a X+=1
IF EXIST "LoRA_average_weights.bat" set /a X+=1
REM no previous files exist
IF "%X%"=="0" (
Set X=
Set exitAfter=True
GOTO inspectLoras
)
ECHO ***** WARNING *****
ECHO[
IF "%X%"=="1" (
ECHO 1 file exists from a previous run and will be deleted if you proceed:
) ELSE (
ECHO %X% files exist from a previous run and will be deleted if you proceed:
)
ECHO[
IF EXIST "LoRA_average_weights.txt" ECHO LoRA_average_weights.txt
IF EXIST "LoRA_average_weights.csv" ECHO LoRA_average_weights.csv
IF EXIST "LoRA_average_weights.bat" ECHO LoRA_average_weights.txt
ECHO[
ECHO NOTE: If you don't want to delete the file(s), rename the file(s)
ECHO that you want to keep before running this option.
ECHO[
Set YN=
REM IF "%X%"=="1" (
Set /P YN=Do you want to delete the file(s) and continue? (Y/N, X = cancel, exit = quit):
REM ) ELSE (
REM Set /P YN=Do you want to delete the files and continue? (Y/N, X = cancel, exit = quit):
REM )
ECHO[
IF /I "%YN%"=="Y" (
DEL "LoRA_average_weights.*" /F /Q
Set exitAfter=True
GOTO inspectLoras
)
IF /I "%YN%"=="N" GOTO ROOT
IF /I "%YN%"=="X" GOTO ROOT
IF /I "%YN%"=="exit" GOTO endOfLine
ECHO[
ECHO "%YN$" is invalid. Please try again.
ECHO[
PAUSE
GOTO inspectLorasCheckExisting
PAUSE
GOTO ROOT
REM ***** INSPECT LORAS *****
:inspectLoras
Set afterFolderAsk=inspectLoras
cls
ECHO[
ECHO ECHO LoRA inspector -^> INSPECT LORA^(s^)
ECHO[
ECHO path:
ECHO %folderPath%
ECHO[
IF /I "%folderPath%"=="NULL" GOTO rootGetFolderPath
REM IF "%folderPath%"=="" GOTO rootGetFolderPath
IF "%exitAfter%"=="True" GOTO inspectLorasAskYN
:inspectLorasNow
CLS
ECHO[
python.exe "lora-inspector.py" -w "%folderPath%"
ECHO[
cscript.exe //NOLOGO LoRA_inspector_helper.vbs
ECHO[
IF "%exitAfter%"=="True" GOTO endOfLine
PAUSE
goto ROOT
:inspectLorasAskYN
cls
ECHO[
ECHO ***** NOTICE: THE SCRIPT TAKES AWHILE FOR MANY LoRA's, DO NOT CLOSE THIS WINDOW *****
ECHO[
ECHO Instructions:
ECHO 1. Run this on a folder with LoRA files in it
ECHO 2. When it is done, press Ctr+A to select all, then Ctrl+C to copy
ECHO 3. Open LoRA_average_weights.txt and press Ctrl+V to paste
ECHO 4. Run LoRA_inspector_helper.vbs to create the CSV and batch file
ECHO[
ECHO NOTE- if you don't have LoRA_average_weights.txt yet, simply
ECHO run LoRA_inspector_helper.vbs to create it
ECHO[
Set YN=
Set /P YN=Are you sure you want to continue? (Y/N, X = cancel, exit = quit):
ECHO[
IF /I "%YN%"=="Y" GOTO inspectLorasNow
IF /I "%YN%"=="N" GOTO ROOT
IF /I "%YN%"=="X" GOTO ROOT
IF /I "%YN%"=="exit" GOTO endOfLine
ECHO[
ECHO "%YN%" is invalid. Please try again.
ECHO[
PAUSE
GOTO inspectLorasAskYN
REM ***** SAVE METADATA TO FILES *****
:saveMetadataToFiles
Set afterFolderAsk=saveMetadataToFiles
cls
ECHO[
ECHO ECHO LoRA inspector -^> SAVE METADATA TO FILE^(S^)
ECHO[
ECHO path:
ECHO %folderPath%
ECHO[
IF /I "%folderPath%"=="NULL" GOTO rootGetFolderPath
IF "%folderPath%"=="" GOTO rootGetFolderPath
python.exe "lora-inspector.py" -s "%folderPath%"
ECHO[
@ECHO OFF
ECHO[
ECHO formatting JSON file^(s^)...
ECHO[
cscript.exe //NOLOGO "LoRA_inspector_helper.vbs" 1
ECHO[
PAUSE
:saveMetadataToFilesAskMove
cls
ECHO[
ECHO ECHO LoRA inspector -^> metdadata saved -^> OPTION TO MOVE FILE^(S^)
ECHO[
ECHO ***** Now you have the option to move the file^(s^) *****
ECHO[
Set YN=
ECHO Do you want to move the formatted JSON file^(s^) to the LoRA folder,
ECHO and rename them to match the LoRA file^(s^)?
Set /P YN=Type the option and press enter (Y/N, X = cancel, exit = quit):
ECHO[
IF /I "%YN%"=="Y" GOTO saveMetadataToFilesMoveTheFiles
IF /I "%YN%"=="N" GOTO ROOT
IF /I "%YN%"=="X" GOTO ROOT
IF /I "%YN%"=="exit" GOTO endOfLine
ECHO[
ECHO "%YN%" is invalid. Please try again.
ECHO[
PAUSE
GOTO saveMetadataToFilesAskMove
:saveMetadataToFilesMoveTheFiles
cls
ECHO[
ECHO ECHO LoRA inspector -^> metdadata saved -^> MOVING FILE^(S^)
ECHO[
cscript.exe //NOLOGO "LoRA_inspector_helper.vbs" "%folderPath%"
ECHO[
PAUSE
GOTO ROOT
:endOfLine
SET exitAfter=
SET YN=
SET Choice=
SET folderPath=
SET var=
SET valid=
SET count=
SET afterFolderAsk=
SET X=
@ECHO ON
CALL cmd.exe /k