magicfixeseverything commited on
Commit
cc80c12
1 Parent(s): af3ca30

Upload 6 files

Browse files
Files changed (4) hide show
  1. AI Image Creation.lnk +0 -0
  2. Instructions.txt +452 -0
  3. ai_image_creation.bat +8 -0
  4. app.py +3 -21
AI Image Creation.lnk ADDED
Binary file (1.41 kB). View file
 
Instructions.txt ADDED
@@ -0,0 +1,452 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ AI Image Creation Offline on Windows using NVIDIA GPU
3
+
4
+ About installing Diffusers in a virtual environment:
5
+ https://huggingface.co/docs/diffusers/installation
6
+ But I include the instructions on what you need to do below.
7
+
8
+ ---
9
+
10
+ I am still working on this. (note added December 7th, 2023) I am very new to
11
+ this, so I'm sure there are many ways this could be done better.
12
+
13
+ ---
14
+
15
+ You must have a NVIDIA graphics card with Cuda installed. I already had Cuda
16
+ installed. If you need Cuda, it's in a step below. This script is written to
17
+ be used on my Windows computer using the GPU. This script will not work
18
+ using a CPU. While there is code in the script for CPU usage, it doesn't
19
+ work on a Windows computer. It might be related to the Triton module not
20
+ being available in Windows. There seem to be something that might work, but
21
+ it would have meant installing something from elsewhere that I was not
22
+ willing to try.
23
+
24
+ The version of CUDA might matter. If you have one that doesn't work, you
25
+ might have to install a different version of CUDA.
26
+
27
+ If you have installed Automatic1111, you don't need to do step 1 and 2 as
28
+ that program required Python and Git. You don't need Automatic1111 installed
29
+ to use this program.
30
+
31
+ About Automatic1111:
32
+
33
+ https://github.com/AUTOMATIC1111/stable-diffusion-webui#installation-and-running
34
+
35
+ Your Antivirus/Firewall software will need to be set to allow the command
36
+ prompt to download and install these programs. What you allow or don't allow
37
+ is up to you. You may need to reinstall some of it if you don't allow it
38
+ through the first time and it doesn't work for you. I don't know what the
39
+ minimum you need to allow would be, or if some or all of it can operate in a
40
+ sandboxed environment.
41
+
42
+ ---
43
+
44
+ Step 1 (if you haven't done already):
45
+
46
+ Install Python 3.10.6:
47
+
48
+ https://www.python.org/ftp/python/3.10.6/python-3.10.6-amd64.exe
49
+
50
+ Make sure to check "Add Python to PATH"
51
+
52
+ ---
53
+
54
+ Step 2 (if you haven't done already):
55
+
56
+ Install git
57
+
58
+ https://git-scm.com/download/win
59
+
60
+ ---
61
+
62
+ Step 3:
63
+
64
+ Create directory manually:
65
+
66
+ C:/Diffusers
67
+
68
+ This can be anywhere, but if you change it here you need to change it in all
69
+ the other places in these instructions and in some of the files you
70
+ download.
71
+
72
+ ---
73
+
74
+ Step 4:
75
+
76
+ You need to open a regular Command Prompt. You can press Win key + R to get
77
+ "Run" window. In that, enter:
78
+
79
+ cmd
80
+
81
+ In Command Prompt, copy this line and press Enter:
82
+
83
+ cd C:\Diffusers && py -m venv .venv && .venv\Scripts\activate.bat
84
+
85
+ This will change the directory of the command prompt to the directory you
86
+ created. Next, it creates a virtual environment for Python as described
87
+ here:
88
+
89
+ https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/
90
+
91
+ Finally, it activates that virtual environment as also described there.
92
+
93
+ The command prompt will now look like this:
94
+
95
+ (.venv) C:\Diffusers>
96
+
97
+ You don't need to reopen the Command Prompt each time. Wait until a task
98
+ finishes and then you will be able to enter the next command. It's best you
99
+ do not close it.
100
+
101
+ If you do close it, you will need to go to the directory again each time and
102
+ activate the virtual environment like this, by copying this and pressing
103
+ Enter:
104
+
105
+ cd C:\Diffusers && .venv\Scripts\activate.bat
106
+
107
+ You do not want to install Python packages outside of the virtual
108
+ environment as it would replace the packages in your main installation. That
109
+ could cause conflicts in other programs.
110
+
111
+ Always make sure you have:
112
+
113
+ (.venv) C:\Diffusers>
114
+
115
+ In future steps. (though I have added the code to activate it every time as
116
+ a precaution)
117
+
118
+ ---
119
+
120
+ Step 5 (optional):
121
+
122
+ pip is the package installer for Python.
123
+
124
+ If you want to make sure pip is up-to-date, in Command Prompt (that is doing
125
+ things in your virtual environment), copy this line and press Enter:
126
+
127
+ cd C:\Diffusers && .venv\Scripts\activate.bat && py -m pip install --upgrade pip
128
+
129
+ If you want to then verify it updated, you could optionally do this, in
130
+ Command Prompt, copy this line and press Enter:
131
+
132
+ cd C:\Diffusers && .venv\Scripts\activate.bat && py -m pip --version
133
+
134
+ Since you are using a virtual environment, packages that are installed will
135
+ be installed into this folder rather than into Python's main program:
136
+
137
+ C:/Diffusers/.venv/Lib/site-packages
138
+
139
+ That way you don't cause issues updating things you may not want to have
140
+ updated.
141
+
142
+ ---
143
+
144
+ Step 6 (if needed; unsure of this step, I didn't do it):
145
+
146
+ If you don't have Cuda and need to get it, it's here:
147
+
148
+ https://developer.nvidia.com/cuda-toolkit-archive
149
+
150
+ I have 12.2 installed. Some things mention needing 12.1. In Step 8, as of
151
+ writing this, it specifically mentions Cuda 12.1. You may want to check the
152
+ PyTorch website first in Step 8 if you need to install Cuda to see what
153
+ version it is compatible with or you will not get past that step.
154
+
155
+ That link above has a list of prior versions. As packages update, you might
156
+ need something even newer.
157
+
158
+ To see what version of Cuda you have, in Command Prompt, copy this
159
+ line and press Enter:
160
+
161
+ nvidia-smi
162
+
163
+ In the top right corner of the text output that is displayed, your Cuda
164
+ version will be displayed.
165
+
166
+ An older page on this command is here:
167
+
168
+ https://developer.nvidia.com/nvidia-system-management-interface
169
+
170
+ The text output now looks different.
171
+
172
+ ---
173
+
174
+ Step 7:
175
+
176
+ You need to install PyTorch.
177
+
178
+ You should visit their website and see what version they recommend based on
179
+ the version of Cuda you have.
180
+
181
+ https://pytorch.org/
182
+
183
+ As of writing this, in the "INSTALL PYTORCH" section I selected the Stable
184
+ PyTorch build, Windows, Pip, Python and Cuda 12.1.
185
+
186
+ That generated in the "Run this Command" section the command you see below.
187
+ (with the added code to do this in the virtual environment)
188
+
189
+ To install PyTorch in Command Prompt (that is doing things in your virtual
190
+ environment), copy this line and press Enter:
191
+
192
+ cd C:\Diffusers && .venv\Scripts\activate.bat && pip3 install -U xformers --index-url https://download.pytorch.org/whl/cu121
193
+
194
+ A lot of things will download and install, including any packages needed to
195
+ run this. When complete, move on to the next step. (when the command prompt
196
+ returns to where you can paste into it again)
197
+
198
+ The torch file alone is over 2 gigabytes.
199
+
200
+ ---
201
+
202
+ Step 8:
203
+
204
+ This step installs the rest of what you need.
205
+
206
+ You can read about them if you want:
207
+
208
+ https://huggingface.co/docs/diffusers/index
209
+ https://huggingface.co/docs/transformers/index
210
+ https://huggingface.co/docs/accelerate/index
211
+ https://pypi.org/project/ftfy/
212
+ https://github.com/modin-project/modin
213
+ https://pypi.org/project/invisible-watermark/
214
+ https://github.com/gradio-app/gradio
215
+
216
+ To install these, in Command Prompt (that is doing things in your virtual
217
+ environment), all you need to do is copy this line and press Enter:
218
+
219
+ cd C:\Diffusers && .venv\Scripts\activate.bat && pip install diffusers transformers accelerate ftfy modin[all] invisible_watermark
220
+
221
+ A whole bunch of things, what might be 100 packages or more, will download
222
+ and install, including any packages needed to run these.
223
+
224
+ When complete, then install this version of Gradio. A later version fixes a
225
+ bug that is needed for the menus to work properly.
226
+
227
+ cd C:\Diffusers && .venv\Scripts\activate.bat && pip install https://gradio-builds.s3.amazonaws.com/fce80ac804dce1b1b22a8b5c575a35cf0356b82a/gradio-4.8.0-py3-none-any.whl
228
+
229
+ The gallery feature doesn't allow images to be downloaded using the download
230
+ button in the current version above. Hopefully that will work in a later
231
+ version. (so eventually you will need to try another Gradio version)
232
+
233
+ That command is described here:
234
+
235
+ https://www.gradio.app/main/docs/interface
236
+
237
+ When a later version is eventually called, "gradio" will eventually be added
238
+ to the previous command rather than having to specify the version number and
239
+ where to install from.
240
+
241
+ When complete, move on to the next step.
242
+
243
+ ---
244
+
245
+ Step 9:
246
+
247
+ Download the following file:
248
+
249
+ https://huggingface.co/spaces/magicfixeseverything/ai_image_creation/raw/main/ai_image_creation.py
250
+
251
+ Add it into a folder you create here:
252
+
253
+ C:/Diffusers/.venv/
254
+
255
+ Like this:
256
+
257
+ C:/Diffusers/.venv/ai_image_creation/
258
+
259
+ Add then add the file here:
260
+
261
+ C:/Diffusers/.venv/ai_image_creation/ai_image_creation.py
262
+
263
+ There are some things you will need to change in that file, most notably the
264
+ directory specified in "main_dir"
265
+
266
+ ---
267
+
268
+ Step 10:
269
+
270
+ You're ready to run the script that runs the web interface.
271
+
272
+ The first time the models download it will take time as it's gigabytes of
273
+ data that you need to download. An individual model file isn't downloaded
274
+ until you actually try creating an image for that model. For all four
275
+ models, the total size might be about 20 gigabytes if running on a GPU. It
276
+ could be twice that size if on a CPU.
277
+
278
+ In Command Prompt (that is doing things in your virtual environment), copy
279
+ this line and press Enter:
280
+
281
+ cd C:\Diffusers && .venv\Scripts\activate.bat && py .venv\ai_image_creation\app.py
282
+
283
+ That will launch the web interface.
284
+
285
+ Model files are downloaded to:
286
+
287
+ C:\Diffusers\model_data
288
+
289
+ You should know that this folder can grow considerably. You need to manually
290
+ clean it out when you need to get rid of old models. Occasionally, new
291
+ versions will be downloaded when you create an image. When that happens, you
292
+ may want to remove the old version if the new version works. Otherwise, you
293
+ could have 10 to 20 gigabytes of space added each time.
294
+
295
+ You should also know that temporary images created are likely stored here:
296
+
297
+ %USERPROFILE%/AppData/Local/Temp/gradio
298
+
299
+ Those however are likely cleaned out automatically by your computer.
300
+
301
+ A package called Triton apparently can't be installed on Windows so you will
302
+ see an error in the Command Prompt go by about that every time you launch
303
+ the web interface. It doesn't seem to impact anything when using a GPU on
304
+ Windows.
305
+
306
+ https://github.com/openai/triton/issues/1057
307
+ https://github.com/openai/triton/issues/1640
308
+
309
+ Someone offers something there that might work, but I didn't want to install
310
+ something from someone randomly. Again, it seems to work without it when
311
+ using a GPU. If trying to use a CPU using Windows, then it might mean you
312
+ can't use this script.
313
+
314
+ When done, you will get a message like this:
315
+
316
+ Running on local URL: http://127.0.0.1:7860
317
+
318
+ If your browser did not open a web browser, visit the link that was in the
319
+ command prompt. If it was not the one above, note it. However, if you have
320
+ something like Automatic1111 open already, it will use a different port,
321
+ like "7861".
322
+
323
+ It might be this:
324
+
325
+ http://127.0.0.1:7860
326
+
327
+ ---
328
+
329
+ Step 11:
330
+
331
+ When you open the link, you'll see the display to create the imagery. You
332
+ must leave the command prompt open. When you process an image, the command
333
+ prompt will tell you the progress of what you are creating and approximately
334
+ how long it will take for the step it is on. It will take longer as there
335
+ will be things that happen for which there is no progress indicator.
336
+
337
+ ---
338
+
339
+ Step 12:
340
+
341
+ To create a shortcut to the command prompt that needs to be launched every
342
+ time, download the following file:
343
+
344
+ https://huggingface.co/spaces/magicfixeseverything/ai_image_creation/raw/main/ai_image_creation.bat
345
+
346
+ Add it into the folder you created:
347
+
348
+ C:/Diffusers/.venv/ai_image_creation/ai_image_creation.bat
349
+
350
+ The content of that file is the following:
351
+
352
+
353
+ @echo off
354
+
355
+ cd C:\Diffusers
356
+ call .venv\Scripts\activate.bat
357
+ timeout /t 0 >nul
358
+ py .venv\ai_image_creation\ai_image_creation.py
359
+
360
+ cmd /k
361
+
362
+
363
+ For whatever reason, sometimes a shortcut from the desktop doesn't execute.
364
+ I am seeing if a timeout for zero seconds works. (>nul makes the delay
365
+ message not appear)
366
+
367
+ Next, we will create a shortcut to that, which you could do on the desktop.
368
+
369
+ You can follow the instructions below or download this file instead:
370
+
371
+ https://huggingface.co/spaces/magicfixeseverything/ai_image_creation/resolve/main/SDXL%20%26%20PhotoReal.lnk
372
+
373
+ Right click on your desktop and then click on "New > Shortcut".
374
+
375
+ For "Type the location of the item", enter:
376
+
377
+ cmd
378
+
379
+ Then click "Next". You can name the shortcut whatever you want, like
380
+ "AI Image Creation".
381
+
382
+ Then click "Finish".
383
+
384
+ Then right click on the shortcut you created and click "Properties".
385
+
386
+ In "Target", replace what is there with the following:
387
+
388
+ C:\Windows\System32\cmd.exe /k C:/Diffusers/.venv/ai_image_creation/ai_image_creation.bat
389
+
390
+ That will execute that file each time you click on it.
391
+
392
+ If for some reason that doesn't work sometimes, and rather than get the
393
+ program to launch it simply opens the command prompt, then you must enter
394
+ this each time in the command prompt:
395
+
396
+ cd C:\Diffusers && .venv\Scripts\activate.bat && py .venv\ai_image_creation\ai_image_creation.py
397
+
398
+ You might also not be able to use a shortcut. If so, just copy
399
+ "ai_image_creation.bat" and put it on your desktop and name it what you
400
+ want.
401
+
402
+ ---
403
+
404
+ Step 13 (Important):
405
+
406
+ I feel this is a very important step. After you have created model data for
407
+ each base model, model data will then have been downloaded. This could be 20
408
+ gigabytes or more of data. I strongly recommend that you then disable the
409
+ script from downloading updates to the model data. It will not automatically
410
+ delete old data. If you didn't manually go through and delete the older
411
+ data, eventually the model data would use all of the space on your computer.
412
+
413
+ Once you have downloaded the model data for each model, you can disable
414
+ updating by doing the following in a command prompt:
415
+
416
+ setx HF_HUB_OFFLINE "1"
417
+
418
+ It doesn't matter if it is in your virtual environment or not as it will be
419
+ stored with all your environment variables.
420
+
421
+ To view where this variable goes, in the search bar in Windows you can look
422
+ for:
423
+
424
+ edit environment variables
425
+
426
+ And it will be listed.
427
+
428
+ If you need to once again download model data, you can delete it there or
429
+ enter the following in the command prompt:
430
+
431
+ setx HF_HUB_OFFLINE "0" && REG DELETE HKEY_CURRENT_USER\Environment /v HF_HUB_OFFLINE /f
432
+
433
+ In my testing, setting it to 0 and then deleting it made it immediately take
434
+ effect, once you restart the script, to be able to download model data
435
+ again.
436
+
437
+ You can read about environment variables here at HuggingFace:
438
+ https://huggingface.co/docs/huggingface_hub/package_reference/environment_variables#hfhuboffline
439
+
440
+ In regard to HuggingFace caching things, you can learn more on this page:
441
+ https://huggingface.co/docs/huggingface_hub/how-to-cachehttps://huggingface.co/docs/huggingface_hub/how-to-cache#limitations
442
+
443
+ This is just my preferred way of handling it.
444
+
445
+ Optionally, you can disable telemetry by entering this in the command
446
+ prompt:
447
+
448
+ setx HF_HUB_DISABLE_TELEMETRY "1"
449
+
450
+ And to turn it back on:
451
+
452
+ setx HF_HUB_DISABLE_TELEMETRY "0" && REG DELETE HKEY_CURRENT_USER\Environment /v HF_HUB_DISABLE_TELEMETRY /f
ai_image_creation.bat ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ @echo off
2
+
3
+ cd C:\Diffusers
4
+ call .venv\Scripts\activate.bat
5
+ timeout /t 0 >nul
6
+ py .venv\ai_image_creation\app.py
7
+
8
+ cmd /k
app.py CHANGED
@@ -497,7 +497,7 @@ opening_html = ""
497
 
498
  if device == "cpu":
499
 
500
- opening_html = "<span style=\"font-weight: bold; color: red;\">THIS APP IS EXCEPTIONALLY SLOW!</span><br/>This app is not running on a GPU. The first time it loads after the space is rebuilt it might take 10 minutes to generate a SDXL Turbo image. It may take two minutes after that point. For other models, it may take hours to create a single image!"
501
 
502
 
503
 
@@ -551,8 +551,6 @@ which_output_type_before_refiner_and_upscaler = "latent"
551
 
552
  import os
553
 
554
- #script_being_run_on_hugging_face = 0
555
-
556
  try:
557
  if (os.uname().find("magicfixeseverything") >= 0):
558
  script_being_run_on_hugging_face = 0
@@ -578,6 +576,8 @@ if script_being_run_on_hugging_face == 1:
578
  use_custom_hugging_face_cache_dir = 0
579
  show_messages_in_modal_on_page = 0
580
 
 
 
581
 
582
 
583
  saved_images_dir = main_dir + "/" + saved_images_folder_name
@@ -589,24 +589,6 @@ if not os.path.exists(hugging_face_cache_dir):
589
 
590
 
591
 
592
-
593
-
594
-
595
-
596
- os.environ["HF_HUB_OFFLINE"] = "1"
597
-
598
-
599
-
600
-
601
-
602
-
603
-
604
-
605
-
606
-
607
-
608
-
609
-
610
  if auto_save_imagery == 1:
611
 
612
  from datetime import datetime
 
497
 
498
  if device == "cpu":
499
 
500
+ opening_html = "<span style=\"font-weight: bold; color: red;\">THIS APP IS EXCEPTIONALLY SLOW! THE REFINER CODE DOESN'T WORK RIGHT YET.</span><br/>This app is not running on a GPU. The first time it loads after the space is rebuilt it might take 10 minutes to generate a SDXL Turbo image. It may take two minutes after that point. For other models, it may take hours to create a single image!"
501
 
502
 
503
 
 
551
 
552
  import os
553
 
 
 
554
  try:
555
  if (os.uname().find("magicfixeseverything") >= 0):
556
  script_being_run_on_hugging_face = 0
 
576
  use_custom_hugging_face_cache_dir = 0
577
  show_messages_in_modal_on_page = 0
578
 
579
+ ending_html = "<p>If you would like to download this app to run offline on a Windows computer that has a NVIDIA graphics card, click <a href=\"https://huggingface.co/spaces/magicfixeseverything/ai_image_creation/blob/main/ai_image_creation.zip\">here</a> to download it.</p>" + ending_html
580
+
581
 
582
 
583
  saved_images_dir = main_dir + "/" + saved_images_folder_name
 
589
 
590
 
591
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
592
  if auto_save_imagery == 1:
593
 
594
  from datetime import datetime