magicfixeseverything commited on
Commit
91a0c60
1 Parent(s): 1a8212d

Upload 6 files

Browse files
Instructions.txt CHANGED
@@ -4,8 +4,6 @@
4
 
5
  Spaghetti AI for Windows using NVIDIA GPU
6
 
7
- December 28th, 2023 - This app remains a work in progress.
8
-
9
 
10
  I wanted to come up with a unique name for the app, so I chose something
11
  silly.
@@ -369,7 +367,82 @@ cd C:/Spaghetti_AI && .venv\Scripts\activate.bat && pip install https://gradio-b
369
  --------------------
370
 
371
 
372
- Step 10:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
373
 
374
  You're ready to run the script that runs the web interface.
375
 
@@ -424,11 +497,13 @@ cd C:/Spaghetti_AI && .venv\Scripts\activate.bat && py .venv\app_files\spaghetti
424
  You should know that this folder can grow considerably. You need to
425
  manually clean it out when you need to get rid of old models.
426
  Occasionally, new versions will be downloaded when you create an image.
427
- When that happens, you may want to remove the old version if the new
428
- version works. Otherwise, you could have 10 to 20 gigabytes of space
429
- added each time you use a model that updates.
 
430
 
431
- You should also know that temporary images created are likely stored here:
 
432
 
433
  %USERPROFILE%/AppData/Local/Temp/gradio
434
 
@@ -451,7 +526,7 @@ cd C:/Spaghetti_AI && .venv\Scripts\activate.bat && py .venv\app_files\spaghetti
451
  --------------------
452
 
453
 
454
- Step 11:
455
 
456
  When you open the link, you'll see the display to create the imagery.
457
  You must leave the command prompt open. When you process an image, the
@@ -465,7 +540,7 @@ cd C:/Spaghetti_AI && .venv\Scripts\activate.bat && py .venv\app_files\spaghetti
465
  --------------------
466
 
467
 
468
- Step 12:
469
 
470
  To create a shortcut to the command that needs to be launched every
471
  time, use:
@@ -510,52 +585,8 @@ cd C:/Spaghetti_AI && .venv\Scripts\activate.bat && py .venv\app_files\spaghetti
510
  You might also not be able to use a shortcut. If so, just copy
511
  "spaghetti_ai_launcher.bat" and put it on your desktop and name it what
512
  you want. The downside, if you do that, would be reconfiguring your
513
- firewall to use it from that location too.
514
-
515
-
516
- --------------------
517
-
518
-
519
- Step 13 (Important):
520
-
521
- I feel this is a very important step. After you have created model data
522
- for each base model, as well as have used the refiner and upscaler, data
523
- will then have been downloaded. (or you use the method to download the
524
- data at the same time) This could be 40 gigabytes or more of data. I
525
- strongly recommend that you then disable the script from downloading
526
- updates to the model data. It will not automatically delete old data. If
527
- you didn't manually go through and delete the older data, eventually the
528
- model data would use all of the space on your computer.
529
-
530
- If you use "spaghetti_ai_launcher.bat" to launch the script, you can set
531
- "HF_HUB_OFFLINE" in that file to 1 to not download data again.
532
-
533
- That is the easiest way that doesn't impact other installations. If you
534
- wanted to permanently store that environment variable in Windows, which
535
- I don't recommend, it would impact other installations that use Hugging
536
- Face. This only has it apply when using the script.
537
-
538
- You can read about environment variables here at Hugging Face:
539
-
540
- https://huggingface.co/docs/huggingface_hub/package_reference/environment_variables#hfhuboffline
541
-
542
- In regard to Hugging Face caching things, you can learn more on this
543
- page:
544
-
545
- https://huggingface.co/docs/huggingface_hub/how-to-cache#limitations
546
-
547
- The first time you use the script you will need to set HF_HUB_OFFLINE to
548
- 0 like this there:
549
-
550
- set HF_HUB_OFFLINE=0
551
-
552
- Do not include any spaces before or after the equals sign.
553
-
554
- Or access the app from the command line when you want to download data.
555
-
556
- The script will not work otherwise. Because of the importance of this
557
- variable, I prefer to not have the script work with the .bat file until
558
- someone changes that value themselves.
559
 
560
 
561
  --------------------
@@ -601,7 +632,8 @@ set HF_HUB_OFFLINE=0
601
  The main script.
602
 
603
  "C:/Spaghetti_AI" needs to be set in "main_dir" in this file if
604
- you change the path.
 
605
 
606
  - Spaghetti AI (no icon).lnk
607
  - Spaghetti AI.lnk
@@ -617,3 +649,25 @@ set HF_HUB_OFFLINE=0
617
  provided or another. If you change the path from
618
  "C:/Spaghetti_AI", the shortcut will have to be edited in the
619
  "Target" field of the "Shortcut" tab.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  Spaghetti AI for Windows using NVIDIA GPU
6
 
 
 
7
 
8
  I wanted to come up with a unique name for the app, so I chose something
9
  silly.
 
367
  --------------------
368
 
369
 
370
+ Step 10 (Important):
371
+
372
+ I feel this is a very important step. When you try to create model data
373
+ for each base model, as well as use the refiner and upscaler, model data
374
+ will try to be downloaded. There is also an option to download all, or
375
+ just the default data, at one time. That we will cover in a later step.
376
+ But before you can download model data, you need to make sure two things
377
+ are set to "0". At least one will not be when you get this script so
378
+ that you read this section.
379
+
380
+ All the model data could be 40 gigabytes or more of data. I strongly
381
+ recommend that you then disable the script from downloading updates to
382
+ the model data once you have downloaded what you want. HuggingFace
383
+ doesn't just download a model once and never try again. If something is
384
+ updated, it will download it again. It will not delete the older
385
+ version. This could eventually allow it to use all the space on your
386
+ hard drive as that could potentially add 5 to 15 gigabytes of data each
387
+ time a model updates. There are two variables that you need to make sure
388
+ are "0". If you do not use "spaghetti_ai_launcher.bat", then there is
389
+ only one.
390
+
391
+ In "spaghetti_ai_launcher.bat", if you use it, set this to 0:
392
+
393
+ HF_HUB_OFFLINE
394
+
395
+ In "spaghetti_ai_script.py", set this to 0:
396
+
397
+ only_use_local_files
398
+
399
+ To have model data download, both variables must be set to 0 or model
400
+ data will not download. Eventually I may only use one of those. You
401
+ can't set, that I can see, "HF_HUB_OFFLINE" in the python script. It
402
+ should now block all requests online, including to download model data,
403
+ whereas the other only prevents model data from being downloaded. Some
404
+ people might not use "spaghetti_ai_launcher.bat", so it's hard to just
405
+ pick one to use.
406
+
407
+ If you use "spaghetti_ai_launcher.bat" to launch the script, you can set
408
+ "HF_HUB_OFFLINE" in that file to 1 to not download data again and not
409
+ set "only_use_local_files". That variable will automatically be changed
410
+ to "1" if "HF_HUB_OFFLINE" is set to "1"
411
+
412
+ "HF_HUB_OFFLINE" can be set permanently in Windows, until you change it,
413
+ but this is the easiest way that doesn't impact other installations. If
414
+ you wanted to permanently store that environment variable in Windows,
415
+ which I don't recommend, it would impact other installations that use
416
+ Hugging Face. This only has it apply when using the script.
417
+
418
+ You can read about environment variables here at Hugging Face:
419
+
420
+ https://huggingface.co/docs/huggingface_hub/package_reference/environment_variables#hfhuboffline
421
+
422
+ In regard to Hugging Face caching things, you can learn more on this
423
+ page:
424
+
425
+ https://huggingface.co/docs/huggingface_hub/how-to-cache#limitations
426
+
427
+ The first time you use the script you will need to set HF_HUB_OFFLINE to
428
+ 0 like this there:
429
+
430
+ set HF_HUB_OFFLINE=0
431
+
432
+ Do not include any spaces before or after the equals sign.
433
+
434
+ Or access the app from the command line when you want to download data
435
+ if "only_use_local_files" is set to "0".
436
+
437
+ The script will not work otherwise. Because of the importance of this
438
+ variable, I prefer to not have the script work with the .bat file until
439
+ someone changes that value themselves.
440
+
441
+
442
+ --------------------
443
+
444
+
445
+ Step 11:
446
 
447
  You're ready to run the script that runs the web interface.
448
 
 
497
  You should know that this folder can grow considerably. You need to
498
  manually clean it out when you need to get rid of old models.
499
  Occasionally, new versions will be downloaded when you create an image.
500
+ O(unless you turned off the ability to download model data) When that
501
+ Ohappens, you may want to remove the old version if the new version
502
+ Oworks. Otherwise, you could have 5 to 15 gigabytes of space added each
503
+ Otime you use a model that updates.
504
 
505
+ You should also know that temporary images created are likely stored
506
+ Ohere:
507
 
508
  %USERPROFILE%/AppData/Local/Temp/gradio
509
 
 
526
  --------------------
527
 
528
 
529
+ Step 12:
530
 
531
  When you open the link, you'll see the display to create the imagery.
532
  You must leave the command prompt open. When you process an image, the
 
540
  --------------------
541
 
542
 
543
+ Step 13:
544
 
545
  To create a shortcut to the command that needs to be launched every
546
  time, use:
 
585
  You might also not be able to use a shortcut. If so, just copy
586
  "spaghetti_ai_launcher.bat" and put it on your desktop and name it what
587
  you want. The downside, if you do that, would be reconfiguring your
588
+ firewall to use it from that location too. It's best to create a
589
+ shortcut.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
590
 
591
 
592
  --------------------
 
632
  The main script.
633
 
634
  "C:/Spaghetti_AI" needs to be set in "main_dir" in this file if
635
+ you change the path. If "only_use_local_files" is set to "1", you
636
+ will need to change it to download model data.
637
 
638
  - Spaghetti AI (no icon).lnk
639
  - Spaghetti AI.lnk
 
649
  provided or another. If you change the path from
650
  "C:/Spaghetti_AI", the shortcut will have to be edited in the
651
  "Target" field of the "Shortcut" tab.
652
+
653
+
654
+ --------------------
655
+
656
+
657
+ Various Information
658
+
659
+ You get this error:
660
+
661
+ "CUDA out of memory. Tried to allocate 82.00 MiB. GPU 0 has a total
662
+ capacty of 12.00 GiB of which 0 bytes is free. Of the allocated
663
+ memory 16.97 GiB is allocated by PyTorch, and 439.95 MiB is reserved
664
+ by PyTorch but unallocated. If reserved but unallocated memory is
665
+ large try setting max_split_size_mb to avoid fragmentation. See
666
+ documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF"
667
+
668
+ Try setting these to 1 in spaghetti_ai_script.py:
669
+
670
+ use_sequential_cpu_offload_for_base_model = 1
671
+ use_sequential_cpu_offload_for_refiner = 1
672
+ use_sequential_cpu_offload_for_upscaler = 1
673
+
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 💻
4
  colorFrom: blue
5
  colorTo: blue
6
  sdk: gradio
7
- sdk_version: 4.11.0
8
  app_file: spaghetti_ai_script.py
9
  pinned: false
10
  license: mit
 
4
  colorFrom: blue
5
  colorTo: blue
6
  sdk: gradio
7
+ sdk_version: 4.13.0
8
  app_file: spaghetti_ai_script.py
9
  pinned: false
10
  license: mit
spaghetti_ai.zip CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:42d0277d19fa65d8476f48587806150af5f3dc70042405e62b2027233c1de5f4
3
- size 88898
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b1b63dabdff2dc4c16c0a0732144d07b0e8fca2daba0f8f86f39c78751f332af
3
+ size 93329
spaghetti_ai_install.txt CHANGED
@@ -5,8 +5,6 @@ REM
5
  REM
6
  REM Install Spaghetti AI for Windows using NVIDIA GPU
7
  REM
8
- REM December 28th, 2023 - This app remains a work in progress.
9
- REM
10
  REM
11
  REM Before running this script, you need to complete the following steps.
12
  REM
 
5
  REM
6
  REM Install Spaghetti AI for Windows using NVIDIA GPU
7
  REM
 
 
8
  REM
9
  REM Before running this script, you need to complete the following steps.
10
  REM
spaghetti_ai_launcher.bat CHANGED
@@ -5,8 +5,6 @@ REM
5
  REM
6
  REM Install Spaghetti AI for Windows using NVIDIA GPU
7
  REM
8
- REM December 28th, 2023 - This app remains a work in progress.
9
- REM
10
  REM
11
  REM Instructions for this file
12
  REM
 
5
  REM
6
  REM Install Spaghetti AI for Windows using NVIDIA GPU
7
  REM
 
 
8
  REM
9
  REM Instructions for this file
10
  REM
spaghetti_ai_script.py CHANGED
@@ -11,14 +11,6 @@ import time
11
 
12
  ##########
13
 
14
- #
15
- # The zip file wasn't updated on January 4th, 2024. This is just a version
16
- # I wanted to get out that I have been working on for awhile. The cancel
17
- # button doesn't work yet so that is not enabled.
18
- #
19
-
20
- ##########
21
-
22
  #
23
  # Spaghetti AI by MagicFixesEverything
24
  # https://huggingface.co/magicfixeseverything
@@ -242,7 +234,7 @@ auto_open_browser = 0
242
  # immediately. It will stop after completing the current step it is on.
243
  #
244
 
245
- enable_image_generation_cancellation = 0
246
 
247
  ####################
248
 
@@ -252,9 +244,7 @@ enable_image_generation_cancellation = 0
252
  # This will likely be removed in the future.
253
  #
254
  # This doesn't work well at all. It just closes the command prompt. I
255
- # might remove this eventually unless someone knows of a way it can work
256
- # better, such as stopping the generation without closing the command
257
- # prompt.
258
  #
259
 
260
  enable_close_command_prompt_button = 0
@@ -357,6 +347,16 @@ default_add_seed_into_pipe = 1
357
 
358
  ####################
359
 
 
 
 
 
 
 
 
 
 
 
360
  #
361
  # Save Base Image When Using Refiner
362
  #
@@ -443,6 +443,9 @@ base_model_names_object = {
443
  # https://huggingface.co/spaces/Manjushri/SDXL-1.0
444
  # https://huggingface.co/spaces/Manjushri/PhotoReal-V3.8.1
445
  #
 
 
 
446
  # You can use the following customizations...
447
  #
448
  ##########
@@ -470,7 +473,7 @@ base_model_names_object = {
470
  # For some reason, I haven't been able to match this version of the
471
  # configuration yet. That means this link doesn't work:
472
  #
473
- # http://127.0.0.1:7860/?model=photoreal&model_config=photoreal_3-8-1&scheduler=model_default&width=768&height=768&guidance=5&steps=50&prompt=&neg_prompt=&seed=&add_seed=no&refiner=no&denoise_start=0.95&refiner_steps=&use_denoise_end=no&latent_space_before_refiner=no&upscaler=no&upscaler_steps=
474
  #
475
  ####################
476
  #
@@ -479,7 +482,7 @@ base_model_names_object = {
479
  # - Valid from November 12th to December 29th.
480
  # Base model was changed from 3.6 to 3.7.5: "circulus/canvers-real-v3.7.5"
481
  #
482
- # http://127.0.0.1:7860/?model=photoreal&model_config=photoreal_3-7-5&scheduler=model_default&width=768&height=768&guidance=7&steps=50&prompt=&neg_prompt=&seed=&add_seed=no&refiner=no&denoise_start=0.95&refiner_steps=&use_denoise_end=no&latent_space_before_refiner=no&upscaler=no&upscaler_steps=
483
  #
484
  ####################
485
  #
@@ -489,7 +492,7 @@ base_model_names_object = {
489
  # "circulus/canvers-realistic-v3.6" was already in effect.
490
  # But there were changes on this date.
491
  #
492
- # http://127.0.0.1:7860/?model=photoreal&model_config=photoreal_3-6&scheduler=model_default&width=768&height=768&guidance=7&steps=50&prompt=&neg_prompt=&seed=&add_seed=no&refiner=no&denoise_start=0.95&refiner_steps=&use_denoise_end=no&latent_space_before_refiner=no&upscaler=no&upscaler_steps=
493
  #
494
  ####################
495
 
@@ -949,10 +952,8 @@ number_of_reserved_tokens = 2
949
  generate_image_button_normal_text = "Generate Image"
950
  generate_image_button_in_progress_text = "Generating..."
951
 
952
- cancel_image_in_queue_button_text = "Cancel"
953
-
954
- cancel_image_in_progress_button_normal_text = "Cancel Processing"
955
- cancel_image_in_progress_button_in_progress_text = "Cancelling..."
956
 
957
 
958
 
@@ -961,6 +962,12 @@ gradio_image_gallery_component_height = 350
961
 
962
 
963
 
 
 
 
 
 
 
964
  ###############################################################################
965
  ###############################################################################
966
  #
@@ -975,6 +982,12 @@ gradio_image_gallery_component_height = 350
975
 
976
 
977
 
 
 
 
 
 
 
978
  if script_being_run_on_hugging_face == 1:
979
 
980
  # If on HuggingFace, I change some things.
@@ -1384,6 +1397,14 @@ if default_add_seed_into_pipe == 1:
1384
 
1385
 
1386
 
 
 
 
 
 
 
 
 
1387
  default_save_base_image_when_using_refiner_is_selected = False
1388
 
1389
  if default_save_base_image_when_using_refiner == 1:
@@ -1445,6 +1466,10 @@ current_preview_image_user_id = 0
1445
 
1446
 
1447
 
 
 
 
 
1448
  cancel_image_generation_ids_object = {}
1449
  cancel_image_generation_times_object = {}
1450
  seconds_to_store_cancellations_in_cancel_image_generation_times_object = 86400
@@ -2897,17 +2922,6 @@ def load_image_preview (
2897
 
2898
  user_id_state_value = user_id_state.value
2899
 
2900
-
2901
-
2902
-
2903
-
2904
-
2905
- # print ("constant ... user_id_state_value: ", user_id_state_value)
2906
-
2907
-
2908
-
2909
-
2910
-
2911
  # print ("Image preview check run", current_preview_image_user_id, user_id_state_value)
2912
 
2913
  if (
@@ -2982,10 +2996,6 @@ def before_create_image_function ():
2982
 
2983
 
2984
 
2985
- #print ("before_create_image_function: ", image_generation_id)
2986
-
2987
-
2988
-
2989
  before_create_image_object = {
2990
  generate_image_button: generate_image_button_update,
2991
  output_text_field: output_text_field_update,
@@ -3018,22 +3028,17 @@ def before_create_image_function ():
3018
 
3019
  if enable_image_generation_cancellation == 1:
3020
 
3021
- cancel_image_buttons_group_update = gr.Group(
3022
  visible = True
3023
  )
3024
 
3025
- cancel_image_in_queue_button_update = gr.Button(
3026
- interactive = True
3027
- )
3028
-
3029
- cancel_image_in_progress_button_update = gr.Button(
3030
  interactive = True
3031
  )
3032
 
3033
  before_create_image_object.update({
3034
- cancel_image_buttons_group: cancel_image_buttons_group_update,
3035
- cancel_image_in_queue_button: cancel_image_in_queue_button_update,
3036
- cancel_image_in_progress_button: cancel_image_in_progress_button_update
3037
  })
3038
 
3039
  return before_create_image_object
@@ -3054,8 +3059,6 @@ def before_create_image_function ():
3054
 
3055
  def after_create_image_function ():
3056
 
3057
- #print ("after_create_image_function")
3058
-
3059
  generate_image_button_update = gr.Button(
3060
  value = generate_image_button_normal_text,
3061
  variant = "primary",
@@ -3097,30 +3100,29 @@ def after_create_image_function ():
3097
  visible = True
3098
  )
3099
 
3100
- cancel_image_buttons_group_update = gr.Group(
3101
  visible = False
3102
  )
3103
 
3104
- cancel_image_in_queue_button_update = gr.Button(
3105
- value = cancel_image_in_queue_button_text,
3106
  interactive = False
3107
  )
3108
 
3109
- cancel_image_in_progress_button_update = gr.Button(
3110
- value = cancel_image_in_progress_button_normal_text,
3111
- interactive = False
3112
  )
3113
 
3114
- cancel_image_in_progress_message_field_row_update = gr.Button(
3115
- visible = False
3116
  )
3117
 
3118
  after_create_image_object.update({
3119
  generate_image_button_row: generate_image_button_row_update,
3120
- cancel_image_buttons_group: cancel_image_buttons_group_update,
3121
- cancel_image_in_queue_button: cancel_image_in_queue_button_update,
3122
- cancel_image_in_progress_button: cancel_image_in_progress_button_update,
3123
- cancel_image_in_progress_message_field_row: cancel_image_in_progress_message_field_row_update
3124
  })
3125
 
3126
  return after_create_image_object
@@ -3144,11 +3146,6 @@ def remove_from_cancel_object (
3144
  image_generation_id_state_value
3145
  ):
3146
 
3147
- #print ("remove_from_cancel_object")
3148
-
3149
- #print (cancel_image_generation_ids_object)
3150
- #print (cancel_image_generation_times_object)
3151
-
3152
  if (
3153
  (user_id_state_value in cancel_image_generation_ids_object) and
3154
  (image_generation_id_state_value in cancel_image_generation_ids_object[user_id_state_value])
@@ -3156,24 +3153,14 @@ def remove_from_cancel_object (
3156
 
3157
  cancel_image_generation_ids_object[user_id_state_value].remove(image_generation_id_state_value)
3158
 
3159
- #print (len(cancel_image_generation_ids_object[user_id_state_value]))
3160
-
3161
  if len(cancel_image_generation_ids_object[user_id_state_value]) == 0:
3162
 
3163
  cancel_image_generation_ids_object.pop(user_id_state_value, None)
3164
 
3165
- #print ("after1")
3166
- #print (cancel_image_generation_ids_object)
3167
- #print (cancel_image_generation_times_object)
3168
-
3169
  if image_generation_id_state_value in cancel_image_generation_times_object:
3170
 
3171
  cancel_image_generation_times_object.pop(image_generation_id_state_value, None)
3172
 
3173
- #print ("after2")
3174
- #print (cancel_image_generation_ids_object)
3175
- #print (cancel_image_generation_times_object)
3176
-
3177
 
3178
 
3179
 
@@ -3384,6 +3371,7 @@ def create_image_function (
3384
  base_model_steps_field_for_sdxl_turbo,
3385
  actual_seed,
3386
  add_seed_into_pipe,
 
3387
 
3388
  refining_selection_field_value,
3389
  refining_denoise_start_field_value,
@@ -3421,6 +3409,10 @@ def create_image_function (
3421
  image_generation_id_state_value = image_generation_id_state.value
3422
  user_id_state_value = user_id_state.value
3423
 
 
 
 
 
3424
 
3425
 
3426
  global cancel_image_generation_ids_object
@@ -3434,19 +3426,6 @@ def create_image_function (
3434
 
3435
 
3436
 
3437
-
3438
-
3439
-
3440
- #here
3441
-
3442
- #print ("create_image_function ---", prompt_text)
3443
- #print ("image_generation_id_state_value: ", image_generation_id_state_value)
3444
- #print ("canceled_images_array_state: ", canceled_images_array_state)
3445
- #print ("user_id_state_value: ", user_id_state_value)
3446
- #print ("cancel_image_generation_ids_object: ", cancel_image_generation_ids_object)
3447
- #print ("cancel_image_generation_times_object: ", cancel_image_generation_times_object)
3448
- print ("-------------------------")
3449
-
3450
  if image_processing_is_canceled(user_id_state_value, image_generation_id_state_value):
3451
 
3452
  # User likely canceled while waiting in queue
@@ -3554,6 +3533,7 @@ def create_image_function (
3554
 
3555
 
3556
  add_seed_into_pipe = numerical_bool(add_seed_into_pipe)
 
3557
 
3558
 
3559
 
@@ -3750,7 +3730,15 @@ def create_image_function (
3750
 
3751
 
3752
 
3753
- if add_seed_into_pipe == 0:
 
 
 
 
 
 
 
 
3754
 
3755
  generator = None
3756
 
@@ -3862,7 +3850,8 @@ def create_image_function (
3862
  (
3863
  ((int(callback_step_index) % image_preview_step_interval) == 0) or
3864
  (seconds_per_step >= image_preview_seconds_interval)
3865
- )
 
3866
  ):
3867
 
3868
  latents = callback_kwargs["latents"]
@@ -3871,6 +3860,16 @@ def create_image_function (
3871
 
3872
  model_to_use = base_model_name_value
3873
 
 
 
 
 
 
 
 
 
 
 
3874
  create_preview_image(
3875
  model_to_use,
3876
  user_id_state_value,
@@ -3902,7 +3901,10 @@ def create_image_function (
3902
  is_final_image
3903
  )
3904
 
3905
- if show_image_creation_progress_log == 1:
 
 
 
3906
 
3907
  progress(
3908
  progress = (
@@ -3965,7 +3967,8 @@ def create_image_function (
3965
  (
3966
  ((int(callback_step_index) % image_preview_step_interval) == 0) or
3967
  (seconds_per_step >= image_preview_seconds_interval)
3968
- )
 
3969
  ):
3970
 
3971
  latents = callback_kwargs["latents"]
@@ -3983,7 +3986,10 @@ def create_image_function (
3983
  temporary_extra
3984
  )
3985
 
3986
- if show_image_creation_progress_log == 1:
 
 
 
3987
 
3988
  progress(
3989
  progress = (
@@ -4043,7 +4049,8 @@ def create_image_function (
4043
  (
4044
  ((int(callback_step_index) % image_preview_step_interval) == 0) or
4045
  (seconds_per_step >= image_preview_seconds_interval)
4046
- )
 
4047
  ):
4048
 
4049
  latents = callback_latents
@@ -4061,7 +4068,10 @@ def create_image_function (
4061
  temporary_extra
4062
  )
4063
 
4064
- if show_image_creation_progress_log == 1:
 
 
 
4065
 
4066
  progress(
4067
  progress = (
@@ -4104,10 +4114,6 @@ def create_image_function (
4104
 
4105
 
4106
 
4107
- generator = torch.manual_seed(actual_seed)
4108
-
4109
-
4110
-
4111
  if image_processing_is_canceled(user_id_state_value, image_generation_id_state_value):
4112
 
4113
  if show_messages_in_command_prompt == 1:
@@ -4686,14 +4692,13 @@ def create_image_function (
4686
 
4687
  #####################
4688
  #
4689
- # Cancel Image In Queue Function
4690
  #
4691
  # Image generation has not yet started and we need to cancel it.
4692
  #
4693
  #####################
4694
 
4695
- def cancel_image_in_queue_function(
4696
- confirm_cancel_image_field_value,
4697
  user_id_state,
4698
  image_generation_id_state
4699
  ):
@@ -4701,22 +4706,6 @@ def cancel_image_in_queue_function(
4701
  user_id_state_value = user_id_state.value
4702
  image_generation_id_state_value = image_generation_id_state.value
4703
 
4704
- confirm_cancel_image_field_value = numerical_bool(confirm_cancel_image_field_value)
4705
-
4706
- #print ("confirm_cancel_image_field_value: ", confirm_cancel_image_field_value)
4707
-
4708
- if confirm_cancel_image_field_value == 0:
4709
-
4710
- # User has not confirmed cancellation
4711
-
4712
- confirm_cancel_image_field_row_update = gr.Row(
4713
- visible = True
4714
- )
4715
-
4716
- return {
4717
- confirm_cancel_image_field_row: confirm_cancel_image_field_row_update
4718
- }
4719
-
4720
 
4721
 
4722
  global image_generation_ids_object
@@ -4729,155 +4718,90 @@ def cancel_image_in_queue_function(
4729
  cancel_image_generation_ids_object[user_id_state_value].append(image_generation_id_state_value)
4730
  cancel_image_generation_times_object[image_generation_id_state_value] = time.time()
4731
 
4732
- generate_image_button_row_update = gr.Row(
4733
- visible = True
4734
- )
4735
-
4736
- generate_image_button_update = gr.Button(
4737
- value = generate_image_button_normal_text,
4738
- variant = "primary",
4739
- interactive = True
4740
- )
4741
-
4742
- output_text_field_update = gr.Textbox(
4743
- visible = True
4744
- )
4745
 
4746
- output_image_preview_field_row_update = gr.Row(
4747
- visible = False
4748
- )
4749
 
4750
- cancel_image_buttons_group_update = gr.Group(
4751
- visible = False
4752
- )
4753
-
4754
- cancel_image_in_queue_button_update = gr.Button(
4755
- value = cancel_image_in_queue_button_text,
4756
- interactive = False
4757
- )
4758
-
4759
- cancel_image_in_progress_button_update = gr.Button(
4760
- value = cancel_image_in_progress_button_normal_text,
4761
  interactive = False
4762
  )
4763
 
4764
- cancel_image_in_progress_message_field_row_update = gr.Row(
4765
- visible = False
4766
- )
4767
-
4768
- confirm_cancel_image_field_row_update = gr.Row(
4769
- visible = False
4770
- )
4771
-
4772
- confirm_cancel_image_field_update = gr.Checkbox(
4773
- value = 0
4774
  )
4775
 
 
4776
 
 
4777
 
4778
- return {
4779
- generate_image_button_row: generate_image_button_row_update,
4780
- generate_image_button: generate_image_button_update,
4781
- output_text_field: output_text_field_update,
4782
- output_image_preview_field_row: output_image_preview_field_row_update,
4783
- cancel_image_buttons_group: cancel_image_buttons_group_update,
4784
- cancel_image_in_queue_button: cancel_image_in_queue_button_update,
4785
- cancel_image_in_progress_button: cancel_image_in_progress_button_update,
4786
- cancel_image_in_progress_message_field_row: cancel_image_in_progress_message_field_row_update,
4787
- confirm_cancel_image_field_row: confirm_cancel_image_field_row_update,
4788
- confirm_cancel_image_field: confirm_cancel_image_field_update
4789
- }
4790
 
 
4791
 
4792
 
4793
 
 
4794
 
4795
 
4796
 
4797
- #####################
4798
- #
4799
- # Cancel Image In Progress Function
4800
- #
4801
- # Image generation has already started and we need to cancel it.
4802
- #
4803
- #####################
4804
 
4805
- def cancel_image_in_progress_function(
4806
- confirm_cancel_image_field_value,
4807
- user_id_state,
4808
- image_generation_id_state
4809
- ):
4810
 
4811
- user_id_state_value = user_id_state.value
4812
- image_generation_id_state_value = image_generation_id_state.value
4813
 
4814
- confirm_cancel_image_field_value = numerical_bool(confirm_cancel_image_field_value)
 
4815
 
4816
- if confirm_cancel_image_field_value == 0:
4817
 
4818
- # User has not confirmed cancellation
 
 
 
4819
 
4820
- confirm_cancel_image_field_row_update = gr.Row(
4821
  visible = True
4822
  )
4823
 
4824
- return {
4825
- confirm_cancel_image_field_row: confirm_cancel_image_field_row_update
4826
- }
4827
-
4828
-
4829
-
4830
- show_message("Your image generation is being canceled. After the current step in the process is complete, the cancellation will be complete.")
4831
-
4832
-
4833
-
4834
- # We need to save this cancellation to an object that we check. We save
4835
- # the time as the cancellation might be applied later in the queue and
4836
- # there may have been multiple cancellations by others. We will remove
4837
- # older cancellations eventually from it by checking the time.
4838
-
4839
-
4840
-
4841
- global image_generation_ids_object
4842
- global cancel_image_generation_times_object
4843
-
4844
- if (user_id_state_value not in cancel_image_generation_ids_object):
4845
-
4846
- cancel_image_generation_ids_object[user_id_state_value] = []
4847
 
4848
- cancel_image_generation_ids_object[user_id_state_value].append(image_generation_id_state_value)
4849
- cancel_image_generation_times_object[image_generation_id_state_value] = time.time()
 
4850
 
 
 
 
 
 
 
 
4851
 
4852
 
4853
- generate_image_button_row_update = gr.Row(
4854
- visible = False
4855
- )
4856
 
4857
- cancel_image_in_progress_button_update = gr.Button(
4858
- value = "Cancelling...",
4859
- interactive = False
4860
  )
4861
 
4862
- cancel_image_in_progress_message_field_row_update = gr.Row(
4863
- visible = True
4864
- )
 
 
4865
 
4866
- confirm_cancel_image_field_update = gr.Checkbox(
4867
- value = 0
4868
- )
4869
 
4870
- confirm_cancel_image_field_row_update = gr.Row(
4871
- visible = False
4872
- )
4873
 
4874
- return {
4875
- generate_image_button_row: generate_image_button_row_update,
4876
- cancel_image_in_progress_button: cancel_image_in_progress_button_update,
4877
- confirm_cancel_image_field_row: confirm_cancel_image_field_row_update,
4878
- confirm_cancel_image_field: confirm_cancel_image_field_update,
4879
- cancel_image_in_progress_message_field_row: cancel_image_in_progress_message_field_row_update
4880
- }
4881
 
4882
 
4883
 
@@ -5223,6 +5147,8 @@ def get_query_params(
5223
 
5224
  add_seed_key_in_url = "add_seed"
5225
 
 
 
5226
  if add_seed_key_in_url in url_object:
5227
 
5228
  add_seed_in_url = url_object[add_seed_key_in_url].lower()
@@ -5242,6 +5168,34 @@ def get_query_params(
5242
 
5243
 
5244
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5245
  refiner_key_in_url = "refiner"
5246
 
5247
  if refiner_key_in_url in url_object:
@@ -5600,49 +5554,22 @@ with gr.Blocks(
5600
  interactive = False
5601
  )
5602
 
5603
- with gr.Group(
5604
  visible = False
5605
- ) as cancel_image_buttons_group:
5606
-
5607
- with gr.Row(
5608
- elem_id = "cancel_image_in_queue_button_row_id",
5609
- visible = True
5610
- ):
5611
-
5612
- cancel_image_in_queue_button = gr.Button(
5613
- value = cancel_image_in_queue_button_text,
5614
- variant = "stop",
5615
- interactive = False
5616
- )
5617
-
5618
- with gr.Row(
5619
- elem_id = "cancel_image_in_progress_button_row_id",
5620
- visible = True
5621
- ):
5622
-
5623
- cancel_image_in_progress_button = gr.Button(
5624
- value = cancel_image_in_progress_button_normal_text,
5625
- variant = "stop",
5626
- interactive = False
5627
- )
5628
-
5629
- with gr.Row(
5630
- visible = False
5631
- ) as confirm_cancel_image_field_row:
5632
 
5633
- confirm_cancel_image_field = gr.Checkbox(
5634
- label = "Check to confirm & click button again",
5635
- value = 0,
5636
- interactive = True,
5637
- container = True
5638
- )
5639
 
5640
  with gr.Row(
5641
  visible = False
5642
- ) as cancel_image_in_progress_message_field_row:
5643
 
5644
  cancel_image_message_field = gr.HTML(
5645
- value = "<div style=\"text-align: center;\">Image generation will be canceled once the current step completes.</div>"
5646
  )
5647
 
5648
  with gr.Group():
@@ -6058,8 +5985,16 @@ with gr.Blocks(
6058
  visible = False
6059
  ) as output_image_preview_field_row:
6060
 
 
 
 
 
 
 
6061
  output_image_preview_field = gr.Image(
6062
  elem_id = "image_preview_id",
 
 
6063
  label = "Preview",
6064
  type = "pil",
6065
  interactive = False,
@@ -6162,6 +6097,16 @@ with gr.Blocks(
6162
  elem_classes = "sp_checkbox"
6163
  )
6164
 
 
 
 
 
 
 
 
 
 
 
6165
  with gr.Row():
6166
 
6167
  save_or_display_word_text_for_save_base_image = "Display"
@@ -6529,6 +6474,7 @@ async (
6529
  base_model_steps_field_for_sdxl_turbo_field,
6530
  seed_field,
6531
  add_seed_into_pipe_field,
 
6532
 
6533
  refining_selection_field,
6534
  refining_denoise_start_field,
@@ -6579,11 +6525,10 @@ async (
6579
  prompt_truncated_field,
6580
  negative_prompt_truncated_field_group,
6581
  negative_prompt_truncated_field,
6582
- cancel_image_buttons_group,
6583
- confirm_cancel_image_field,
6584
- cancel_image_in_queue_button,
6585
- cancel_image_in_progress_button,
6586
- cancel_image_in_progress_message_field_row,
6587
  error_text_field,
6588
  image_generation_id_state
6589
  ],
@@ -6620,12 +6565,10 @@ async (
6620
  output_text_field,
6621
  output_image_preview_field_row,
6622
  generate_image_button_row,
6623
- cancel_image_buttons_group,
6624
- confirm_cancel_image_field_row,
6625
- confirm_cancel_image_field,
6626
- cancel_image_in_queue_button,
6627
- cancel_image_in_progress_button,
6628
- cancel_image_in_progress_message_field_row
6629
  ],
6630
  show_progress = "hidden",
6631
  queue = True
@@ -6688,50 +6631,25 @@ async (
6688
 
6689
 
6690
 
6691
- cancel_image_in_queue_click_event = cancel_image_in_queue_button.click(
6692
- fn = cancel_image_in_queue_function,
6693
  inputs = [
6694
- confirm_cancel_image_field,
6695
  user_id_state,
6696
  image_generation_id_state
6697
  ],
6698
  outputs = [
 
6699
  generate_image_button,
6700
- output_image_field,
6701
- output_image_gallery_field,
6702
  output_text_field,
6703
  output_image_preview_field_row,
6704
- generate_image_button_row,
6705
- cancel_image_buttons_group,
6706
- confirm_cancel_image_field_row,
6707
- confirm_cancel_image_field,
6708
- cancel_image_in_queue_button,
6709
- cancel_image_in_progress_button,
6710
- cancel_image_in_progress_message_field_row
6711
  ],
6712
  show_progress = "hidden",
6713
- cancels = generate_image_button_click_event,
6714
- queue = False
6715
- )
6716
-
6717
-
6718
-
6719
- cancel_image_in_progress_click_event = cancel_image_in_progress_button.click(
6720
- fn = cancel_image_in_progress_function,
6721
- inputs = [
6722
- confirm_cancel_image_field,
6723
- user_id_state,
6724
- image_generation_id_state
6725
- ],
6726
- outputs = [
6727
- generate_image_button_row,
6728
- cancel_image_in_progress_button,
6729
- confirm_cancel_image_field_row,
6730
- confirm_cancel_image_field,
6731
- cancel_image_in_progress_message_field_row
6732
- ],
6733
- show_progress = "hidden",
6734
- queue = False
6735
  )
6736
 
6737
 
 
11
 
12
  ##########
13
 
 
 
 
 
 
 
 
 
14
  #
15
  # Spaghetti AI by MagicFixesEverything
16
  # https://huggingface.co/magicfixeseverything
 
234
  # immediately. It will stop after completing the current step it is on.
235
  #
236
 
237
+ enable_image_generation_cancellation = 1
238
 
239
  ####################
240
 
 
244
  # This will likely be removed in the future.
245
  #
246
  # This doesn't work well at all. It just closes the command prompt. I
247
+ # might remove this eventually.
 
 
248
  #
249
 
250
  enable_close_command_prompt_button = 0
 
347
 
348
  ####################
349
 
350
+ #
351
+ # Use torch.manual_seed But Do Not Add To Pipe
352
+ #
353
+ # We need this to match the PhotoReal site to make it work.
354
+ #
355
+
356
+ default_use_torch_manual_seed_but_do_not_add_to_pipe = 0
357
+
358
+ ####################
359
+
360
  #
361
  # Save Base Image When Using Refiner
362
  #
 
443
  # https://huggingface.co/spaces/Manjushri/SDXL-1.0
444
  # https://huggingface.co/spaces/Manjushri/PhotoReal-V3.8.1
445
  #
446
+ # The PhotoReal site doesn't explicitly add the seed to the generation, so
447
+ # that option needs to be unchecked to match that imagery.
448
+ #
449
  # You can use the following customizations...
450
  #
451
  ##########
 
473
  # For some reason, I haven't been able to match this version of the
474
  # configuration yet. That means this link doesn't work:
475
  #
476
+ # http://127.0.0.1:7860/?model=photoreal&model_config=photoreal_3-8-1&scheduler=model_default&width=768&height=768&guidance=5&steps=50&prompt=&neg_prompt=&seed=&add_seed=no&use_torch_manual_seed_but_not_in_generator=yes&refiner=no&denoise_start=0.95&refiner_steps=&use_denoise_end=no&latent_space_before_refiner=no&upscaler=no&upscaler_steps=
477
  #
478
  ####################
479
  #
 
482
  # - Valid from November 12th to December 29th.
483
  # Base model was changed from 3.6 to 3.7.5: "circulus/canvers-real-v3.7.5"
484
  #
485
+ # http://127.0.0.1:7860/?model=photoreal&model_config=photoreal_3-7-5&scheduler=model_default&width=768&height=768&guidance=7&steps=50&prompt=&neg_prompt=&seed=&add_seed=no&use_torch_manual_seed_but_not_in_generator=yes&refiner=no&denoise_start=0.95&refiner_steps=&use_denoise_end=no&latent_space_before_refiner=no&upscaler=no&upscaler_steps=
486
  #
487
  ####################
488
  #
 
492
  # "circulus/canvers-realistic-v3.6" was already in effect.
493
  # But there were changes on this date.
494
  #
495
+ # http://127.0.0.1:7860/?model=photoreal&model_config=photoreal_3-6&scheduler=model_default&width=768&height=768&guidance=7&steps=50&prompt=&neg_prompt=&seed=&add_seed=no&use_torch_manual_seed_but_not_in_generator=yes&refiner=no&denoise_start=0.95&refiner_steps=&use_denoise_end=no&latent_space_before_refiner=no&upscaler=no&upscaler_steps=
496
  #
497
  ####################
498
 
 
952
  generate_image_button_normal_text = "Generate Image"
953
  generate_image_button_in_progress_text = "Generating..."
954
 
955
+ cancel_image_button_text = "Cancel"
956
+ cancel_image_button_in_progress_text = "Cancelling..."
 
 
957
 
958
 
959
 
 
962
 
963
 
964
 
965
+ canceled_image_in_queue_message = "Due to how the queue works in this app, you need to reload the page after canceling an image. Otherwise, you will not be able to generate another image until you reach the position in the queue you were in originally. At that time, the button to generate an image will appear again."
966
+
967
+ canceled_image_in_process_of_being_generated = "<div style=\"text-align: center;\">Image generation will be canceled once the current step completes.</div>"
968
+
969
+
970
+
971
  ###############################################################################
972
  ###############################################################################
973
  #
 
982
 
983
 
984
 
985
+ if default_add_seed_into_pipe == 1:
986
+
987
+ default_use_torch_manual_seed_but_do_not_add_to_pipe = 0
988
+
989
+
990
+
991
  if script_being_run_on_hugging_face == 1:
992
 
993
  # If on HuggingFace, I change some things.
 
1397
 
1398
 
1399
 
1400
+ default_use_torch_manual_seed_but_do_not_add_to_pipe_is_selected = False
1401
+
1402
+ if default_use_torch_manual_seed_but_do_not_add_to_pipe == 1:
1403
+
1404
+ default_use_torch_manual_seed_but_do_not_add_to_pipe_is_selected = True
1405
+
1406
+
1407
+
1408
  default_save_base_image_when_using_refiner_is_selected = False
1409
 
1410
  if default_save_base_image_when_using_refiner == 1:
 
1466
 
1467
 
1468
 
1469
+ current_image_generation_id_in_progress = 0
1470
+
1471
+
1472
+
1473
  cancel_image_generation_ids_object = {}
1474
  cancel_image_generation_times_object = {}
1475
  seconds_to_store_cancellations_in_cancel_image_generation_times_object = 86400
 
2922
 
2923
  user_id_state_value = user_id_state.value
2924
 
 
 
 
 
 
 
 
 
 
 
 
2925
  # print ("Image preview check run", current_preview_image_user_id, user_id_state_value)
2926
 
2927
  if (
 
2996
 
2997
 
2998
 
 
 
 
 
2999
  before_create_image_object = {
3000
  generate_image_button: generate_image_button_update,
3001
  output_text_field: output_text_field_update,
 
3028
 
3029
  if enable_image_generation_cancellation == 1:
3030
 
3031
+ cancel_image_button_row_update = gr.Row(
3032
  visible = True
3033
  )
3034
 
3035
+ cancel_image_button_update = gr.Button(
 
 
 
 
3036
  interactive = True
3037
  )
3038
 
3039
  before_create_image_object.update({
3040
+ cancel_image_button_row: cancel_image_button_row_update,
3041
+ cancel_image_button: cancel_image_button_update
 
3042
  })
3043
 
3044
  return before_create_image_object
 
3059
 
3060
  def after_create_image_function ():
3061
 
 
 
3062
  generate_image_button_update = gr.Button(
3063
  value = generate_image_button_normal_text,
3064
  variant = "primary",
 
3100
  visible = True
3101
  )
3102
 
3103
+ cancel_image_button_row_update = gr.Row(
3104
  visible = False
3105
  )
3106
 
3107
+ cancel_image_button_update = gr.Button(
3108
+ value = cancel_image_button_text,
3109
  interactive = False
3110
  )
3111
 
3112
+ cancel_image_message_field_row_update = gr.Button(
3113
+ visible = False
 
3114
  )
3115
 
3116
+ cancel_image_message_field_update = gr.Button(
3117
+ value = ""
3118
  )
3119
 
3120
  after_create_image_object.update({
3121
  generate_image_button_row: generate_image_button_row_update,
3122
+ cancel_image_button_row: cancel_image_button_row_update,
3123
+ cancel_image_button: cancel_image_button_update,
3124
+ cancel_image_message_field_row: cancel_image_message_field_row_update,
3125
+ cancel_image_message_field: cancel_image_message_field_update
3126
  })
3127
 
3128
  return after_create_image_object
 
3146
  image_generation_id_state_value
3147
  ):
3148
 
 
 
 
 
 
3149
  if (
3150
  (user_id_state_value in cancel_image_generation_ids_object) and
3151
  (image_generation_id_state_value in cancel_image_generation_ids_object[user_id_state_value])
 
3153
 
3154
  cancel_image_generation_ids_object[user_id_state_value].remove(image_generation_id_state_value)
3155
 
 
 
3156
  if len(cancel_image_generation_ids_object[user_id_state_value]) == 0:
3157
 
3158
  cancel_image_generation_ids_object.pop(user_id_state_value, None)
3159
 
 
 
 
 
3160
  if image_generation_id_state_value in cancel_image_generation_times_object:
3161
 
3162
  cancel_image_generation_times_object.pop(image_generation_id_state_value, None)
3163
 
 
 
 
 
3164
 
3165
 
3166
 
 
3371
  base_model_steps_field_for_sdxl_turbo,
3372
  actual_seed,
3373
  add_seed_into_pipe,
3374
+ use_torch_manual_seed_but_do_not_add_to_pipe_field,
3375
 
3376
  refining_selection_field_value,
3377
  refining_denoise_start_field_value,
 
3409
  image_generation_id_state_value = image_generation_id_state.value
3410
  user_id_state_value = user_id_state.value
3411
 
3412
+ global current_image_generation_id_in_progress
3413
+
3414
+ current_image_generation_id_in_progress = image_generation_id_state_value
3415
+
3416
 
3417
 
3418
  global cancel_image_generation_ids_object
 
3426
 
3427
 
3428
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3429
  if image_processing_is_canceled(user_id_state_value, image_generation_id_state_value):
3430
 
3431
  # User likely canceled while waiting in queue
 
3533
 
3534
 
3535
  add_seed_into_pipe = numerical_bool(add_seed_into_pipe)
3536
+ use_torch_manual_seed_but_do_not_add_to_pipe_field = numerical_bool(use_torch_manual_seed_but_do_not_add_to_pipe_field)
3537
 
3538
 
3539
 
 
3730
 
3731
 
3732
 
3733
+ if add_seed_into_pipe == 1:
3734
+
3735
+ generator = torch.manual_seed(actual_seed)
3736
+
3737
+ else:
3738
+
3739
+ if use_torch_manual_seed_but_do_not_add_to_pipe_field == 1:
3740
+
3741
+ torch.manual_seed(actual_seed)
3742
 
3743
  generator = None
3744
 
 
3850
  (
3851
  ((int(callback_step_index) % image_preview_step_interval) == 0) or
3852
  (seconds_per_step >= image_preview_seconds_interval)
3853
+ ) and
3854
+ (callback_step_number < current_estimated_total_base_model_steps)
3855
  ):
3856
 
3857
  latents = callback_kwargs["latents"]
 
3860
 
3861
  model_to_use = base_model_name_value
3862
 
3863
+ is_final_image = 0
3864
+
3865
+ pil_image = create_image_from_latents(
3866
+ model_to_use,
3867
+ pipe,
3868
+ latents,
3869
+ generator,
3870
+ is_final_image
3871
+ )
3872
+
3873
  create_preview_image(
3874
  model_to_use,
3875
  user_id_state_value,
 
3901
  is_final_image
3902
  )
3903
 
3904
+ if (
3905
+ (show_image_creation_progress_log == 1) and
3906
+ (callback_step_number <= current_estimated_total_base_model_steps)
3907
+ ):
3908
 
3909
  progress(
3910
  progress = (
 
3967
  (
3968
  ((int(callback_step_index) % image_preview_step_interval) == 0) or
3969
  (seconds_per_step >= image_preview_seconds_interval)
3970
+ ) and
3971
+ (callback_step_number < current_estimated_total_refiner_steps)
3972
  ):
3973
 
3974
  latents = callback_kwargs["latents"]
 
3986
  temporary_extra
3987
  )
3988
 
3989
+ if (
3990
+ (show_image_creation_progress_log == 1) and
3991
+ (callback_step_number <= current_estimated_total_refiner_steps)
3992
+ ):
3993
 
3994
  progress(
3995
  progress = (
 
4049
  (
4050
  ((int(callback_step_index) % image_preview_step_interval) == 0) or
4051
  (seconds_per_step >= image_preview_seconds_interval)
4052
+ ) and
4053
+ (callback_step_number < current_estimated_total_upscaler_steps)
4054
  ):
4055
 
4056
  latents = callback_latents
 
4068
  temporary_extra
4069
  )
4070
 
4071
+ if (
4072
+ (show_image_creation_progress_log == 1) and
4073
+ (callback_step_number <= current_estimated_total_upscaler_steps)
4074
+ ):
4075
 
4076
  progress(
4077
  progress = (
 
4114
 
4115
 
4116
 
 
 
 
 
4117
  if image_processing_is_canceled(user_id_state_value, image_generation_id_state_value):
4118
 
4119
  if show_messages_in_command_prompt == 1:
 
4692
 
4693
  #####################
4694
  #
4695
+ # Cancel Image Function
4696
  #
4697
  # Image generation has not yet started and we need to cancel it.
4698
  #
4699
  #####################
4700
 
4701
+ def cancel_image_function(
 
4702
  user_id_state,
4703
  image_generation_id_state
4704
  ):
 
4706
  user_id_state_value = user_id_state.value
4707
  image_generation_id_state_value = image_generation_id_state.value
4708
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4709
 
4710
 
4711
  global image_generation_ids_object
 
4718
  cancel_image_generation_ids_object[user_id_state_value].append(image_generation_id_state_value)
4719
  cancel_image_generation_times_object[image_generation_id_state_value] = time.time()
4720
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4721
 
 
 
 
4722
 
4723
+ cancel_image_button_update = gr.Button(
4724
+ value = cancel_image_button_in_progress_text,
 
 
 
 
 
 
 
 
 
4725
  interactive = False
4726
  )
4727
 
4728
+ cancel_image_message_field_row_update = gr.Row(
4729
+ visible = True
 
 
 
 
 
 
 
 
4730
  )
4731
 
4732
+ cancel_image_object = {}
4733
 
4734
+ if image_generation_id_state_value == current_image_generation_id_in_progress:
4735
 
4736
+ # If they cancel the image that is currently being generated, we will
4737
+ # stop it after the next step is complete and return the image to
4738
+ # them. They will not need to reload the page again to create another
4739
+ # image.
 
 
 
 
 
 
 
 
4740
 
4741
+ cancel_image_message_field_html = canceled_image_in_process_of_being_generated
4742
 
4743
 
4744
 
4745
+ show_message("Your image generation is being canceled. After the current step in the process is complete, the cancellation will be complete.")
4746
 
4747
 
4748
 
4749
+ generate_image_button_row_update = gr.Row(
4750
+ visible = False
4751
+ )
 
 
 
 
4752
 
4753
+ cancel_image_object.update({
4754
+ generate_image_button_row: generate_image_button_row_update,
4755
+ cancel_image_message_field_row: cancel_image_message_field_row_update
4756
+ })
 
4757
 
4758
+ else:
 
4759
 
4760
+ # If they cancel there place in the queue, we have to make them
4761
+ # reload the page if they want to generate another image.
4762
 
4763
+ cancel_image_message_field_html = canceled_image_in_queue_message
4764
 
4765
+ generate_image_button_update = gr.Button(
4766
+ value = generate_image_button_normal_text,
4767
+ interactive = False
4768
+ )
4769
 
4770
+ output_text_field_update = gr.Textbox(
4771
  visible = True
4772
  )
4773
 
4774
+ output_image_preview_field_row_update = gr.Row(
4775
+ visible = False
4776
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4777
 
4778
+ cancel_image_button_row_update = gr.Row(
4779
+ visible = False
4780
+ )
4781
 
4782
+ cancel_image_object.update({
4783
+ generate_image_button: generate_image_button_update,
4784
+ output_text_field: output_text_field_update,
4785
+ output_image_preview_field_row: output_image_preview_field_row_update,
4786
+ cancel_image_button_row: cancel_image_button_row_update,
4787
+ cancel_image_message_field_row: cancel_image_message_field_row_update
4788
+ })
4789
 
4790
 
 
 
 
4791
 
4792
+ cancel_image_message_field_update = gr.Button(
4793
+ value = cancel_image_message_field_html
 
4794
  )
4795
 
4796
+ cancel_image_object.update({
4797
+ cancel_image_button: cancel_image_button_update,
4798
+ cancel_image_message_field_row: cancel_image_message_field_row_update,
4799
+ cancel_image_message_field: cancel_image_message_field_update
4800
+ })
4801
 
 
 
 
4802
 
 
 
 
4803
 
4804
+ return cancel_image_object
 
 
 
 
 
 
4805
 
4806
 
4807
 
 
5147
 
5148
  add_seed_key_in_url = "add_seed"
5149
 
5150
+ add_seed_to_generation = None
5151
+
5152
  if add_seed_key_in_url in url_object:
5153
 
5154
  add_seed_in_url = url_object[add_seed_key_in_url].lower()
 
5168
 
5169
 
5170
 
5171
+ use_torch_manual_seed_but_not_in_generator_key_in_url = "use_torch_manual_seed_but_not_in_generator"
5172
+
5173
+ if use_torch_manual_seed_but_not_in_generator_key_in_url in url_object:
5174
+
5175
+ use_torch_manual_seed_but_not_in_generator_in_url = url_object[use_torch_manual_seed_but_not_in_generator_key_in_url].lower()
5176
+
5177
+ use_torch_manual_seed_but_not_in_generator_to_generation = False
5178
+
5179
+ if (
5180
+ (use_torch_manual_seed_but_not_in_generator_in_url == "1") or
5181
+ (use_torch_manual_seed_but_not_in_generator_in_url == "y") or
5182
+ (use_torch_manual_seed_but_not_in_generator_in_url == "yes") or
5183
+ (use_torch_manual_seed_but_not_in_generator_in_url == "true")
5184
+ ):
5185
+
5186
+ use_torch_manual_seed_but_not_in_generator_to_generation = True
5187
+
5188
+ if (
5189
+ add_seed_to_generation and
5190
+ add_seed_to_generation == True
5191
+ ):
5192
+
5193
+ use_torch_manual_seed_but_not_in_generator_to_generation = False
5194
+
5195
+ field_object.update({use_torch_manual_seed_but_do_not_add_to_pipe_field: use_torch_manual_seed_but_not_in_generator_to_generation})
5196
+
5197
+
5198
+
5199
  refiner_key_in_url = "refiner"
5200
 
5201
  if refiner_key_in_url in url_object:
 
5554
  interactive = False
5555
  )
5556
 
5557
+ with gr.Row(
5558
  visible = False
5559
+ ) as cancel_image_button_row:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5560
 
5561
+ cancel_image_button = gr.Button(
5562
+ value = cancel_image_button_text,
5563
+ variant = "stop",
5564
+ interactive = False
5565
+ )
 
5566
 
5567
  with gr.Row(
5568
  visible = False
5569
+ ) as cancel_image_message_field_row:
5570
 
5571
  cancel_image_message_field = gr.HTML(
5572
+ value = ""
5573
  )
5574
 
5575
  with gr.Group():
 
5985
  visible = False
5986
  ) as output_image_preview_field_row:
5987
 
5988
+ output_image_preview_field_every_value = None
5989
+
5990
+ if enable_image_preview == 1:
5991
+
5992
+ output_image_preview_field_every_value = load_image_preview_frequency_in_seconds
5993
+
5994
  output_image_preview_field = gr.Image(
5995
  elem_id = "image_preview_id",
5996
+ # value = load_image_preview(user_id_state),
5997
+ # every = output_image_preview_field_every_value,
5998
  label = "Preview",
5999
  type = "pil",
6000
  interactive = False,
 
6097
  elem_classes = "sp_checkbox"
6098
  )
6099
 
6100
+ with gr.Row():
6101
+
6102
+ use_torch_manual_seed_but_do_not_add_to_pipe_field = gr.Checkbox(
6103
+ label = "Use torch.manual_seed, but don't actually add seed to generation (ignored if \"Add seed to generation\" is checked. This is to maintain compatibility with PhotoReal site)",
6104
+ value = default_use_torch_manual_seed_but_do_not_add_to_pipe_is_selected,
6105
+ interactive = True,
6106
+ container = False,
6107
+ elem_classes = "sp_checkbox"
6108
+ )
6109
+
6110
  with gr.Row():
6111
 
6112
  save_or_display_word_text_for_save_base_image = "Display"
 
6474
  base_model_steps_field_for_sdxl_turbo_field,
6475
  seed_field,
6476
  add_seed_into_pipe_field,
6477
+ use_torch_manual_seed_but_do_not_add_to_pipe_field,
6478
 
6479
  refining_selection_field,
6480
  refining_denoise_start_field,
 
6525
  prompt_truncated_field,
6526
  negative_prompt_truncated_field_group,
6527
  negative_prompt_truncated_field,
6528
+ cancel_image_button_row,
6529
+ cancel_image_button,
6530
+ cancel_image_message_field_row,
6531
+ cancel_image_message_field,
 
6532
  error_text_field,
6533
  image_generation_id_state
6534
  ],
 
6565
  output_text_field,
6566
  output_image_preview_field_row,
6567
  generate_image_button_row,
6568
+ cancel_image_button_row,
6569
+ cancel_image_button,
6570
+ cancel_image_message_field_row,
6571
+ cancel_image_message_field
 
 
6572
  ],
6573
  show_progress = "hidden",
6574
  queue = True
 
6631
 
6632
 
6633
 
6634
+ cancel_image_click_event = cancel_image_button.click(
6635
+ fn = cancel_image_function,
6636
  inputs = [
 
6637
  user_id_state,
6638
  image_generation_id_state
6639
  ],
6640
  outputs = [
6641
+ generate_image_button_row,
6642
  generate_image_button,
 
 
6643
  output_text_field,
6644
  output_image_preview_field_row,
6645
+ cancel_image_button_row,
6646
+ cancel_image_button,
6647
+ cancel_image_message_field_row,
6648
+ cancel_image_message_field
 
 
 
6649
  ],
6650
  show_progress = "hidden",
6651
+ cancels = [generate_image_button_click_event],
6652
+ queue = True
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6653
  )
6654
 
6655