Spaces:
				
			
			
	
			
			
		Running
		
			on 
			
			Zero
	
	
	
			
			
	
	
	
	
		
		
		Running
		
			on 
			
			Zero
	Super-squash branch 'main' using huggingface_hub
Browse filesCo-authored-by: John6666 <John6666@users.noreply.huggingface.co>
- .gitattributes +35 -0
- README.md +16 -0
- app.py +1371 -0
- color_image.png +0 -0
- constants.py +585 -0
- image.webp +0 -0
- image_processor.py +130 -0
- packages.txt +3 -0
- requirements.txt +5 -0
- spiral_no_transparent.png +0 -0
- utils.py +485 -0
    	
        .gitattributes
    ADDED
    
    | @@ -0,0 +1,35 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            *.7z filter=lfs diff=lfs merge=lfs -text
         | 
| 2 | 
            +
            *.arrow filter=lfs diff=lfs merge=lfs -text
         | 
| 3 | 
            +
            *.bin filter=lfs diff=lfs merge=lfs -text
         | 
| 4 | 
            +
            *.bz2 filter=lfs diff=lfs merge=lfs -text
         | 
| 5 | 
            +
            *.ckpt filter=lfs diff=lfs merge=lfs -text
         | 
| 6 | 
            +
            *.ftz filter=lfs diff=lfs merge=lfs -text
         | 
| 7 | 
            +
            *.gz filter=lfs diff=lfs merge=lfs -text
         | 
| 8 | 
            +
            *.h5 filter=lfs diff=lfs merge=lfs -text
         | 
| 9 | 
            +
            *.joblib filter=lfs diff=lfs merge=lfs -text
         | 
| 10 | 
            +
            *.lfs.* filter=lfs diff=lfs merge=lfs -text
         | 
| 11 | 
            +
            *.mlmodel filter=lfs diff=lfs merge=lfs -text
         | 
| 12 | 
            +
            *.model filter=lfs diff=lfs merge=lfs -text
         | 
| 13 | 
            +
            *.msgpack filter=lfs diff=lfs merge=lfs -text
         | 
| 14 | 
            +
            *.npy filter=lfs diff=lfs merge=lfs -text
         | 
| 15 | 
            +
            *.npz filter=lfs diff=lfs merge=lfs -text
         | 
| 16 | 
            +
            *.onnx filter=lfs diff=lfs merge=lfs -text
         | 
| 17 | 
            +
            *.ot filter=lfs diff=lfs merge=lfs -text
         | 
| 18 | 
            +
            *.parquet filter=lfs diff=lfs merge=lfs -text
         | 
| 19 | 
            +
            *.pb filter=lfs diff=lfs merge=lfs -text
         | 
| 20 | 
            +
            *.pickle filter=lfs diff=lfs merge=lfs -text
         | 
| 21 | 
            +
            *.pkl filter=lfs diff=lfs merge=lfs -text
         | 
| 22 | 
            +
            *.pt filter=lfs diff=lfs merge=lfs -text
         | 
| 23 | 
            +
            *.pth filter=lfs diff=lfs merge=lfs -text
         | 
| 24 | 
            +
            *.rar filter=lfs diff=lfs merge=lfs -text
         | 
| 25 | 
            +
            *.safetensors filter=lfs diff=lfs merge=lfs -text
         | 
| 26 | 
            +
            saved_model/**/* filter=lfs diff=lfs merge=lfs -text
         | 
| 27 | 
            +
            *.tar.* filter=lfs diff=lfs merge=lfs -text
         | 
| 28 | 
            +
            *.tar filter=lfs diff=lfs merge=lfs -text
         | 
| 29 | 
            +
            *.tflite filter=lfs diff=lfs merge=lfs -text
         | 
| 30 | 
            +
            *.tgz filter=lfs diff=lfs merge=lfs -text
         | 
| 31 | 
            +
            *.wasm filter=lfs diff=lfs merge=lfs -text
         | 
| 32 | 
            +
            *.xz filter=lfs diff=lfs merge=lfs -text
         | 
| 33 | 
            +
            *.zip filter=lfs diff=lfs merge=lfs -text
         | 
| 34 | 
            +
            *.zst filter=lfs diff=lfs merge=lfs -text
         | 
| 35 | 
            +
            *tfevents* filter=lfs diff=lfs merge=lfs -text
         | 
    	
        README.md
    ADDED
    
    | @@ -0,0 +1,16 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            title: 🧩 DiffuseCraft
         | 
| 3 | 
            +
            emoji: 🧩🖼️
         | 
| 4 | 
            +
            colorFrom: red
         | 
| 5 | 
            +
            colorTo: pink
         | 
| 6 | 
            +
            sdk: gradio
         | 
| 7 | 
            +
            sdk_version: 4.31.3
         | 
| 8 | 
            +
            app_file: app.py
         | 
| 9 | 
            +
            pinned: true
         | 
| 10 | 
            +
            license: mit
         | 
| 11 | 
            +
            short_description: Stunning images using stable diffusion.
         | 
| 12 | 
            +
            preload_from_hub:
         | 
| 13 | 
            +
              - madebyollin/sdxl-vae-fp16-fix config.json,diffusion_pytorch_model.safetensors
         | 
| 14 | 
            +
            ---
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
         | 
    	
        app.py
    ADDED
    
    | @@ -0,0 +1,1371 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            import spaces
         | 
| 2 | 
            +
            import os
         | 
| 3 | 
            +
            from stablepy import (
         | 
| 4 | 
            +
                Model_Diffusers,
         | 
| 5 | 
            +
                SCHEDULE_TYPE_OPTIONS,
         | 
| 6 | 
            +
                SCHEDULE_PREDICTION_TYPE_OPTIONS,
         | 
| 7 | 
            +
                check_scheduler_compatibility,
         | 
| 8 | 
            +
                TASK_AND_PREPROCESSORS,
         | 
| 9 | 
            +
                FACE_RESTORATION_MODELS,
         | 
| 10 | 
            +
                scheduler_names,
         | 
| 11 | 
            +
            )
         | 
| 12 | 
            +
            from constants import (
         | 
| 13 | 
            +
                DIRECTORY_MODELS,
         | 
| 14 | 
            +
                DIRECTORY_LORAS,
         | 
| 15 | 
            +
                DIRECTORY_VAES,
         | 
| 16 | 
            +
                DIRECTORY_EMBEDS,
         | 
| 17 | 
            +
                DIRECTORY_UPSCALERS,
         | 
| 18 | 
            +
                DOWNLOAD_MODEL,
         | 
| 19 | 
            +
                DOWNLOAD_VAE,
         | 
| 20 | 
            +
                DOWNLOAD_LORA,
         | 
| 21 | 
            +
                LOAD_DIFFUSERS_FORMAT_MODEL,
         | 
| 22 | 
            +
                DIFFUSERS_FORMAT_LORAS,
         | 
| 23 | 
            +
                DOWNLOAD_EMBEDS,
         | 
| 24 | 
            +
                CIVITAI_API_KEY,
         | 
| 25 | 
            +
                HF_TOKEN,
         | 
| 26 | 
            +
                TASK_STABLEPY,
         | 
| 27 | 
            +
                TASK_MODEL_LIST,
         | 
| 28 | 
            +
                UPSCALER_DICT_GUI,
         | 
| 29 | 
            +
                UPSCALER_KEYS,
         | 
| 30 | 
            +
                PROMPT_W_OPTIONS,
         | 
| 31 | 
            +
                WARNING_MSG_VAE,
         | 
| 32 | 
            +
                SDXL_TASK,
         | 
| 33 | 
            +
                MODEL_TYPE_TASK,
         | 
| 34 | 
            +
                POST_PROCESSING_SAMPLER,
         | 
| 35 | 
            +
                SUBTITLE_GUI,
         | 
| 36 | 
            +
                HELP_GUI,
         | 
| 37 | 
            +
                EXAMPLES_GUI_HELP,
         | 
| 38 | 
            +
                EXAMPLES_GUI,
         | 
| 39 | 
            +
                RESOURCES,
         | 
| 40 | 
            +
                DIFFUSERS_CONTROLNET_MODEL,
         | 
| 41 | 
            +
                IP_MODELS,
         | 
| 42 | 
            +
                MODE_IP_OPTIONS,
         | 
| 43 | 
            +
            )
         | 
| 44 | 
            +
            from stablepy.diffusers_vanilla.style_prompt_config import STYLE_NAMES
         | 
| 45 | 
            +
            import torch
         | 
| 46 | 
            +
            import re
         | 
| 47 | 
            +
            import time
         | 
| 48 | 
            +
            from PIL import ImageFile
         | 
| 49 | 
            +
            from utils import (
         | 
| 50 | 
            +
                download_things,
         | 
| 51 | 
            +
                get_model_list,
         | 
| 52 | 
            +
                extract_parameters,
         | 
| 53 | 
            +
                get_my_lora,
         | 
| 54 | 
            +
                get_model_type,
         | 
| 55 | 
            +
                extract_exif_data,
         | 
| 56 | 
            +
                create_mask_now,
         | 
| 57 | 
            +
                download_diffuser_repo,
         | 
| 58 | 
            +
                get_used_storage_gb,
         | 
| 59 | 
            +
                delete_model,
         | 
| 60 | 
            +
                progress_step_bar,
         | 
| 61 | 
            +
                html_template_message,
         | 
| 62 | 
            +
                escape_html,
         | 
| 63 | 
            +
            )
         | 
| 64 | 
            +
            from image_processor import preprocessor_tab
         | 
| 65 | 
            +
            from datetime import datetime
         | 
| 66 | 
            +
            import gradio as gr
         | 
| 67 | 
            +
            import logging
         | 
| 68 | 
            +
            import diffusers
         | 
| 69 | 
            +
            import warnings
         | 
| 70 | 
            +
            from stablepy import logger
         | 
| 71 | 
            +
            from diffusers import FluxPipeline
         | 
| 72 | 
            +
            # import urllib.parse
         | 
| 73 | 
            +
            import subprocess
         | 
| 74 | 
            +
             | 
| 75 | 
            +
            subprocess.run("rm -rf /data-nvme/zerogpu-offload/*", env={}, shell=True)
         | 
| 76 | 
            +
            ImageFile.LOAD_TRUNCATED_IMAGES = True
         | 
| 77 | 
            +
            torch.backends.cuda.matmul.allow_tf32 = True
         | 
| 78 | 
            +
            # os.environ["PYTORCH_NO_CUDA_MEMORY_CACHING"] = "1"
         | 
| 79 | 
            +
            print(os.getenv("SPACES_ZERO_GPU"))
         | 
| 80 | 
            +
             | 
| 81 | 
            +
            directories = [DIRECTORY_MODELS, DIRECTORY_LORAS, DIRECTORY_VAES, DIRECTORY_EMBEDS, DIRECTORY_UPSCALERS]
         | 
| 82 | 
            +
            for directory in directories:
         | 
| 83 | 
            +
                os.makedirs(directory, exist_ok=True)
         | 
| 84 | 
            +
             | 
| 85 | 
            +
            # Download stuffs
         | 
| 86 | 
            +
            for url in [url.strip() for url in DOWNLOAD_MODEL.split(',')]:
         | 
| 87 | 
            +
                if not os.path.exists(f"./models/{url.split('/')[-1]}"):
         | 
| 88 | 
            +
                    download_things(DIRECTORY_MODELS, url, HF_TOKEN, CIVITAI_API_KEY)
         | 
| 89 | 
            +
            for url in [url.strip() for url in DOWNLOAD_VAE.split(',')]:
         | 
| 90 | 
            +
                if not os.path.exists(f"./vaes/{url.split('/')[-1]}"):
         | 
| 91 | 
            +
                    download_things(DIRECTORY_VAES, url, HF_TOKEN, CIVITAI_API_KEY)
         | 
| 92 | 
            +
            for url in [url.strip() for url in DOWNLOAD_LORA.split(',')]:
         | 
| 93 | 
            +
                if not os.path.exists(f"./loras/{url.split('/')[-1]}"):
         | 
| 94 | 
            +
                    download_things(DIRECTORY_LORAS, url, HF_TOKEN, CIVITAI_API_KEY)
         | 
| 95 | 
            +
             | 
| 96 | 
            +
            # Download Embeddings
         | 
| 97 | 
            +
            for url_embed in DOWNLOAD_EMBEDS:
         | 
| 98 | 
            +
                if not os.path.exists(f"./embedings/{url_embed.split('/')[-1]}"):
         | 
| 99 | 
            +
                    download_things(DIRECTORY_EMBEDS, url_embed, HF_TOKEN, CIVITAI_API_KEY)
         | 
| 100 | 
            +
             | 
| 101 | 
            +
            # Build list models
         | 
| 102 | 
            +
            embed_list = get_model_list(DIRECTORY_EMBEDS)
         | 
| 103 | 
            +
            embed_list = [
         | 
| 104 | 
            +
                (os.path.splitext(os.path.basename(emb))[0], emb) for emb in embed_list
         | 
| 105 | 
            +
            ]
         | 
| 106 | 
            +
            single_file_model_list = get_model_list(DIRECTORY_MODELS)
         | 
| 107 | 
            +
            model_list = LOAD_DIFFUSERS_FORMAT_MODEL + single_file_model_list
         | 
| 108 | 
            +
            lora_model_list = get_model_list(DIRECTORY_LORAS)
         | 
| 109 | 
            +
            lora_model_list.insert(0, "None")
         | 
| 110 | 
            +
            lora_model_list = lora_model_list + DIFFUSERS_FORMAT_LORAS
         | 
| 111 | 
            +
            vae_model_list = get_model_list(DIRECTORY_VAES)
         | 
| 112 | 
            +
            vae_model_list.insert(0, "BakedVAE")
         | 
| 113 | 
            +
            vae_model_list.insert(0, "None")
         | 
| 114 | 
            +
             | 
| 115 | 
            +
            print('\033[33m🏁 Download and listing of valid models completed.\033[0m')
         | 
| 116 | 
            +
             | 
| 117 | 
            +
            flux_repo = "camenduru/FLUX.1-dev-diffusers"
         | 
| 118 | 
            +
            flux_pipe = FluxPipeline.from_pretrained(
         | 
| 119 | 
            +
                flux_repo,
         | 
| 120 | 
            +
                transformer=None,
         | 
| 121 | 
            +
                torch_dtype=torch.bfloat16,
         | 
| 122 | 
            +
            ).to("cuda")
         | 
| 123 | 
            +
            components = flux_pipe.components
         | 
| 124 | 
            +
            delete_model(flux_repo)
         | 
| 125 | 
            +
            # components = None
         | 
| 126 | 
            +
             | 
| 127 | 
            +
            #######################
         | 
| 128 | 
            +
            # GUI
         | 
| 129 | 
            +
            #######################
         | 
| 130 | 
            +
            logging.getLogger("diffusers").setLevel(logging.ERROR)
         | 
| 131 | 
            +
            diffusers.utils.logging.set_verbosity(40)
         | 
| 132 | 
            +
            warnings.filterwarnings(action="ignore", category=FutureWarning, module="diffusers")
         | 
| 133 | 
            +
            warnings.filterwarnings(action="ignore", category=UserWarning, module="diffusers")
         | 
| 134 | 
            +
            warnings.filterwarnings(action="ignore", category=FutureWarning, module="transformers")
         | 
| 135 | 
            +
            logger.setLevel(logging.DEBUG)
         | 
| 136 | 
            +
             | 
| 137 | 
            +
            CSS = """
         | 
| 138 | 
            +
            .contain { display: flex; flex-direction: column; }
         | 
| 139 | 
            +
            #component-0 { height: 100%; }
         | 
| 140 | 
            +
            #gallery { flex-grow: 1; }
         | 
| 141 | 
            +
            #load_model { height: 50px; }
         | 
| 142 | 
            +
            """
         | 
| 143 | 
            +
             | 
| 144 | 
            +
             | 
| 145 | 
            +
            class GuiSD:
         | 
| 146 | 
            +
                def __init__(self, stream=True):
         | 
| 147 | 
            +
                    self.model = None
         | 
| 148 | 
            +
                    self.status_loading = False
         | 
| 149 | 
            +
                    self.sleep_loading = 4
         | 
| 150 | 
            +
                    self.last_load = datetime.now()
         | 
| 151 | 
            +
                    self.inventory = []
         | 
| 152 | 
            +
             | 
| 153 | 
            +
                def update_storage_models(self, storage_floor_gb=24, required_inventory_for_purge=3):
         | 
| 154 | 
            +
                    while get_used_storage_gb() > storage_floor_gb:
         | 
| 155 | 
            +
                        if len(self.inventory) < required_inventory_for_purge:
         | 
| 156 | 
            +
                            break
         | 
| 157 | 
            +
                        removal_candidate = self.inventory.pop(0)
         | 
| 158 | 
            +
                        delete_model(removal_candidate)
         | 
| 159 | 
            +
             | 
| 160 | 
            +
                def update_inventory(self, model_name):
         | 
| 161 | 
            +
                    if model_name not in single_file_model_list:
         | 
| 162 | 
            +
                        self.inventory = [
         | 
| 163 | 
            +
                            m for m in self.inventory if m != model_name
         | 
| 164 | 
            +
                        ] + [model_name]
         | 
| 165 | 
            +
                    print(self.inventory)
         | 
| 166 | 
            +
             | 
| 167 | 
            +
                def load_new_model(self, model_name, vae_model, task, controlnet_model, progress=gr.Progress(track_tqdm=True)):
         | 
| 168 | 
            +
             | 
| 169 | 
            +
                    # download link model > model_name
         | 
| 170 | 
            +
             | 
| 171 | 
            +
                    self.update_storage_models()
         | 
| 172 | 
            +
             | 
| 173 | 
            +
                    vae_model = vae_model if vae_model != "None" else None
         | 
| 174 | 
            +
                    model_type = get_model_type(model_name)
         | 
| 175 | 
            +
                    dtype_model = torch.bfloat16 if model_type == "FLUX" else torch.float16
         | 
| 176 | 
            +
             | 
| 177 | 
            +
                    if not os.path.exists(model_name):
         | 
| 178 | 
            +
                        _ = download_diffuser_repo(
         | 
| 179 | 
            +
                            repo_name=model_name,
         | 
| 180 | 
            +
                            model_type=model_type,
         | 
| 181 | 
            +
                            revision="main",
         | 
| 182 | 
            +
                            token=True,
         | 
| 183 | 
            +
                        )
         | 
| 184 | 
            +
             | 
| 185 | 
            +
                    self.update_inventory(model_name)
         | 
| 186 | 
            +
             | 
| 187 | 
            +
                    for i in range(68):
         | 
| 188 | 
            +
                        if not self.status_loading:
         | 
| 189 | 
            +
                            self.status_loading = True
         | 
| 190 | 
            +
                            if i > 0:
         | 
| 191 | 
            +
                                time.sleep(self.sleep_loading)
         | 
| 192 | 
            +
                                print("Previous model ops...")
         | 
| 193 | 
            +
                            break
         | 
| 194 | 
            +
                        time.sleep(0.5)
         | 
| 195 | 
            +
                        print(f"Waiting queue {i}")
         | 
| 196 | 
            +
                        yield "Waiting queue"
         | 
| 197 | 
            +
             | 
| 198 | 
            +
                    self.status_loading = True
         | 
| 199 | 
            +
             | 
| 200 | 
            +
                    yield f"Loading model: {model_name}"
         | 
| 201 | 
            +
             | 
| 202 | 
            +
                    if vae_model == "BakedVAE":
         | 
| 203 | 
            +
                        vae_model = model_name
         | 
| 204 | 
            +
                    elif vae_model:
         | 
| 205 | 
            +
                        vae_type = "SDXL" if "sdxl" in vae_model.lower() else "SD 1.5"
         | 
| 206 | 
            +
                        if model_type != vae_type:
         | 
| 207 | 
            +
                            gr.Warning(WARNING_MSG_VAE)
         | 
| 208 | 
            +
             | 
| 209 | 
            +
                    print("Loading model...")
         | 
| 210 | 
            +
             | 
| 211 | 
            +
                    try:
         | 
| 212 | 
            +
                        start_time = time.time()
         | 
| 213 | 
            +
             | 
| 214 | 
            +
                        if self.model is None:
         | 
| 215 | 
            +
                            self.model = Model_Diffusers(
         | 
| 216 | 
            +
                                base_model_id=model_name,
         | 
| 217 | 
            +
                                task_name=TASK_STABLEPY[task],
         | 
| 218 | 
            +
                                vae_model=vae_model,
         | 
| 219 | 
            +
                                type_model_precision=dtype_model,
         | 
| 220 | 
            +
                                retain_task_model_in_cache=False,
         | 
| 221 | 
            +
                                controlnet_model=controlnet_model,
         | 
| 222 | 
            +
                                device="cpu",
         | 
| 223 | 
            +
                                env_components=components,
         | 
| 224 | 
            +
                            )
         | 
| 225 | 
            +
                            self.model.advanced_params(image_preprocessor_cuda_active=True)
         | 
| 226 | 
            +
                        else:
         | 
| 227 | 
            +
                            if self.model.base_model_id != model_name:
         | 
| 228 | 
            +
                                load_now_time = datetime.now()
         | 
| 229 | 
            +
                                elapsed_time = max((load_now_time - self.last_load).total_seconds(), 0)
         | 
| 230 | 
            +
             | 
| 231 | 
            +
                                if elapsed_time <= 9:
         | 
| 232 | 
            +
                                    print("Waiting for the previous model's time ops...")
         | 
| 233 | 
            +
                                    time.sleep(9 - elapsed_time)
         | 
| 234 | 
            +
             | 
| 235 | 
            +
                            self.model.device = torch.device("cpu")
         | 
| 236 | 
            +
                            self.model.load_pipe(
         | 
| 237 | 
            +
                                model_name,
         | 
| 238 | 
            +
                                task_name=TASK_STABLEPY[task],
         | 
| 239 | 
            +
                                vae_model=vae_model,
         | 
| 240 | 
            +
                                type_model_precision=dtype_model,
         | 
| 241 | 
            +
                                retain_task_model_in_cache=False,
         | 
| 242 | 
            +
                                controlnet_model=controlnet_model,
         | 
| 243 | 
            +
                            )
         | 
| 244 | 
            +
             | 
| 245 | 
            +
                        end_time = time.time()
         | 
| 246 | 
            +
                        self.sleep_loading = max(min(int(end_time - start_time), 10), 4)
         | 
| 247 | 
            +
                    except Exception as e:
         | 
| 248 | 
            +
                        self.last_load = datetime.now()
         | 
| 249 | 
            +
                        self.status_loading = False
         | 
| 250 | 
            +
                        self.sleep_loading = 4
         | 
| 251 | 
            +
                        raise e
         | 
| 252 | 
            +
             | 
| 253 | 
            +
                    self.last_load = datetime.now()
         | 
| 254 | 
            +
                    self.status_loading = False
         | 
| 255 | 
            +
             | 
| 256 | 
            +
                    yield f"Model loaded: {model_name}"
         | 
| 257 | 
            +
             | 
| 258 | 
            +
                # @spaces.GPU(duration=59)
         | 
| 259 | 
            +
                @torch.inference_mode()
         | 
| 260 | 
            +
                def generate_pipeline(
         | 
| 261 | 
            +
                    self,
         | 
| 262 | 
            +
                    prompt,
         | 
| 263 | 
            +
                    neg_prompt,
         | 
| 264 | 
            +
                    num_images,
         | 
| 265 | 
            +
                    steps,
         | 
| 266 | 
            +
                    cfg,
         | 
| 267 | 
            +
                    clip_skip,
         | 
| 268 | 
            +
                    seed,
         | 
| 269 | 
            +
                    lora1,
         | 
| 270 | 
            +
                    lora_scale1,
         | 
| 271 | 
            +
                    lora2,
         | 
| 272 | 
            +
                    lora_scale2,
         | 
| 273 | 
            +
                    lora3,
         | 
| 274 | 
            +
                    lora_scale3,
         | 
| 275 | 
            +
                    lora4,
         | 
| 276 | 
            +
                    lora_scale4,
         | 
| 277 | 
            +
                    lora5,
         | 
| 278 | 
            +
                    lora_scale5,
         | 
| 279 | 
            +
                    lora6,
         | 
| 280 | 
            +
                    lora_scale6,
         | 
| 281 | 
            +
                    lora7,
         | 
| 282 | 
            +
                    lora_scale7,
         | 
| 283 | 
            +
                    sampler,
         | 
| 284 | 
            +
                    schedule_type,
         | 
| 285 | 
            +
                    schedule_prediction_type,
         | 
| 286 | 
            +
                    img_height,
         | 
| 287 | 
            +
                    img_width,
         | 
| 288 | 
            +
                    model_name,
         | 
| 289 | 
            +
                    vae_model,
         | 
| 290 | 
            +
                    task,
         | 
| 291 | 
            +
                    image_control,
         | 
| 292 | 
            +
                    preprocessor_name,
         | 
| 293 | 
            +
                    preprocess_resolution,
         | 
| 294 | 
            +
                    image_resolution,
         | 
| 295 | 
            +
                    style_prompt,  # list []
         | 
| 296 | 
            +
                    style_json_file,
         | 
| 297 | 
            +
                    image_mask,
         | 
| 298 | 
            +
                    strength,
         | 
| 299 | 
            +
                    low_threshold,
         | 
| 300 | 
            +
                    high_threshold,
         | 
| 301 | 
            +
                    value_threshold,
         | 
| 302 | 
            +
                    distance_threshold,
         | 
| 303 | 
            +
                    recolor_gamma_correction,
         | 
| 304 | 
            +
                    tile_blur_sigma,
         | 
| 305 | 
            +
                    controlnet_output_scaling_in_unet,
         | 
| 306 | 
            +
                    controlnet_start_threshold,
         | 
| 307 | 
            +
                    controlnet_stop_threshold,
         | 
| 308 | 
            +
                    textual_inversion,
         | 
| 309 | 
            +
                    syntax_weights,
         | 
| 310 | 
            +
                    upscaler_model_path,
         | 
| 311 | 
            +
                    upscaler_increases_size,
         | 
| 312 | 
            +
                    upscaler_tile_size,
         | 
| 313 | 
            +
                    upscaler_tile_overlap,
         | 
| 314 | 
            +
                    hires_steps,
         | 
| 315 | 
            +
                    hires_denoising_strength,
         | 
| 316 | 
            +
                    hires_sampler,
         | 
| 317 | 
            +
                    hires_prompt,
         | 
| 318 | 
            +
                    hires_negative_prompt,
         | 
| 319 | 
            +
                    hires_before_adetailer,
         | 
| 320 | 
            +
                    hires_after_adetailer,
         | 
| 321 | 
            +
                    hires_schedule_type,
         | 
| 322 | 
            +
                    hires_guidance_scale,
         | 
| 323 | 
            +
                    controlnet_model,
         | 
| 324 | 
            +
                    loop_generation,
         | 
| 325 | 
            +
                    leave_progress_bar,
         | 
| 326 | 
            +
                    disable_progress_bar,
         | 
| 327 | 
            +
                    image_previews,
         | 
| 328 | 
            +
                    display_images,
         | 
| 329 | 
            +
                    save_generated_images,
         | 
| 330 | 
            +
                    filename_pattern,
         | 
| 331 | 
            +
                    image_storage_location,
         | 
| 332 | 
            +
                    retain_compel_previous_load,
         | 
| 333 | 
            +
                    retain_detailfix_model_previous_load,
         | 
| 334 | 
            +
                    retain_hires_model_previous_load,
         | 
| 335 | 
            +
                    t2i_adapter_preprocessor,
         | 
| 336 | 
            +
                    t2i_adapter_conditioning_scale,
         | 
| 337 | 
            +
                    t2i_adapter_conditioning_factor,
         | 
| 338 | 
            +
                    xformers_memory_efficient_attention,
         | 
| 339 | 
            +
                    freeu,
         | 
| 340 | 
            +
                    generator_in_cpu,
         | 
| 341 | 
            +
                    adetailer_inpaint_only,
         | 
| 342 | 
            +
                    adetailer_verbose,
         | 
| 343 | 
            +
                    adetailer_sampler,
         | 
| 344 | 
            +
                    adetailer_active_a,
         | 
| 345 | 
            +
                    prompt_ad_a,
         | 
| 346 | 
            +
                    negative_prompt_ad_a,
         | 
| 347 | 
            +
                    strength_ad_a,
         | 
| 348 | 
            +
                    face_detector_ad_a,
         | 
| 349 | 
            +
                    person_detector_ad_a,
         | 
| 350 | 
            +
                    hand_detector_ad_a,
         | 
| 351 | 
            +
                    mask_dilation_a,
         | 
| 352 | 
            +
                    mask_blur_a,
         | 
| 353 | 
            +
                    mask_padding_a,
         | 
| 354 | 
            +
                    adetailer_active_b,
         | 
| 355 | 
            +
                    prompt_ad_b,
         | 
| 356 | 
            +
                    negative_prompt_ad_b,
         | 
| 357 | 
            +
                    strength_ad_b,
         | 
| 358 | 
            +
                    face_detector_ad_b,
         | 
| 359 | 
            +
                    person_detector_ad_b,
         | 
| 360 | 
            +
                    hand_detector_ad_b,
         | 
| 361 | 
            +
                    mask_dilation_b,
         | 
| 362 | 
            +
                    mask_blur_b,
         | 
| 363 | 
            +
                    mask_padding_b,
         | 
| 364 | 
            +
                    retain_task_cache_gui,
         | 
| 365 | 
            +
                    guidance_rescale,
         | 
| 366 | 
            +
                    image_ip1,
         | 
| 367 | 
            +
                    mask_ip1,
         | 
| 368 | 
            +
                    model_ip1,
         | 
| 369 | 
            +
                    mode_ip1,
         | 
| 370 | 
            +
                    scale_ip1,
         | 
| 371 | 
            +
                    image_ip2,
         | 
| 372 | 
            +
                    mask_ip2,
         | 
| 373 | 
            +
                    model_ip2,
         | 
| 374 | 
            +
                    mode_ip2,
         | 
| 375 | 
            +
                    scale_ip2,
         | 
| 376 | 
            +
                    pag_scale,
         | 
| 377 | 
            +
                    face_restoration_model,
         | 
| 378 | 
            +
                    face_restoration_visibility,
         | 
| 379 | 
            +
                    face_restoration_weight,
         | 
| 380 | 
            +
                ):
         | 
| 381 | 
            +
                    info_state = html_template_message("Navigating latent space...")
         | 
| 382 | 
            +
                    yield info_state, gr.update(), gr.update()
         | 
| 383 | 
            +
             | 
| 384 | 
            +
                    vae_model = vae_model if vae_model != "None" else None
         | 
| 385 | 
            +
                    loras_list = [lora1, lora2, lora3, lora4, lora5, lora6, lora7]
         | 
| 386 | 
            +
                    vae_msg = f"VAE: {vae_model}" if vae_model else ""
         | 
| 387 | 
            +
                    msg_lora = ""
         | 
| 388 | 
            +
             | 
| 389 | 
            +
                    print("Config model:", model_name, vae_model, loras_list)
         | 
| 390 | 
            +
             | 
| 391 | 
            +
                    task = TASK_STABLEPY[task]
         | 
| 392 | 
            +
             | 
| 393 | 
            +
                    params_ip_img = []
         | 
| 394 | 
            +
                    params_ip_msk = []
         | 
| 395 | 
            +
                    params_ip_model = []
         | 
| 396 | 
            +
                    params_ip_mode = []
         | 
| 397 | 
            +
                    params_ip_scale = []
         | 
| 398 | 
            +
             | 
| 399 | 
            +
                    all_adapters = [
         | 
| 400 | 
            +
                        (image_ip1, mask_ip1, model_ip1, mode_ip1, scale_ip1),
         | 
| 401 | 
            +
                        (image_ip2, mask_ip2, model_ip2, mode_ip2, scale_ip2),
         | 
| 402 | 
            +
                    ]
         | 
| 403 | 
            +
             | 
| 404 | 
            +
                    if not hasattr(self.model.pipe, "transformer"):
         | 
| 405 | 
            +
                        for imgip, mskip, modelip, modeip, scaleip in all_adapters:
         | 
| 406 | 
            +
                            if imgip:
         | 
| 407 | 
            +
                                params_ip_img.append(imgip)
         | 
| 408 | 
            +
                                if mskip:
         | 
| 409 | 
            +
                                    params_ip_msk.append(mskip)
         | 
| 410 | 
            +
                                params_ip_model.append(modelip)
         | 
| 411 | 
            +
                                params_ip_mode.append(modeip)
         | 
| 412 | 
            +
                                params_ip_scale.append(scaleip)
         | 
| 413 | 
            +
             | 
| 414 | 
            +
                    concurrency = 5
         | 
| 415 | 
            +
                    self.model.stream_config(concurrency=concurrency, latent_resize_by=1, vae_decoding=False)
         | 
| 416 | 
            +
             | 
| 417 | 
            +
                    if task != "txt2img" and not image_control:
         | 
| 418 | 
            +
                        raise ValueError("Reference image is required. Please upload one in 'Image ControlNet/Inpaint/Img2img'.")
         | 
| 419 | 
            +
             | 
| 420 | 
            +
                    if task in ["inpaint", "repaint"] and not image_mask:
         | 
| 421 | 
            +
                        raise ValueError("Mask image not found. Upload one in 'Image Mask' to proceed.")
         | 
| 422 | 
            +
             | 
| 423 | 
            +
                    if "https://" not in str(UPSCALER_DICT_GUI[upscaler_model_path]):
         | 
| 424 | 
            +
                        upscaler_model = upscaler_model_path
         | 
| 425 | 
            +
                    else:
         | 
| 426 | 
            +
                        url_upscaler = UPSCALER_DICT_GUI[upscaler_model_path]
         | 
| 427 | 
            +
             | 
| 428 | 
            +
                        if not os.path.exists(f"./{DIRECTORY_UPSCALERS}/{url_upscaler.split('/')[-1]}"):
         | 
| 429 | 
            +
                            download_things(DIRECTORY_UPSCALERS, url_upscaler, HF_TOKEN)
         | 
| 430 | 
            +
             | 
| 431 | 
            +
                        upscaler_model = f"./{DIRECTORY_UPSCALERS}/{url_upscaler.split('/')[-1]}"
         | 
| 432 | 
            +
             | 
| 433 | 
            +
                    logging.getLogger("ultralytics").setLevel(logging.INFO if adetailer_verbose else logging.ERROR)
         | 
| 434 | 
            +
             | 
| 435 | 
            +
                    adetailer_params_A = {
         | 
| 436 | 
            +
                        "face_detector_ad": face_detector_ad_a,
         | 
| 437 | 
            +
                        "person_detector_ad": person_detector_ad_a,
         | 
| 438 | 
            +
                        "hand_detector_ad": hand_detector_ad_a,
         | 
| 439 | 
            +
                        "prompt": prompt_ad_a,
         | 
| 440 | 
            +
                        "negative_prompt": negative_prompt_ad_a,
         | 
| 441 | 
            +
                        "strength": strength_ad_a,
         | 
| 442 | 
            +
                        # "image_list_task" : None,
         | 
| 443 | 
            +
                        "mask_dilation": mask_dilation_a,
         | 
| 444 | 
            +
                        "mask_blur": mask_blur_a,
         | 
| 445 | 
            +
                        "mask_padding": mask_padding_a,
         | 
| 446 | 
            +
                        "inpaint_only": adetailer_inpaint_only,
         | 
| 447 | 
            +
                        "sampler": adetailer_sampler,
         | 
| 448 | 
            +
                    }
         | 
| 449 | 
            +
             | 
| 450 | 
            +
                    adetailer_params_B = {
         | 
| 451 | 
            +
                        "face_detector_ad": face_detector_ad_b,
         | 
| 452 | 
            +
                        "person_detector_ad": person_detector_ad_b,
         | 
| 453 | 
            +
                        "hand_detector_ad": hand_detector_ad_b,
         | 
| 454 | 
            +
                        "prompt": prompt_ad_b,
         | 
| 455 | 
            +
                        "negative_prompt": negative_prompt_ad_b,
         | 
| 456 | 
            +
                        "strength": strength_ad_b,
         | 
| 457 | 
            +
                        # "image_list_task" : None,
         | 
| 458 | 
            +
                        "mask_dilation": mask_dilation_b,
         | 
| 459 | 
            +
                        "mask_blur": mask_blur_b,
         | 
| 460 | 
            +
                        "mask_padding": mask_padding_b,
         | 
| 461 | 
            +
                    }
         | 
| 462 | 
            +
                    pipe_params = {
         | 
| 463 | 
            +
                        "prompt": prompt,
         | 
| 464 | 
            +
                        "negative_prompt": neg_prompt,
         | 
| 465 | 
            +
                        "img_height": img_height,
         | 
| 466 | 
            +
                        "img_width": img_width,
         | 
| 467 | 
            +
                        "num_images": num_images,
         | 
| 468 | 
            +
                        "num_steps": steps,
         | 
| 469 | 
            +
                        "guidance_scale": cfg,
         | 
| 470 | 
            +
                        "clip_skip": clip_skip,
         | 
| 471 | 
            +
                        "pag_scale": float(pag_scale),
         | 
| 472 | 
            +
                        "seed": seed,
         | 
| 473 | 
            +
                        "image": image_control,
         | 
| 474 | 
            +
                        "preprocessor_name": preprocessor_name,
         | 
| 475 | 
            +
                        "preprocess_resolution": preprocess_resolution,
         | 
| 476 | 
            +
                        "image_resolution": image_resolution,
         | 
| 477 | 
            +
                        "style_prompt": style_prompt if style_prompt else "",
         | 
| 478 | 
            +
                        "style_json_file": "",
         | 
| 479 | 
            +
                        "image_mask": image_mask,  # only for Inpaint
         | 
| 480 | 
            +
                        "strength": strength,  # only for Inpaint or ...
         | 
| 481 | 
            +
                        "low_threshold": low_threshold,
         | 
| 482 | 
            +
                        "high_threshold": high_threshold,
         | 
| 483 | 
            +
                        "value_threshold": value_threshold,
         | 
| 484 | 
            +
                        "distance_threshold": distance_threshold,
         | 
| 485 | 
            +
                        "recolor_gamma_correction": float(recolor_gamma_correction),
         | 
| 486 | 
            +
                        "tile_blur_sigma": int(tile_blur_sigma),
         | 
| 487 | 
            +
                        "lora_A": lora1 if lora1 != "None" else None,
         | 
| 488 | 
            +
                        "lora_scale_A": lora_scale1,
         | 
| 489 | 
            +
                        "lora_B": lora2 if lora2 != "None" else None,
         | 
| 490 | 
            +
                        "lora_scale_B": lora_scale2,
         | 
| 491 | 
            +
                        "lora_C": lora3 if lora3 != "None" else None,
         | 
| 492 | 
            +
                        "lora_scale_C": lora_scale3,
         | 
| 493 | 
            +
                        "lora_D": lora4 if lora4 != "None" else None,
         | 
| 494 | 
            +
                        "lora_scale_D": lora_scale4,
         | 
| 495 | 
            +
                        "lora_E": lora5 if lora5 != "None" else None,
         | 
| 496 | 
            +
                        "lora_scale_E": lora_scale5,
         | 
| 497 | 
            +
                        "lora_F": lora6 if lora6 != "None" else None,
         | 
| 498 | 
            +
                        "lora_scale_F": lora_scale6,
         | 
| 499 | 
            +
                        "lora_G": lora7 if lora7 != "None" else None,
         | 
| 500 | 
            +
                        "lora_scale_G": lora_scale7,
         | 
| 501 | 
            +
                        "textual_inversion": embed_list if textual_inversion else [],
         | 
| 502 | 
            +
                        "syntax_weights": syntax_weights,  # "Classic"
         | 
| 503 | 
            +
                        "sampler": sampler,
         | 
| 504 | 
            +
                        "schedule_type": schedule_type,
         | 
| 505 | 
            +
                        "schedule_prediction_type": schedule_prediction_type,
         | 
| 506 | 
            +
                        "xformers_memory_efficient_attention": xformers_memory_efficient_attention,
         | 
| 507 | 
            +
                        "gui_active": True,
         | 
| 508 | 
            +
                        "loop_generation": loop_generation,
         | 
| 509 | 
            +
                        "controlnet_conditioning_scale": float(controlnet_output_scaling_in_unet),
         | 
| 510 | 
            +
                        "control_guidance_start": float(controlnet_start_threshold),
         | 
| 511 | 
            +
                        "control_guidance_end": float(controlnet_stop_threshold),
         | 
| 512 | 
            +
                        "generator_in_cpu": generator_in_cpu,
         | 
| 513 | 
            +
                        "FreeU": freeu,
         | 
| 514 | 
            +
                        "adetailer_A": adetailer_active_a,
         | 
| 515 | 
            +
                        "adetailer_A_params": adetailer_params_A,
         | 
| 516 | 
            +
                        "adetailer_B": adetailer_active_b,
         | 
| 517 | 
            +
                        "adetailer_B_params": adetailer_params_B,
         | 
| 518 | 
            +
                        "leave_progress_bar": leave_progress_bar,
         | 
| 519 | 
            +
                        "disable_progress_bar": disable_progress_bar,
         | 
| 520 | 
            +
                        "image_previews": image_previews,
         | 
| 521 | 
            +
                        "display_images": display_images,
         | 
| 522 | 
            +
                        "save_generated_images": save_generated_images,
         | 
| 523 | 
            +
                        "filename_pattern": filename_pattern,
         | 
| 524 | 
            +
                        "image_storage_location": image_storage_location,
         | 
| 525 | 
            +
                        "retain_compel_previous_load": retain_compel_previous_load,
         | 
| 526 | 
            +
                        "retain_detailfix_model_previous_load": retain_detailfix_model_previous_load,
         | 
| 527 | 
            +
                        "retain_hires_model_previous_load": retain_hires_model_previous_load,
         | 
| 528 | 
            +
                        "t2i_adapter_preprocessor": t2i_adapter_preprocessor,
         | 
| 529 | 
            +
                        "t2i_adapter_conditioning_scale": float(t2i_adapter_conditioning_scale),
         | 
| 530 | 
            +
                        "t2i_adapter_conditioning_factor": float(t2i_adapter_conditioning_factor),
         | 
| 531 | 
            +
                        "upscaler_model_path": upscaler_model,
         | 
| 532 | 
            +
                        "upscaler_increases_size": upscaler_increases_size,
         | 
| 533 | 
            +
                        "upscaler_tile_size": upscaler_tile_size,
         | 
| 534 | 
            +
                        "upscaler_tile_overlap": upscaler_tile_overlap,
         | 
| 535 | 
            +
                        "hires_steps": hires_steps,
         | 
| 536 | 
            +
                        "hires_denoising_strength": hires_denoising_strength,
         | 
| 537 | 
            +
                        "hires_prompt": hires_prompt,
         | 
| 538 | 
            +
                        "hires_negative_prompt": hires_negative_prompt,
         | 
| 539 | 
            +
                        "hires_sampler": hires_sampler,
         | 
| 540 | 
            +
                        "hires_before_adetailer": hires_before_adetailer,
         | 
| 541 | 
            +
                        "hires_after_adetailer": hires_after_adetailer,
         | 
| 542 | 
            +
                        "hires_schedule_type": hires_schedule_type,
         | 
| 543 | 
            +
                        "hires_guidance_scale": hires_guidance_scale,
         | 
| 544 | 
            +
                        "ip_adapter_image": params_ip_img,
         | 
| 545 | 
            +
                        "ip_adapter_mask": params_ip_msk,
         | 
| 546 | 
            +
                        "ip_adapter_model": params_ip_model,
         | 
| 547 | 
            +
                        "ip_adapter_mode": params_ip_mode,
         | 
| 548 | 
            +
                        "ip_adapter_scale": params_ip_scale,
         | 
| 549 | 
            +
                        "face_restoration_model": face_restoration_model,
         | 
| 550 | 
            +
                        "face_restoration_visibility": face_restoration_visibility,
         | 
| 551 | 
            +
                        "face_restoration_weight": face_restoration_weight,
         | 
| 552 | 
            +
                    }
         | 
| 553 | 
            +
             | 
| 554 | 
            +
                    # kwargs for diffusers pipeline
         | 
| 555 | 
            +
                    if guidance_rescale:
         | 
| 556 | 
            +
                        pipe_params["guidance_rescale"] = guidance_rescale
         | 
| 557 | 
            +
             | 
| 558 | 
            +
                    self.model.device = torch.device("cuda:0")
         | 
| 559 | 
            +
                    if hasattr(self.model.pipe, "transformer") and loras_list != ["None"] * self.model.num_loras:
         | 
| 560 | 
            +
                        self.model.pipe.transformer.to(self.model.device)
         | 
| 561 | 
            +
                        print("transformer to cuda")
         | 
| 562 | 
            +
             | 
| 563 | 
            +
                    actual_progress = 0
         | 
| 564 | 
            +
                    info_images = gr.update()
         | 
| 565 | 
            +
                    for img, [seed, image_path, metadata] in self.model(**pipe_params):
         | 
| 566 | 
            +
                        info_state = progress_step_bar(actual_progress, steps)
         | 
| 567 | 
            +
                        actual_progress += concurrency
         | 
| 568 | 
            +
                        if image_path:
         | 
| 569 | 
            +
                            info_images = f"Seeds: {str(seed)}"
         | 
| 570 | 
            +
                            if vae_msg:
         | 
| 571 | 
            +
                                info_images = info_images + "<br>" + vae_msg
         | 
| 572 | 
            +
             | 
| 573 | 
            +
                            if "Cannot copy out of meta tensor; no data!" in self.model.last_lora_error:
         | 
| 574 | 
            +
                                msg_ram = "Unable to process the LoRAs due to high RAM usage; please try again later."
         | 
| 575 | 
            +
                                print(msg_ram)
         | 
| 576 | 
            +
                                msg_lora += f"<br>{msg_ram}"
         | 
| 577 | 
            +
             | 
| 578 | 
            +
                            for status, lora in zip(self.model.lora_status, self.model.lora_memory):
         | 
| 579 | 
            +
                                if status:
         | 
| 580 | 
            +
                                    msg_lora += f"<br>Loaded: {lora}"
         | 
| 581 | 
            +
                                elif status is not None:
         | 
| 582 | 
            +
                                    msg_lora += f"<br>Error with: {lora}"
         | 
| 583 | 
            +
             | 
| 584 | 
            +
                            if msg_lora:
         | 
| 585 | 
            +
                                info_images += msg_lora
         | 
| 586 | 
            +
             | 
| 587 | 
            +
                            info_images = info_images + "<br>" + "GENERATION DATA:<br>" + escape_html(metadata[-1]) + "<br>-------<br>"
         | 
| 588 | 
            +
             | 
| 589 | 
            +
                            download_links = "<br>".join(
         | 
| 590 | 
            +
                                [
         | 
| 591 | 
            +
                                    f'<a href="{path.replace("/images/", "/file=/home/user/app/images/")}" download="{os.path.basename(path)}">Download Image {i + 1}</a>'
         | 
| 592 | 
            +
                                    for i, path in enumerate(image_path)
         | 
| 593 | 
            +
                                ]
         | 
| 594 | 
            +
                            )
         | 
| 595 | 
            +
                            if save_generated_images:
         | 
| 596 | 
            +
                                info_images += f"<br>{download_links}"
         | 
| 597 | 
            +
             | 
| 598 | 
            +
                            info_state = "COMPLETE"
         | 
| 599 | 
            +
             | 
| 600 | 
            +
                        yield info_state, img, info_images
         | 
| 601 | 
            +
             | 
| 602 | 
            +
             | 
| 603 | 
            +
            def dynamic_gpu_duration(func, duration, *args):
         | 
| 604 | 
            +
             | 
| 605 | 
            +
                # @torch.inference_mode()
         | 
| 606 | 
            +
                @spaces.GPU(duration=duration)
         | 
| 607 | 
            +
                def wrapped_func():
         | 
| 608 | 
            +
                    yield from func(*args)
         | 
| 609 | 
            +
             | 
| 610 | 
            +
                return wrapped_func()
         | 
| 611 | 
            +
             | 
| 612 | 
            +
             | 
| 613 | 
            +
            @spaces.GPU
         | 
| 614 | 
            +
            def dummy_gpu():
         | 
| 615 | 
            +
                return None
         | 
| 616 | 
            +
             | 
| 617 | 
            +
             | 
| 618 | 
            +
            def sd_gen_generate_pipeline(*args):
         | 
| 619 | 
            +
                gpu_duration_arg = int(args[-1]) if args[-1] else 59
         | 
| 620 | 
            +
                verbose_arg = int(args[-2])
         | 
| 621 | 
            +
                load_lora_cpu = args[-3]
         | 
| 622 | 
            +
                generation_args = args[:-3]
         | 
| 623 | 
            +
                lora_list = [
         | 
| 624 | 
            +
                    None if item == "None" else item
         | 
| 625 | 
            +
                    for item in [args[7], args[9], args[11], args[13], args[15], args[17], args[19]]
         | 
| 626 | 
            +
                ]
         | 
| 627 | 
            +
                lora_status = [None] * sd_gen.model.num_loras
         | 
| 628 | 
            +
             | 
| 629 | 
            +
                msg_load_lora = "Updating LoRAs in GPU..."
         | 
| 630 | 
            +
                if load_lora_cpu:
         | 
| 631 | 
            +
                    msg_load_lora = "Updating LoRAs in CPU..."
         | 
| 632 | 
            +
             | 
| 633 | 
            +
                if lora_list != sd_gen.model.lora_memory and lora_list != [None] * sd_gen.model.num_loras:
         | 
| 634 | 
            +
                    yield msg_load_lora, gr.update(), gr.update()
         | 
| 635 | 
            +
             | 
| 636 | 
            +
                # Load lora in CPU
         | 
| 637 | 
            +
                if load_lora_cpu:
         | 
| 638 | 
            +
                    lora_status = sd_gen.model.load_lora_on_the_fly(
         | 
| 639 | 
            +
                        lora_A=lora_list[0], lora_scale_A=args[8],
         | 
| 640 | 
            +
                        lora_B=lora_list[1], lora_scale_B=args[10],
         | 
| 641 | 
            +
                        lora_C=lora_list[2], lora_scale_C=args[12],
         | 
| 642 | 
            +
                        lora_D=lora_list[3], lora_scale_D=args[14],
         | 
| 643 | 
            +
                        lora_E=lora_list[4], lora_scale_E=args[16],
         | 
| 644 | 
            +
                        lora_F=lora_list[5], lora_scale_F=args[18],
         | 
| 645 | 
            +
                        lora_G=lora_list[6], lora_scale_G=args[20],
         | 
| 646 | 
            +
                    )
         | 
| 647 | 
            +
                    print(lora_status)
         | 
| 648 | 
            +
             | 
| 649 | 
            +
                sampler_name = args[21]
         | 
| 650 | 
            +
                schedule_type_name = args[22]
         | 
| 651 | 
            +
                _, _, msg_sampler = check_scheduler_compatibility(
         | 
| 652 | 
            +
                    sd_gen.model.class_name, sampler_name, schedule_type_name
         | 
| 653 | 
            +
                )
         | 
| 654 | 
            +
                if msg_sampler:
         | 
| 655 | 
            +
                    gr.Warning(msg_sampler)
         | 
| 656 | 
            +
             | 
| 657 | 
            +
                if verbose_arg:
         | 
| 658 | 
            +
                    for status, lora in zip(lora_status, lora_list):
         | 
| 659 | 
            +
                        if status:
         | 
| 660 | 
            +
                            gr.Info(f"LoRA loaded in CPU: {lora}")
         | 
| 661 | 
            +
                        elif status is not None:
         | 
| 662 | 
            +
                            gr.Warning(f"Failed to load LoRA: {lora}")
         | 
| 663 | 
            +
             | 
| 664 | 
            +
                    if lora_status == [None] * sd_gen.model.num_loras and sd_gen.model.lora_memory != [None] * sd_gen.model.num_loras and load_lora_cpu:
         | 
| 665 | 
            +
                        lora_cache_msg = ", ".join(
         | 
| 666 | 
            +
                            str(x) for x in sd_gen.model.lora_memory if x is not None
         | 
| 667 | 
            +
                        )
         | 
| 668 | 
            +
                        gr.Info(f"LoRAs in cache: {lora_cache_msg}")
         | 
| 669 | 
            +
             | 
| 670 | 
            +
                msg_request = f"Requesting {gpu_duration_arg}s. of GPU time.\nModel: {sd_gen.model.base_model_id}"
         | 
| 671 | 
            +
                if verbose_arg:
         | 
| 672 | 
            +
                    gr.Info(msg_request)
         | 
| 673 | 
            +
                    print(msg_request)
         | 
| 674 | 
            +
                yield msg_request.replace("\n", "<br>"), gr.update(), gr.update()
         | 
| 675 | 
            +
             | 
| 676 | 
            +
                start_time = time.time()
         | 
| 677 | 
            +
             | 
| 678 | 
            +
                # yield from sd_gen.generate_pipeline(*generation_args)
         | 
| 679 | 
            +
                yield from dynamic_gpu_duration(
         | 
| 680 | 
            +
                    sd_gen.generate_pipeline,
         | 
| 681 | 
            +
                    gpu_duration_arg,
         | 
| 682 | 
            +
                    *generation_args,
         | 
| 683 | 
            +
                )
         | 
| 684 | 
            +
             | 
| 685 | 
            +
                end_time = time.time()
         | 
| 686 | 
            +
                execution_time = end_time - start_time
         | 
| 687 | 
            +
                msg_task_complete = (
         | 
| 688 | 
            +
                    f"GPU task complete in: {int(round(execution_time, 0) + 1)} seconds"
         | 
| 689 | 
            +
                )
         | 
| 690 | 
            +
             | 
| 691 | 
            +
                if verbose_arg:
         | 
| 692 | 
            +
                    gr.Info(msg_task_complete)
         | 
| 693 | 
            +
                    print(msg_task_complete)
         | 
| 694 | 
            +
             | 
| 695 | 
            +
                yield msg_task_complete, gr.update(), gr.update()
         | 
| 696 | 
            +
             | 
| 697 | 
            +
             | 
| 698 | 
            +
            @spaces.GPU(duration=15)
         | 
| 699 | 
            +
            def process_upscale(image, upscaler_name, upscaler_size):
         | 
| 700 | 
            +
                if image is None: return None
         | 
| 701 | 
            +
             | 
| 702 | 
            +
                from stablepy.diffusers_vanilla.utils import save_pil_image_with_metadata
         | 
| 703 | 
            +
                from stablepy import load_upscaler_model
         | 
| 704 | 
            +
             | 
| 705 | 
            +
                image = image.convert("RGB")
         | 
| 706 | 
            +
                exif_image = extract_exif_data(image)
         | 
| 707 | 
            +
             | 
| 708 | 
            +
                name_upscaler = UPSCALER_DICT_GUI[upscaler_name]
         | 
| 709 | 
            +
             | 
| 710 | 
            +
                if "https://" in str(name_upscaler):
         | 
| 711 | 
            +
             | 
| 712 | 
            +
                    if not os.path.exists(f"./{DIRECTORY_UPSCALERS}/{name_upscaler.split('/')[-1]}"):
         | 
| 713 | 
            +
                        download_things(DIRECTORY_UPSCALERS, name_upscaler, HF_TOKEN)
         | 
| 714 | 
            +
             | 
| 715 | 
            +
                    name_upscaler = f"./{DIRECTORY_UPSCALERS}/{name_upscaler.split('/')[-1]}"
         | 
| 716 | 
            +
             | 
| 717 | 
            +
                scaler_beta = load_upscaler_model(model=name_upscaler, tile=0, tile_overlap=8, device="cuda", half=True)
         | 
| 718 | 
            +
                image_up = scaler_beta.upscale(image, upscaler_size, True)
         | 
| 719 | 
            +
             | 
| 720 | 
            +
                image_path = save_pil_image_with_metadata(image_up, f'{os.getcwd()}/up_images', exif_image)
         | 
| 721 | 
            +
             | 
| 722 | 
            +
                return image_path
         | 
| 723 | 
            +
             | 
| 724 | 
            +
             | 
| 725 | 
            +
            # https://huggingface.co/spaces/BestWishYsh/ConsisID-preview-Space/discussions/1#674969a022b99c122af5d407
         | 
| 726 | 
            +
            dynamic_gpu_duration.zerogpu = True
         | 
| 727 | 
            +
            sd_gen_generate_pipeline.zerogpu = True
         | 
| 728 | 
            +
            sd_gen = GuiSD()
         | 
| 729 | 
            +
             | 
| 730 | 
            +
            with gr.Blocks(theme="NoCrypt/miku", css=CSS) as app:
         | 
| 731 | 
            +
                gr.Markdown("# 🧩 DiffuseCraft")
         | 
| 732 | 
            +
                gr.Markdown(SUBTITLE_GUI)
         | 
| 733 | 
            +
                with gr.Tab("Generation"):
         | 
| 734 | 
            +
                    with gr.Row():
         | 
| 735 | 
            +
             | 
| 736 | 
            +
                        with gr.Column(scale=2):
         | 
| 737 | 
            +
             | 
| 738 | 
            +
                            def update_task_options(model_name, task_name):
         | 
| 739 | 
            +
                                new_choices = MODEL_TYPE_TASK[get_model_type(model_name)]
         | 
| 740 | 
            +
             | 
| 741 | 
            +
                                if task_name not in new_choices:
         | 
| 742 | 
            +
                                    task_name = "txt2img"
         | 
| 743 | 
            +
             | 
| 744 | 
            +
                                return gr.update(value=task_name, choices=new_choices)
         | 
| 745 | 
            +
             | 
| 746 | 
            +
                            task_gui = gr.Dropdown(label="Task", choices=SDXL_TASK, value=TASK_MODEL_LIST[0])
         | 
| 747 | 
            +
                            model_name_gui = gr.Dropdown(label="Model", choices=model_list, value=model_list[0], allow_custom_value=True)
         | 
| 748 | 
            +
                            prompt_gui = gr.Textbox(lines=5, placeholder="Enter prompt", label="Prompt")
         | 
| 749 | 
            +
                            neg_prompt_gui = gr.Textbox(lines=3, placeholder="Enter Neg prompt", label="Negative prompt", value="lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, worst quality, low quality, very displeasing, (bad)")
         | 
| 750 | 
            +
                            with gr.Row(equal_height=False):
         | 
| 751 | 
            +
                                set_params_gui = gr.Button(value="↙️", variant="secondary", size="sm")
         | 
| 752 | 
            +
                                clear_prompt_gui = gr.Button(value="🗑️", variant="secondary", size="sm")
         | 
| 753 | 
            +
                                set_random_seed = gr.Button(value="🎲", variant="secondary", size="sm")
         | 
| 754 | 
            +
                            generate_button = gr.Button(value="GENERATE IMAGE", variant="primary")
         | 
| 755 | 
            +
             | 
| 756 | 
            +
                            model_name_gui.change(
         | 
| 757 | 
            +
                                update_task_options,
         | 
| 758 | 
            +
                                [model_name_gui, task_gui],
         | 
| 759 | 
            +
                                [task_gui],
         | 
| 760 | 
            +
                            )
         | 
| 761 | 
            +
             | 
| 762 | 
            +
                            load_model_gui = gr.HTML(elem_id="load_model", elem_classes="contain")
         | 
| 763 | 
            +
             | 
| 764 | 
            +
                            result_images = gr.Gallery(
         | 
| 765 | 
            +
                                label="Generated images",
         | 
| 766 | 
            +
                                show_label=False,
         | 
| 767 | 
            +
                                elem_id="gallery",
         | 
| 768 | 
            +
                                columns=[2],
         | 
| 769 | 
            +
                                rows=[2],
         | 
| 770 | 
            +
                                object_fit="contain",
         | 
| 771 | 
            +
                                # height="auto",
         | 
| 772 | 
            +
                                interactive=False,
         | 
| 773 | 
            +
                                preview=False,
         | 
| 774 | 
            +
                                selected_index=50,
         | 
| 775 | 
            +
                            )
         | 
| 776 | 
            +
             | 
| 777 | 
            +
                            actual_task_info = gr.HTML()
         | 
| 778 | 
            +
             | 
| 779 | 
            +
                            with gr.Row(equal_height=False, variant="default"):
         | 
| 780 | 
            +
                                gpu_duration_gui = gr.Number(minimum=5, maximum=240, value=59, show_label=False, container=False, info="GPU time duration (seconds)")
         | 
| 781 | 
            +
                                with gr.Column():
         | 
| 782 | 
            +
                                    verbose_info_gui = gr.Checkbox(value=False, container=False, label="Status info")
         | 
| 783 | 
            +
                                    load_lora_cpu_gui = gr.Checkbox(value=False, container=False, label="Load LoRAs on CPU")
         | 
| 784 | 
            +
             | 
| 785 | 
            +
                        with gr.Column(scale=1):
         | 
| 786 | 
            +
                            steps_gui = gr.Slider(minimum=1, maximum=100, step=1, value=28, label="Steps")
         | 
| 787 | 
            +
                            cfg_gui = gr.Slider(minimum=0, maximum=30, step=0.5, value=7., label="CFG")
         | 
| 788 | 
            +
                            sampler_gui = gr.Dropdown(label="Sampler", choices=scheduler_names, value="Euler")
         | 
| 789 | 
            +
                            schedule_type_gui = gr.Dropdown(label="Schedule type", choices=SCHEDULE_TYPE_OPTIONS, value=SCHEDULE_TYPE_OPTIONS[0])
         | 
| 790 | 
            +
                            img_width_gui = gr.Slider(minimum=64, maximum=4096, step=8, value=1024, label="Img Width")
         | 
| 791 | 
            +
                            img_height_gui = gr.Slider(minimum=64, maximum=4096, step=8, value=1024, label="Img Height")
         | 
| 792 | 
            +
                            seed_gui = gr.Number(minimum=-1, maximum=9999999999, value=-1, label="Seed")
         | 
| 793 | 
            +
                            pag_scale_gui = gr.Slider(minimum=0.0, maximum=10.0, step=0.1, value=0.0, label="PAG Scale")
         | 
| 794 | 
            +
                            with gr.Row():
         | 
| 795 | 
            +
                                clip_skip_gui = gr.Checkbox(value=True, label="Layer 2 Clip Skip")
         | 
| 796 | 
            +
                                free_u_gui = gr.Checkbox(value=False, label="FreeU")
         | 
| 797 | 
            +
             | 
| 798 | 
            +
                            with gr.Row(equal_height=False):
         | 
| 799 | 
            +
             | 
| 800 | 
            +
                                def run_set_params_gui(base_prompt, name_model):
         | 
| 801 | 
            +
                                    valid_receptors = {  # default values
         | 
| 802 | 
            +
                                        "prompt": gr.update(value=base_prompt),
         | 
| 803 | 
            +
                                        "neg_prompt": gr.update(value=""),
         | 
| 804 | 
            +
                                        "Steps": gr.update(value=30),
         | 
| 805 | 
            +
                                        "width": gr.update(value=1024),
         | 
| 806 | 
            +
                                        "height": gr.update(value=1024),
         | 
| 807 | 
            +
                                        "Seed": gr.update(value=-1),
         | 
| 808 | 
            +
                                        "Sampler": gr.update(value="Euler"),
         | 
| 809 | 
            +
                                        "CFG scale": gr.update(value=7.),  # cfg
         | 
| 810 | 
            +
                                        "Clip skip": gr.update(value=True),
         | 
| 811 | 
            +
                                        "Model": gr.update(value=name_model),
         | 
| 812 | 
            +
                                        "Schedule type": gr.update(value="Automatic"),
         | 
| 813 | 
            +
                                        "PAG": gr.update(value=.0),
         | 
| 814 | 
            +
                                        "FreeU": gr.update(value=False),
         | 
| 815 | 
            +
                                    }
         | 
| 816 | 
            +
                                    valid_keys = list(valid_receptors.keys())
         | 
| 817 | 
            +
             | 
| 818 | 
            +
                                    parameters = extract_parameters(base_prompt)
         | 
| 819 | 
            +
                                    # print(parameters)
         | 
| 820 | 
            +
             | 
| 821 | 
            +
                                    if "Sampler" in parameters:
         | 
| 822 | 
            +
                                        value_sampler = parameters["Sampler"]
         | 
| 823 | 
            +
                                        for s_type in SCHEDULE_TYPE_OPTIONS:
         | 
| 824 | 
            +
                                            if s_type in value_sampler:
         | 
| 825 | 
            +
                                                value_sampler = value_sampler.replace(s_type, "").strip()
         | 
| 826 | 
            +
                                                parameters["Sampler"] = value_sampler
         | 
| 827 | 
            +
                                                parameters["Schedule type"] = s_type
         | 
| 828 | 
            +
             | 
| 829 | 
            +
                                    for key, val in parameters.items():
         | 
| 830 | 
            +
                                        # print(val)
         | 
| 831 | 
            +
                                        if key in valid_keys:
         | 
| 832 | 
            +
                                            try:
         | 
| 833 | 
            +
                                                if key == "Sampler":
         | 
| 834 | 
            +
                                                    if val not in scheduler_names:
         | 
| 835 | 
            +
                                                        continue
         | 
| 836 | 
            +
                                                if key == "Schedule type":
         | 
| 837 | 
            +
                                                    if val not in SCHEDULE_TYPE_OPTIONS:
         | 
| 838 | 
            +
                                                        val = "Automatic"
         | 
| 839 | 
            +
                                                elif key == "Clip skip":
         | 
| 840 | 
            +
                                                    if "," in str(val):
         | 
| 841 | 
            +
                                                        val = val.replace(",", "")
         | 
| 842 | 
            +
                                                    if int(val) >= 2:
         | 
| 843 | 
            +
                                                        val = True
         | 
| 844 | 
            +
                                                if key == "prompt":
         | 
| 845 | 
            +
                                                    if ">" in val and "<" in val:
         | 
| 846 | 
            +
                                                        val = re.sub(r'<[^>]+>', '', val)
         | 
| 847 | 
            +
                                                        print("Removed LoRA written in the prompt")
         | 
| 848 | 
            +
                                                if key in ["prompt", "neg_prompt"]:
         | 
| 849 | 
            +
                                                    val = re.sub(r'\s+', ' ', re.sub(r',+', ',', val)).strip()
         | 
| 850 | 
            +
                                                if key in ["Steps", "width", "height", "Seed"]:
         | 
| 851 | 
            +
                                                    val = int(val)
         | 
| 852 | 
            +
                                                if key == "FreeU":
         | 
| 853 | 
            +
                                                    val = True
         | 
| 854 | 
            +
                                                if key in ["CFG scale", "PAG"]:
         | 
| 855 | 
            +
                                                    val = float(val)
         | 
| 856 | 
            +
                                                if key == "Model":
         | 
| 857 | 
            +
                                                    filtered_models = [m for m in model_list if val in m]
         | 
| 858 | 
            +
                                                    if filtered_models:
         | 
| 859 | 
            +
                                                        val = filtered_models[0]
         | 
| 860 | 
            +
                                                    else:
         | 
| 861 | 
            +
                                                        val = name_model
         | 
| 862 | 
            +
                                                if key == "Seed":
         | 
| 863 | 
            +
                                                    continue
         | 
| 864 | 
            +
                                                valid_receptors[key] = gr.update(value=val)
         | 
| 865 | 
            +
                                                # print(val, type(val))
         | 
| 866 | 
            +
                                                # print(valid_receptors)
         | 
| 867 | 
            +
                                            except Exception as e:
         | 
| 868 | 
            +
                                                print(str(e))
         | 
| 869 | 
            +
                                    return [value for value in valid_receptors.values()]
         | 
| 870 | 
            +
             | 
| 871 | 
            +
                                set_params_gui.click(
         | 
| 872 | 
            +
                                    run_set_params_gui, [prompt_gui, model_name_gui], [
         | 
| 873 | 
            +
                                        prompt_gui,
         | 
| 874 | 
            +
                                        neg_prompt_gui,
         | 
| 875 | 
            +
                                        steps_gui,
         | 
| 876 | 
            +
                                        img_width_gui,
         | 
| 877 | 
            +
                                        img_height_gui,
         | 
| 878 | 
            +
                                        seed_gui,
         | 
| 879 | 
            +
                                        sampler_gui,
         | 
| 880 | 
            +
                                        cfg_gui,
         | 
| 881 | 
            +
                                        clip_skip_gui,
         | 
| 882 | 
            +
                                        model_name_gui,
         | 
| 883 | 
            +
                                        schedule_type_gui,
         | 
| 884 | 
            +
                                        pag_scale_gui,
         | 
| 885 | 
            +
                                        free_u_gui,
         | 
| 886 | 
            +
                                    ],
         | 
| 887 | 
            +
                                )
         | 
| 888 | 
            +
             | 
| 889 | 
            +
                                def run_clear_prompt_gui():
         | 
| 890 | 
            +
                                    return gr.update(value=""), gr.update(value="")
         | 
| 891 | 
            +
                                clear_prompt_gui.click(
         | 
| 892 | 
            +
                                    run_clear_prompt_gui, [], [prompt_gui, neg_prompt_gui]
         | 
| 893 | 
            +
                                )
         | 
| 894 | 
            +
             | 
| 895 | 
            +
                                def run_set_random_seed():
         | 
| 896 | 
            +
                                    return -1
         | 
| 897 | 
            +
                                set_random_seed.click(
         | 
| 898 | 
            +
                                    run_set_random_seed, [], seed_gui
         | 
| 899 | 
            +
                                )
         | 
| 900 | 
            +
             | 
| 901 | 
            +
                            num_images_gui = gr.Slider(minimum=1, maximum=5, step=1, value=1, label="Images")
         | 
| 902 | 
            +
                            prompt_syntax_gui = gr.Dropdown(label="Prompt Syntax", choices=PROMPT_W_OPTIONS, value=PROMPT_W_OPTIONS[1][1])
         | 
| 903 | 
            +
                            vae_model_gui = gr.Dropdown(label="VAE Model", choices=vae_model_list, value=vae_model_list[0])
         | 
| 904 | 
            +
             | 
| 905 | 
            +
                            with gr.Accordion("Hires fix", open=False, visible=True):
         | 
| 906 | 
            +
             | 
| 907 | 
            +
                                upscaler_model_path_gui = gr.Dropdown(label="Upscaler", choices=UPSCALER_KEYS, value=UPSCALER_KEYS[0])
         | 
| 908 | 
            +
                                upscaler_increases_size_gui = gr.Slider(minimum=1.1, maximum=4., step=0.1, value=1.2, label="Upscale by")
         | 
| 909 | 
            +
                                upscaler_tile_size_gui = gr.Slider(minimum=0, maximum=512, step=16, value=0, label="Upscaler Tile Size", info="0 = no tiling")
         | 
| 910 | 
            +
                                upscaler_tile_overlap_gui = gr.Slider(minimum=0, maximum=48, step=1, value=8, label="Upscaler Tile Overlap")
         | 
| 911 | 
            +
                                hires_steps_gui = gr.Slider(minimum=0, value=30, maximum=100, step=1, label="Hires Steps")
         | 
| 912 | 
            +
                                hires_denoising_strength_gui = gr.Slider(minimum=0.1, maximum=1.0, step=0.01, value=0.55, label="Hires Denoising Strength")
         | 
| 913 | 
            +
                                hires_sampler_gui = gr.Dropdown(label="Hires Sampler", choices=POST_PROCESSING_SAMPLER, value=POST_PROCESSING_SAMPLER[0])
         | 
| 914 | 
            +
                                hires_schedule_list = ["Use same schedule type"] + SCHEDULE_TYPE_OPTIONS
         | 
| 915 | 
            +
                                hires_schedule_type_gui = gr.Dropdown(label="Hires Schedule type", choices=hires_schedule_list, value=hires_schedule_list[0])
         | 
| 916 | 
            +
                                hires_guidance_scale_gui = gr.Slider(minimum=-1., maximum=30., step=0.5, value=-1., label="Hires CFG", info="If the value is -1, the main CFG will be used")
         | 
| 917 | 
            +
                                hires_prompt_gui = gr.Textbox(label="Hires Prompt", placeholder="Main prompt will be use", lines=3)
         | 
| 918 | 
            +
                                hires_negative_prompt_gui = gr.Textbox(label="Hires Negative Prompt", placeholder="Main negative prompt will be use", lines=3)
         | 
| 919 | 
            +
             | 
| 920 | 
            +
                            with gr.Accordion("LoRA", open=False, visible=True):
         | 
| 921 | 
            +
             | 
| 922 | 
            +
                                def lora_dropdown(label, visible=True):
         | 
| 923 | 
            +
                                    return gr.Dropdown(label=label, choices=lora_model_list, value="None", allow_custom_value=True, visible=visible)
         | 
| 924 | 
            +
             | 
| 925 | 
            +
                                def lora_scale_slider(label, visible=True):
         | 
| 926 | 
            +
                                    return gr.Slider(minimum=-2, maximum=2, step=0.01, value=0.33, label=label, visible=visible)
         | 
| 927 | 
            +
             | 
| 928 | 
            +
                                lora1_gui = lora_dropdown("Lora1")
         | 
| 929 | 
            +
                                lora_scale_1_gui = lora_scale_slider("Lora Scale 1")
         | 
| 930 | 
            +
                                lora2_gui = lora_dropdown("Lora2")
         | 
| 931 | 
            +
                                lora_scale_2_gui = lora_scale_slider("Lora Scale 2")
         | 
| 932 | 
            +
                                lora3_gui = lora_dropdown("Lora3")
         | 
| 933 | 
            +
                                lora_scale_3_gui = lora_scale_slider("Lora Scale 3")
         | 
| 934 | 
            +
                                lora4_gui = lora_dropdown("Lora4")
         | 
| 935 | 
            +
                                lora_scale_4_gui = lora_scale_slider("Lora Scale 4")
         | 
| 936 | 
            +
                                lora5_gui = lora_dropdown("Lora5")
         | 
| 937 | 
            +
                                lora_scale_5_gui = lora_scale_slider("Lora Scale 5")
         | 
| 938 | 
            +
                                lora6_gui = lora_dropdown("Lora6", visible=False)
         | 
| 939 | 
            +
                                lora_scale_6_gui = lora_scale_slider("Lora Scale 6", visible=False)
         | 
| 940 | 
            +
                                lora7_gui = lora_dropdown("Lora7", visible=False)
         | 
| 941 | 
            +
                                lora_scale_7_gui = lora_scale_slider("Lora Scale 7", visible=False)
         | 
| 942 | 
            +
             | 
| 943 | 
            +
                                with gr.Accordion("From URL", open=False, visible=True):
         | 
| 944 | 
            +
                                    text_lora = gr.Textbox(
         | 
| 945 | 
            +
                                        label="LoRA's download URL",
         | 
| 946 | 
            +
                                        placeholder="https://civitai.com/api/download/models/28907",
         | 
| 947 | 
            +
                                        lines=1,
         | 
| 948 | 
            +
                                        info="It has to be .safetensors files, and you can also download them from Hugging Face.",
         | 
| 949 | 
            +
                                    )
         | 
| 950 | 
            +
                                    romanize_text = gr.Checkbox(value=False, label="Transliterate name", visible=False)
         | 
| 951 | 
            +
                                    button_lora = gr.Button("Get and Refresh the LoRA Lists")
         | 
| 952 | 
            +
                                    new_lora_status = gr.HTML()
         | 
| 953 | 
            +
                                    button_lora.click(
         | 
| 954 | 
            +
                                        get_my_lora,
         | 
| 955 | 
            +
                                        [text_lora, romanize_text],
         | 
| 956 | 
            +
                                        [lora1_gui, lora2_gui, lora3_gui, lora4_gui, lora5_gui, lora6_gui, lora7_gui, new_lora_status]
         | 
| 957 | 
            +
                                    )
         | 
| 958 | 
            +
             | 
| 959 | 
            +
                            with gr.Accordion("Face restoration", open=False, visible=True):
         | 
| 960 | 
            +
             | 
| 961 | 
            +
                                face_rest_options = [None] + FACE_RESTORATION_MODELS
         | 
| 962 | 
            +
             | 
| 963 | 
            +
                                face_restoration_model_gui = gr.Dropdown(label="Face restoration model", choices=face_rest_options, value=face_rest_options[0])
         | 
| 964 | 
            +
                                face_restoration_visibility_gui = gr.Slider(minimum=0., maximum=1., step=0.001, value=1., label="Visibility")
         | 
| 965 | 
            +
                                face_restoration_weight_gui = gr.Slider(minimum=0., maximum=1., step=0.001, value=.5, label="Weight", info="(0 = maximum effect, 1 = minimum effect)")
         | 
| 966 | 
            +
             | 
| 967 | 
            +
                            with gr.Accordion("IP-Adapter", open=False, visible=True):
         | 
| 968 | 
            +
             | 
| 969 | 
            +
                                with gr.Accordion("IP-Adapter 1", open=False, visible=True):
         | 
| 970 | 
            +
                                    image_ip1 = gr.Image(label="IP Image", type="filepath")
         | 
| 971 | 
            +
                                    mask_ip1 = gr.Image(label="IP Mask", type="filepath")
         | 
| 972 | 
            +
                                    model_ip1 = gr.Dropdown(value="plus_face", label="Model", choices=IP_MODELS)
         | 
| 973 | 
            +
                                    mode_ip1 = gr.Dropdown(value="original", label="Mode", choices=MODE_IP_OPTIONS)
         | 
| 974 | 
            +
                                    scale_ip1 = gr.Slider(minimum=0., maximum=2., step=0.01, value=0.7, label="Scale")
         | 
| 975 | 
            +
                                with gr.Accordion("IP-Adapter 2", open=False, visible=True):
         | 
| 976 | 
            +
                                    image_ip2 = gr.Image(label="IP Image", type="filepath")
         | 
| 977 | 
            +
                                    mask_ip2 = gr.Image(label="IP Mask (optional)", type="filepath")
         | 
| 978 | 
            +
                                    model_ip2 = gr.Dropdown(value="base", label="Model", choices=IP_MODELS)
         | 
| 979 | 
            +
                                    mode_ip2 = gr.Dropdown(value="style", label="Mode", choices=MODE_IP_OPTIONS)
         | 
| 980 | 
            +
                                    scale_ip2 = gr.Slider(minimum=0., maximum=2., step=0.01, value=0.7, label="Scale")
         | 
| 981 | 
            +
             | 
| 982 | 
            +
                            with gr.Accordion("ControlNet / Img2img / Inpaint", open=False, visible=True):
         | 
| 983 | 
            +
                                image_control = gr.Image(label="Image ControlNet/Inpaint/Img2img", type="filepath")
         | 
| 984 | 
            +
                                image_mask_gui = gr.Image(label="Image Mask", type="filepath")
         | 
| 985 | 
            +
                                strength_gui = gr.Slider(
         | 
| 986 | 
            +
                                    minimum=0.01, maximum=1.0, step=0.01, value=0.55, label="Strength",
         | 
| 987 | 
            +
                                    info="This option adjusts the level of changes for img2img, repaint and inpaint."
         | 
| 988 | 
            +
                                )
         | 
| 989 | 
            +
                                image_resolution_gui = gr.Slider(
         | 
| 990 | 
            +
                                    minimum=64, maximum=2048, step=64, value=1024, label="Image Resolution",
         | 
| 991 | 
            +
                                    info="The maximum proportional size of the generated image based on the uploaded image."
         | 
| 992 | 
            +
                                )
         | 
| 993 | 
            +
                                controlnet_model_gui = gr.Dropdown(label="ControlNet model", choices=DIFFUSERS_CONTROLNET_MODEL, value=DIFFUSERS_CONTROLNET_MODEL[0], allow_custom_value=True)
         | 
| 994 | 
            +
                                control_net_output_scaling_gui = gr.Slider(minimum=0, maximum=5.0, step=0.1, value=1, label="ControlNet Output Scaling in UNet")
         | 
| 995 | 
            +
                                control_net_start_threshold_gui = gr.Slider(minimum=0, maximum=1, step=0.01, value=0, label="ControlNet Start Threshold (%)")
         | 
| 996 | 
            +
                                control_net_stop_threshold_gui = gr.Slider(minimum=0, maximum=1, step=0.01, value=1, label="ControlNet Stop Threshold (%)")
         | 
| 997 | 
            +
                                preprocessor_name_gui = gr.Dropdown(label="Preprocessor Name", choices=TASK_AND_PREPROCESSORS["canny"])
         | 
| 998 | 
            +
             | 
| 999 | 
            +
                                def change_preprocessor_choices(task):
         | 
| 1000 | 
            +
                                    task = TASK_STABLEPY[task]
         | 
| 1001 | 
            +
                                    if task in TASK_AND_PREPROCESSORS.keys():
         | 
| 1002 | 
            +
                                        choices_task = TASK_AND_PREPROCESSORS[task]
         | 
| 1003 | 
            +
                                    else:
         | 
| 1004 | 
            +
                                        choices_task = TASK_AND_PREPROCESSORS["canny"]
         | 
| 1005 | 
            +
                                    return gr.update(choices=choices_task, value=choices_task[0])
         | 
| 1006 | 
            +
                                task_gui.change(
         | 
| 1007 | 
            +
                                    change_preprocessor_choices,
         | 
| 1008 | 
            +
                                    [task_gui],
         | 
| 1009 | 
            +
                                    [preprocessor_name_gui],
         | 
| 1010 | 
            +
                                )
         | 
| 1011 | 
            +
             | 
| 1012 | 
            +
                                preprocess_resolution_gui = gr.Slider(minimum=64, maximum=2048, step=64, value=512, label="Preprocessor Resolution")
         | 
| 1013 | 
            +
                                low_threshold_gui = gr.Slider(minimum=1, maximum=255, step=1, value=100, label="'CANNY' low threshold")
         | 
| 1014 | 
            +
                                high_threshold_gui = gr.Slider(minimum=1, maximum=255, step=1, value=200, label="'CANNY' high threshold")
         | 
| 1015 | 
            +
                                value_threshold_gui = gr.Slider(minimum=1, maximum=2.0, step=0.01, value=0.1, label="'MLSD' Hough value threshold")
         | 
| 1016 | 
            +
                                distance_threshold_gui = gr.Slider(minimum=1, maximum=20.0, step=0.01, value=0.1, label="'MLSD' Hough distance threshold")
         | 
| 1017 | 
            +
                                recolor_gamma_correction_gui = gr.Number(minimum=0., maximum=25., value=1., step=0.001, label="'RECOLOR' gamma correction")
         | 
| 1018 | 
            +
                                tile_blur_sigma_gui = gr.Number(minimum=0, maximum=100, value=9, step=1, label="'TILE' blur sigma")
         | 
| 1019 | 
            +
             | 
| 1020 | 
            +
                            with gr.Accordion("T2I adapter", open=False, visible=False):
         | 
| 1021 | 
            +
                                t2i_adapter_preprocessor_gui = gr.Checkbox(value=True, label="T2i Adapter Preprocessor")
         | 
| 1022 | 
            +
                                adapter_conditioning_scale_gui = gr.Slider(minimum=0, maximum=5., step=0.1, value=1, label="Adapter Conditioning Scale")
         | 
| 1023 | 
            +
                                adapter_conditioning_factor_gui = gr.Slider(minimum=0, maximum=1., step=0.01, value=0.55, label="Adapter Conditioning Factor (%)")
         | 
| 1024 | 
            +
             | 
| 1025 | 
            +
                            with gr.Accordion("Styles", open=False, visible=True):
         | 
| 1026 | 
            +
             | 
| 1027 | 
            +
                                try:
         | 
| 1028 | 
            +
                                    style_names_found = sd_gen.model.STYLE_NAMES
         | 
| 1029 | 
            +
                                except Exception:
         | 
| 1030 | 
            +
                                    style_names_found = STYLE_NAMES
         | 
| 1031 | 
            +
             | 
| 1032 | 
            +
                                style_prompt_gui = gr.Dropdown(
         | 
| 1033 | 
            +
                                    style_names_found,
         | 
| 1034 | 
            +
                                    multiselect=True,
         | 
| 1035 | 
            +
                                    value=None,
         | 
| 1036 | 
            +
                                    label="Style Prompt",
         | 
| 1037 | 
            +
                                    interactive=True,
         | 
| 1038 | 
            +
                                )
         | 
| 1039 | 
            +
                                style_json_gui = gr.File(label="Style JSON File")
         | 
| 1040 | 
            +
                                style_button = gr.Button("Load styles")
         | 
| 1041 | 
            +
             | 
| 1042 | 
            +
                                def load_json_style_file(json):
         | 
| 1043 | 
            +
                                    if not sd_gen.model:
         | 
| 1044 | 
            +
                                        gr.Info("First load the model")
         | 
| 1045 | 
            +
                                        return gr.update(value=None, choices=STYLE_NAMES)
         | 
| 1046 | 
            +
             | 
| 1047 | 
            +
                                    sd_gen.model.load_style_file(json)
         | 
| 1048 | 
            +
                                    gr.Info(f"{len(sd_gen.model.STYLE_NAMES)} styles loaded")
         | 
| 1049 | 
            +
                                    return gr.update(value=None, choices=sd_gen.model.STYLE_NAMES)
         | 
| 1050 | 
            +
             | 
| 1051 | 
            +
                                style_button.click(load_json_style_file, [style_json_gui], [style_prompt_gui])                        
         | 
| 1052 | 
            +
             | 
| 1053 | 
            +
                            with gr.Accordion("Textual inversion", open=False, visible=False):
         | 
| 1054 | 
            +
                                active_textual_inversion_gui = gr.Checkbox(value=False, label="Active Textual Inversion in prompt")
         | 
| 1055 | 
            +
             | 
| 1056 | 
            +
                            with gr.Accordion("Detailfix", open=False, visible=True):
         | 
| 1057 | 
            +
             | 
| 1058 | 
            +
                                # Adetailer Inpaint Only
         | 
| 1059 | 
            +
                                adetailer_inpaint_only_gui = gr.Checkbox(label="Inpaint only", value=True)
         | 
| 1060 | 
            +
             | 
| 1061 | 
            +
                                # Adetailer Verbose
         | 
| 1062 | 
            +
                                adetailer_verbose_gui = gr.Checkbox(label="Verbose", value=False)
         | 
| 1063 | 
            +
             | 
| 1064 | 
            +
                                # Adetailer Sampler
         | 
| 1065 | 
            +
                                adetailer_sampler_gui = gr.Dropdown(label="Adetailer sampler:", choices=POST_PROCESSING_SAMPLER, value=POST_PROCESSING_SAMPLER[0])
         | 
| 1066 | 
            +
             | 
| 1067 | 
            +
                                with gr.Accordion("Detailfix A", open=False, visible=True):
         | 
| 1068 | 
            +
                                    # Adetailer A
         | 
| 1069 | 
            +
                                    adetailer_active_a_gui = gr.Checkbox(label="Enable Adetailer A", value=False)
         | 
| 1070 | 
            +
                                    prompt_ad_a_gui = gr.Textbox(label="Main prompt", placeholder="Main prompt will be use", lines=3)
         | 
| 1071 | 
            +
                                    negative_prompt_ad_a_gui = gr.Textbox(label="Negative prompt", placeholder="Main negative prompt will be use", lines=3)
         | 
| 1072 | 
            +
                                    strength_ad_a_gui = gr.Number(label="Strength:", value=0.35, step=0.01, minimum=0.01, maximum=1.0)
         | 
| 1073 | 
            +
                                    face_detector_ad_a_gui = gr.Checkbox(label="Face detector", value=True)
         | 
| 1074 | 
            +
                                    person_detector_ad_a_gui = gr.Checkbox(label="Person detector", value=False)
         | 
| 1075 | 
            +
                                    hand_detector_ad_a_gui = gr.Checkbox(label="Hand detector", value=False)
         | 
| 1076 | 
            +
                                    mask_dilation_a_gui = gr.Number(label="Mask dilation:", value=4, minimum=1)
         | 
| 1077 | 
            +
                                    mask_blur_a_gui = gr.Number(label="Mask blur:", value=4, minimum=1)
         | 
| 1078 | 
            +
                                    mask_padding_a_gui = gr.Number(label="Mask padding:", value=32, minimum=1)
         | 
| 1079 | 
            +
             | 
| 1080 | 
            +
                                with gr.Accordion("Detailfix B", open=False, visible=True):
         | 
| 1081 | 
            +
                                    # Adetailer B
         | 
| 1082 | 
            +
                                    adetailer_active_b_gui = gr.Checkbox(label="Enable Adetailer B", value=False)
         | 
| 1083 | 
            +
                                    prompt_ad_b_gui = gr.Textbox(label="Main prompt", placeholder="Main prompt will be use", lines=3)
         | 
| 1084 | 
            +
                                    negative_prompt_ad_b_gui = gr.Textbox(label="Negative prompt", placeholder="Main negative prompt will be use", lines=3)
         | 
| 1085 | 
            +
                                    strength_ad_b_gui = gr.Number(label="Strength:", value=0.35, step=0.01, minimum=0.01, maximum=1.0)
         | 
| 1086 | 
            +
                                    face_detector_ad_b_gui = gr.Checkbox(label="Face detector", value=False)
         | 
| 1087 | 
            +
                                    person_detector_ad_b_gui = gr.Checkbox(label="Person detector", value=True)
         | 
| 1088 | 
            +
                                    hand_detector_ad_b_gui = gr.Checkbox(label="Hand detector", value=False)
         | 
| 1089 | 
            +
                                    mask_dilation_b_gui = gr.Number(label="Mask dilation:", value=4, minimum=1)
         | 
| 1090 | 
            +
                                    mask_blur_b_gui = gr.Number(label="Mask blur:", value=4, minimum=1)
         | 
| 1091 | 
            +
                                    mask_padding_b_gui = gr.Number(label="Mask padding:", value=32, minimum=1)
         | 
| 1092 | 
            +
             | 
| 1093 | 
            +
                            with gr.Accordion("Other settings", open=False, visible=True):
         | 
| 1094 | 
            +
                                schedule_prediction_type_gui = gr.Dropdown(label="Discrete Sampling Type", choices=SCHEDULE_PREDICTION_TYPE_OPTIONS, value=SCHEDULE_PREDICTION_TYPE_OPTIONS[0])
         | 
| 1095 | 
            +
                                guidance_rescale_gui = gr.Number(label="CFG rescale:", value=0., step=0.01, minimum=0., maximum=1.5)
         | 
| 1096 | 
            +
                                save_generated_images_gui = gr.Checkbox(value=True, label="Create a download link for the images")
         | 
| 1097 | 
            +
                                filename_pattern_gui = gr.Textbox(label="Filename pattern", value="model,seed", placeholder="model,seed,sampler,schedule_type,img_width,img_height,guidance_scale,num_steps,vae,prompt_section,neg_prompt_section", lines=1)
         | 
| 1098 | 
            +
                                hires_before_adetailer_gui = gr.Checkbox(value=False, label="Hires Before Adetailer")
         | 
| 1099 | 
            +
                                hires_after_adetailer_gui = gr.Checkbox(value=True, label="Hires After Adetailer")
         | 
| 1100 | 
            +
                                generator_in_cpu_gui = gr.Checkbox(value=False, label="Generator in CPU")
         | 
| 1101 | 
            +
             | 
| 1102 | 
            +
                            with gr.Accordion("More settings", open=False, visible=False):
         | 
| 1103 | 
            +
                                loop_generation_gui = gr.Slider(minimum=1, value=1, label="Loop Generation")
         | 
| 1104 | 
            +
                                retain_task_cache_gui = gr.Checkbox(value=False, label="Retain task model in cache")
         | 
| 1105 | 
            +
                                leave_progress_bar_gui = gr.Checkbox(value=True, label="Leave Progress Bar")
         | 
| 1106 | 
            +
                                disable_progress_bar_gui = gr.Checkbox(value=False, label="Disable Progress Bar")
         | 
| 1107 | 
            +
                                display_images_gui = gr.Checkbox(value=False, label="Display Images")
         | 
| 1108 | 
            +
                                image_previews_gui = gr.Checkbox(value=True, label="Image Previews")
         | 
| 1109 | 
            +
                                image_storage_location_gui = gr.Textbox(value="./images", label="Image Storage Location")
         | 
| 1110 | 
            +
                                retain_compel_previous_load_gui = gr.Checkbox(value=False, label="Retain Compel Previous Load")
         | 
| 1111 | 
            +
                                retain_detailfix_model_previous_load_gui = gr.Checkbox(value=False, label="Retain Detailfix Model Previous Load")
         | 
| 1112 | 
            +
                                retain_hires_model_previous_load_gui = gr.Checkbox(value=False, label="Retain Hires Model Previous Load")
         | 
| 1113 | 
            +
                                xformers_memory_efficient_attention_gui = gr.Checkbox(value=False, label="Xformers Memory Efficient Attention")
         | 
| 1114 | 
            +
             | 
| 1115 | 
            +
                    with gr.Accordion("Examples and help", open=False, visible=True):
         | 
| 1116 | 
            +
                        gr.Markdown(HELP_GUI)
         | 
| 1117 | 
            +
                        gr.Markdown(EXAMPLES_GUI_HELP)
         | 
| 1118 | 
            +
                        gr.Examples(
         | 
| 1119 | 
            +
                            examples=EXAMPLES_GUI,
         | 
| 1120 | 
            +
                            fn=sd_gen.generate_pipeline,
         | 
| 1121 | 
            +
                            inputs=[
         | 
| 1122 | 
            +
                                prompt_gui,
         | 
| 1123 | 
            +
                                neg_prompt_gui,
         | 
| 1124 | 
            +
                                steps_gui,
         | 
| 1125 | 
            +
                                cfg_gui,
         | 
| 1126 | 
            +
                                seed_gui,
         | 
| 1127 | 
            +
                                lora1_gui,
         | 
| 1128 | 
            +
                                lora_scale_1_gui,
         | 
| 1129 | 
            +
                                sampler_gui,
         | 
| 1130 | 
            +
                                img_height_gui,
         | 
| 1131 | 
            +
                                img_width_gui,
         | 
| 1132 | 
            +
                                model_name_gui,
         | 
| 1133 | 
            +
                                task_gui,
         | 
| 1134 | 
            +
                                image_control,
         | 
| 1135 | 
            +
                                image_resolution_gui,
         | 
| 1136 | 
            +
                                strength_gui,
         | 
| 1137 | 
            +
                                control_net_output_scaling_gui,
         | 
| 1138 | 
            +
                                control_net_start_threshold_gui,
         | 
| 1139 | 
            +
                                control_net_stop_threshold_gui,
         | 
| 1140 | 
            +
                                prompt_syntax_gui,
         | 
| 1141 | 
            +
                                upscaler_model_path_gui,
         | 
| 1142 | 
            +
                                gpu_duration_gui,
         | 
| 1143 | 
            +
                                load_lora_cpu_gui,
         | 
| 1144 | 
            +
                            ],
         | 
| 1145 | 
            +
                            outputs=[load_model_gui, result_images, actual_task_info],
         | 
| 1146 | 
            +
                            cache_examples=False,
         | 
| 1147 | 
            +
                        )
         | 
| 1148 | 
            +
                        gr.Markdown(RESOURCES)
         | 
| 1149 | 
            +
             | 
| 1150 | 
            +
                with gr.Tab("Inpaint mask maker", render=True):
         | 
| 1151 | 
            +
             | 
| 1152 | 
            +
                    with gr.Row():
         | 
| 1153 | 
            +
                        with gr.Column(scale=2):
         | 
| 1154 | 
            +
                            image_base = gr.ImageEditor(
         | 
| 1155 | 
            +
                                sources=["upload", "clipboard"],
         | 
| 1156 | 
            +
                                # crop_size="1:1",
         | 
| 1157 | 
            +
                                # enable crop (or disable it)
         | 
| 1158 | 
            +
                                # transforms=["crop"],
         | 
| 1159 | 
            +
                                brush=gr.Brush(
         | 
| 1160 | 
            +
                                    default_size="16",  # or leave it as 'auto'
         | 
| 1161 | 
            +
                                    color_mode="fixed",  # 'fixed' hides the user swatches and colorpicker, 'defaults' shows it
         | 
| 1162 | 
            +
                                    # default_color="black", # html names are supported
         | 
| 1163 | 
            +
                                    colors=[
         | 
| 1164 | 
            +
                                        "rgba(0, 0, 0, 1)",  # rgb(a)
         | 
| 1165 | 
            +
                                        "rgba(0, 0, 0, 0.1)",
         | 
| 1166 | 
            +
                                        "rgba(255, 255, 255, 0.1)",
         | 
| 1167 | 
            +
                                        # "hsl(360, 120, 120)" # in fact any valid colorstring
         | 
| 1168 | 
            +
                                    ]
         | 
| 1169 | 
            +
                                ),
         | 
| 1170 | 
            +
                                eraser=gr.Eraser(default_size="16")
         | 
| 1171 | 
            +
                            )
         | 
| 1172 | 
            +
                            invert_mask = gr.Checkbox(value=False, label="Invert mask")
         | 
| 1173 | 
            +
                            btn = gr.Button("Create mask")
         | 
| 1174 | 
            +
                        with gr.Column(scale=1):
         | 
| 1175 | 
            +
                            img_source = gr.Image(interactive=False)
         | 
| 1176 | 
            +
                            img_result = gr.Image(label="Mask image", show_label=True, interactive=False)
         | 
| 1177 | 
            +
                            btn_send = gr.Button("Send to the first tab")
         | 
| 1178 | 
            +
             | 
| 1179 | 
            +
                        btn.click(create_mask_now, [image_base, invert_mask], [img_source, img_result])
         | 
| 1180 | 
            +
             | 
| 1181 | 
            +
                        def send_img(img_source, img_result):
         | 
| 1182 | 
            +
                            return img_source, img_result
         | 
| 1183 | 
            +
                        btn_send.click(send_img, [img_source, img_result], [image_control, image_mask_gui])
         | 
| 1184 | 
            +
             | 
| 1185 | 
            +
                with gr.Tab("PNG Info"):
         | 
| 1186 | 
            +
             | 
| 1187 | 
            +
                    with gr.Row():
         | 
| 1188 | 
            +
                        with gr.Column():
         | 
| 1189 | 
            +
                            image_metadata = gr.Image(label="Image with metadata", type="pil", sources=["upload"])
         | 
| 1190 | 
            +
             | 
| 1191 | 
            +
                        with gr.Column():
         | 
| 1192 | 
            +
                            result_metadata = gr.Textbox(label="Metadata", show_label=True, show_copy_button=True, interactive=False, container=True, max_lines=99)
         | 
| 1193 | 
            +
             | 
| 1194 | 
            +
                            image_metadata.change(
         | 
| 1195 | 
            +
                                fn=extract_exif_data,
         | 
| 1196 | 
            +
                                inputs=[image_metadata],
         | 
| 1197 | 
            +
                                outputs=[result_metadata],
         | 
| 1198 | 
            +
                            )
         | 
| 1199 | 
            +
             | 
| 1200 | 
            +
                with gr.Tab("Upscaler"):
         | 
| 1201 | 
            +
             | 
| 1202 | 
            +
                    with gr.Row():
         | 
| 1203 | 
            +
                        with gr.Column():
         | 
| 1204 | 
            +
             | 
| 1205 | 
            +
                            USCALER_TAB_KEYS = [name for name in UPSCALER_KEYS[9:]]
         | 
| 1206 | 
            +
             | 
| 1207 | 
            +
                            image_up_tab = gr.Image(label="Image", type="pil", sources=["upload"])
         | 
| 1208 | 
            +
                            upscaler_tab = gr.Dropdown(label="Upscaler", choices=USCALER_TAB_KEYS, value=USCALER_TAB_KEYS[5])
         | 
| 1209 | 
            +
                            upscaler_size_tab = gr.Slider(minimum=1., maximum=4., step=0.1, value=1.1, label="Upscale by")
         | 
| 1210 | 
            +
                            generate_button_up_tab = gr.Button(value="START UPSCALE", variant="primary")
         | 
| 1211 | 
            +
             | 
| 1212 | 
            +
                        with gr.Column():
         | 
| 1213 | 
            +
                            result_up_tab = gr.Image(label="Result", type="pil", interactive=False, format="png")
         | 
| 1214 | 
            +
             | 
| 1215 | 
            +
                            generate_button_up_tab.click(
         | 
| 1216 | 
            +
                                fn=process_upscale,
         | 
| 1217 | 
            +
                                inputs=[image_up_tab, upscaler_tab, upscaler_size_tab],
         | 
| 1218 | 
            +
                                outputs=[result_up_tab],
         | 
| 1219 | 
            +
                            )
         | 
| 1220 | 
            +
             | 
| 1221 | 
            +
                with gr.Tab("Preprocessor", render=True):
         | 
| 1222 | 
            +
                    preprocessor_tab()
         | 
| 1223 | 
            +
             | 
| 1224 | 
            +
                generate_button.click(
         | 
| 1225 | 
            +
                    fn=sd_gen.load_new_model,
         | 
| 1226 | 
            +
                    inputs=[
         | 
| 1227 | 
            +
                        model_name_gui,
         | 
| 1228 | 
            +
                        vae_model_gui,
         | 
| 1229 | 
            +
                        task_gui,
         | 
| 1230 | 
            +
                        controlnet_model_gui,
         | 
| 1231 | 
            +
                    ],
         | 
| 1232 | 
            +
                    outputs=[load_model_gui],
         | 
| 1233 | 
            +
                    queue=True,
         | 
| 1234 | 
            +
                    show_progress="minimal",
         | 
| 1235 | 
            +
                ).success(
         | 
| 1236 | 
            +
                    fn=sd_gen_generate_pipeline,  # fn=sd_gen.generate_pipeline,
         | 
| 1237 | 
            +
                    inputs=[
         | 
| 1238 | 
            +
                        prompt_gui,
         | 
| 1239 | 
            +
                        neg_prompt_gui,
         | 
| 1240 | 
            +
                        num_images_gui,
         | 
| 1241 | 
            +
                        steps_gui,
         | 
| 1242 | 
            +
                        cfg_gui,
         | 
| 1243 | 
            +
                        clip_skip_gui,
         | 
| 1244 | 
            +
                        seed_gui,
         | 
| 1245 | 
            +
                        lora1_gui,
         | 
| 1246 | 
            +
                        lora_scale_1_gui,
         | 
| 1247 | 
            +
                        lora2_gui,
         | 
| 1248 | 
            +
                        lora_scale_2_gui,
         | 
| 1249 | 
            +
                        lora3_gui,
         | 
| 1250 | 
            +
                        lora_scale_3_gui,
         | 
| 1251 | 
            +
                        lora4_gui,
         | 
| 1252 | 
            +
                        lora_scale_4_gui,
         | 
| 1253 | 
            +
                        lora5_gui,
         | 
| 1254 | 
            +
                        lora_scale_5_gui,
         | 
| 1255 | 
            +
                        lora6_gui,
         | 
| 1256 | 
            +
                        lora_scale_6_gui,
         | 
| 1257 | 
            +
                        lora7_gui,
         | 
| 1258 | 
            +
                        lora_scale_7_gui,
         | 
| 1259 | 
            +
                        sampler_gui,
         | 
| 1260 | 
            +
                        schedule_type_gui,
         | 
| 1261 | 
            +
                        schedule_prediction_type_gui,
         | 
| 1262 | 
            +
                        img_height_gui,
         | 
| 1263 | 
            +
                        img_width_gui,
         | 
| 1264 | 
            +
                        model_name_gui,
         | 
| 1265 | 
            +
                        vae_model_gui,
         | 
| 1266 | 
            +
                        task_gui,
         | 
| 1267 | 
            +
                        image_control,
         | 
| 1268 | 
            +
                        preprocessor_name_gui,
         | 
| 1269 | 
            +
                        preprocess_resolution_gui,
         | 
| 1270 | 
            +
                        image_resolution_gui,
         | 
| 1271 | 
            +
                        style_prompt_gui,
         | 
| 1272 | 
            +
                        style_json_gui,
         | 
| 1273 | 
            +
                        image_mask_gui,
         | 
| 1274 | 
            +
                        strength_gui,
         | 
| 1275 | 
            +
                        low_threshold_gui,
         | 
| 1276 | 
            +
                        high_threshold_gui,
         | 
| 1277 | 
            +
                        value_threshold_gui,
         | 
| 1278 | 
            +
                        distance_threshold_gui,
         | 
| 1279 | 
            +
                        recolor_gamma_correction_gui,
         | 
| 1280 | 
            +
                        tile_blur_sigma_gui,
         | 
| 1281 | 
            +
                        control_net_output_scaling_gui,
         | 
| 1282 | 
            +
                        control_net_start_threshold_gui,
         | 
| 1283 | 
            +
                        control_net_stop_threshold_gui,
         | 
| 1284 | 
            +
                        active_textual_inversion_gui,
         | 
| 1285 | 
            +
                        prompt_syntax_gui,
         | 
| 1286 | 
            +
                        upscaler_model_path_gui,
         | 
| 1287 | 
            +
                        upscaler_increases_size_gui,
         | 
| 1288 | 
            +
                        upscaler_tile_size_gui,
         | 
| 1289 | 
            +
                        upscaler_tile_overlap_gui,
         | 
| 1290 | 
            +
                        hires_steps_gui,
         | 
| 1291 | 
            +
                        hires_denoising_strength_gui,
         | 
| 1292 | 
            +
                        hires_sampler_gui,
         | 
| 1293 | 
            +
                        hires_prompt_gui,
         | 
| 1294 | 
            +
                        hires_negative_prompt_gui,
         | 
| 1295 | 
            +
                        hires_before_adetailer_gui,
         | 
| 1296 | 
            +
                        hires_after_adetailer_gui,
         | 
| 1297 | 
            +
                        hires_schedule_type_gui,
         | 
| 1298 | 
            +
                        hires_guidance_scale_gui,
         | 
| 1299 | 
            +
                        controlnet_model_gui,
         | 
| 1300 | 
            +
                        loop_generation_gui,
         | 
| 1301 | 
            +
                        leave_progress_bar_gui,
         | 
| 1302 | 
            +
                        disable_progress_bar_gui,
         | 
| 1303 | 
            +
                        image_previews_gui,
         | 
| 1304 | 
            +
                        display_images_gui,
         | 
| 1305 | 
            +
                        save_generated_images_gui,
         | 
| 1306 | 
            +
                        filename_pattern_gui,
         | 
| 1307 | 
            +
                        image_storage_location_gui,
         | 
| 1308 | 
            +
                        retain_compel_previous_load_gui,
         | 
| 1309 | 
            +
                        retain_detailfix_model_previous_load_gui,
         | 
| 1310 | 
            +
                        retain_hires_model_previous_load_gui,
         | 
| 1311 | 
            +
                        t2i_adapter_preprocessor_gui,
         | 
| 1312 | 
            +
                        adapter_conditioning_scale_gui,
         | 
| 1313 | 
            +
                        adapter_conditioning_factor_gui,
         | 
| 1314 | 
            +
                        xformers_memory_efficient_attention_gui,
         | 
| 1315 | 
            +
                        free_u_gui,
         | 
| 1316 | 
            +
                        generator_in_cpu_gui,
         | 
| 1317 | 
            +
                        adetailer_inpaint_only_gui,
         | 
| 1318 | 
            +
                        adetailer_verbose_gui,
         | 
| 1319 | 
            +
                        adetailer_sampler_gui,
         | 
| 1320 | 
            +
                        adetailer_active_a_gui,
         | 
| 1321 | 
            +
                        prompt_ad_a_gui,
         | 
| 1322 | 
            +
                        negative_prompt_ad_a_gui,
         | 
| 1323 | 
            +
                        strength_ad_a_gui,
         | 
| 1324 | 
            +
                        face_detector_ad_a_gui,
         | 
| 1325 | 
            +
                        person_detector_ad_a_gui,
         | 
| 1326 | 
            +
                        hand_detector_ad_a_gui,
         | 
| 1327 | 
            +
                        mask_dilation_a_gui,
         | 
| 1328 | 
            +
                        mask_blur_a_gui,
         | 
| 1329 | 
            +
                        mask_padding_a_gui,
         | 
| 1330 | 
            +
                        adetailer_active_b_gui,
         | 
| 1331 | 
            +
                        prompt_ad_b_gui,
         | 
| 1332 | 
            +
                        negative_prompt_ad_b_gui,
         | 
| 1333 | 
            +
                        strength_ad_b_gui,
         | 
| 1334 | 
            +
                        face_detector_ad_b_gui,
         | 
| 1335 | 
            +
                        person_detector_ad_b_gui,
         | 
| 1336 | 
            +
                        hand_detector_ad_b_gui,
         | 
| 1337 | 
            +
                        mask_dilation_b_gui,
         | 
| 1338 | 
            +
                        mask_blur_b_gui,
         | 
| 1339 | 
            +
                        mask_padding_b_gui,
         | 
| 1340 | 
            +
                        retain_task_cache_gui,
         | 
| 1341 | 
            +
                        guidance_rescale_gui,
         | 
| 1342 | 
            +
                        image_ip1,
         | 
| 1343 | 
            +
                        mask_ip1,
         | 
| 1344 | 
            +
                        model_ip1,
         | 
| 1345 | 
            +
                        mode_ip1,
         | 
| 1346 | 
            +
                        scale_ip1,
         | 
| 1347 | 
            +
                        image_ip2,
         | 
| 1348 | 
            +
                        mask_ip2,
         | 
| 1349 | 
            +
                        model_ip2,
         | 
| 1350 | 
            +
                        mode_ip2,
         | 
| 1351 | 
            +
                        scale_ip2,
         | 
| 1352 | 
            +
                        pag_scale_gui,
         | 
| 1353 | 
            +
                        face_restoration_model_gui,
         | 
| 1354 | 
            +
                        face_restoration_visibility_gui,
         | 
| 1355 | 
            +
                        face_restoration_weight_gui,
         | 
| 1356 | 
            +
                        load_lora_cpu_gui,
         | 
| 1357 | 
            +
                        verbose_info_gui,
         | 
| 1358 | 
            +
                        gpu_duration_gui,
         | 
| 1359 | 
            +
                    ],
         | 
| 1360 | 
            +
                    outputs=[load_model_gui, result_images, actual_task_info],
         | 
| 1361 | 
            +
                    queue=True,
         | 
| 1362 | 
            +
                    show_progress="minimal",
         | 
| 1363 | 
            +
                )
         | 
| 1364 | 
            +
             | 
| 1365 | 
            +
            app.queue()
         | 
| 1366 | 
            +
             | 
| 1367 | 
            +
            app.launch(
         | 
| 1368 | 
            +
                show_error=True,
         | 
| 1369 | 
            +
                debug=True,
         | 
| 1370 | 
            +
                allowed_paths=["./images/"],
         | 
| 1371 | 
            +
            )
         | 
    	
        color_image.png
    ADDED
    
    |   | 
    	
        constants.py
    ADDED
    
    | @@ -0,0 +1,585 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            import os
         | 
| 2 | 
            +
            from stablepy.diffusers_vanilla.constants import FLUX_CN_UNION_MODES
         | 
| 3 | 
            +
            from stablepy import (
         | 
| 4 | 
            +
                scheduler_names,
         | 
| 5 | 
            +
                SD15_TASKS,
         | 
| 6 | 
            +
                SDXL_TASKS,
         | 
| 7 | 
            +
                ALL_BUILTIN_UPSCALERS,
         | 
| 8 | 
            +
                IP_ADAPTERS_SD,
         | 
| 9 | 
            +
                IP_ADAPTERS_SDXL,
         | 
| 10 | 
            +
            )
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            # - **Download Models**
         | 
| 13 | 
            +
            DOWNLOAD_MODEL = "https://huggingface.co/TechnoByte/MilkyWonderland/resolve/main/milkyWonderland_v40.safetensors"
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            # - **Download VAEs**
         | 
| 16 | 
            +
            DOWNLOAD_VAE = "https://huggingface.co/fp16-guy/anything_kl-f8-anime2_vae-ft-mse-840000-ema-pruned_blessed_clearvae_fp16_cleaned/resolve/main/vae-ft-mse-840000-ema-pruned_fp16.safetensors?download=true"
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            # - **Download LoRAs**
         | 
| 19 | 
            +
            DOWNLOAD_LORA = "https://huggingface.co/Leopain/color/resolve/main/Coloring_book_-_LineArt.safetensors, https://civitai.com/api/download/models/135867, https://huggingface.co/Linaqruf/anime-detailer-xl-lora/resolve/main/anime-detailer-xl.safetensors?download=true, https://huggingface.co/Linaqruf/style-enhancer-xl-lora/resolve/main/style-enhancer-xl.safetensors?download=true, https://huggingface.co/ByteDance/Hyper-SD/resolve/main/Hyper-SD15-8steps-CFG-lora.safetensors?download=true, https://huggingface.co/ByteDance/Hyper-SD/resolve/main/Hyper-SDXL-8steps-CFG-lora.safetensors?download=true"
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            LOAD_DIFFUSERS_FORMAT_MODEL = [
         | 
| 22 | 
            +
                'stabilityai/stable-diffusion-xl-base-1.0',
         | 
| 23 | 
            +
                'Laxhar/noobai-XL-1.1',
         | 
| 24 | 
            +
                'Laxhar/noobai-XL-Vpred-1.0',
         | 
| 25 | 
            +
                'black-forest-labs/FLUX.1-dev',
         | 
| 26 | 
            +
                'John6666/blue-pencil-flux1-v021-fp8-flux',
         | 
| 27 | 
            +
                'John6666/wai-ani-flux-v10forfp8-fp8-flux',
         | 
| 28 | 
            +
                'John6666/xe-anime-flux-v04-fp8-flux',
         | 
| 29 | 
            +
                'John6666/lyh-anime-flux-v2a1-fp8-flux',
         | 
| 30 | 
            +
                'John6666/carnival-unchained-v10-fp8-flux',
         | 
| 31 | 
            +
                'John6666/iniverse-mix-xl-sfwnsfw-fluxdfp16nsfwv11-fp8-flux',
         | 
| 32 | 
            +
                'Freepik/flux.1-lite-8B-alpha',
         | 
| 33 | 
            +
                'shauray/FluxDev-HyperSD-merged',
         | 
| 34 | 
            +
                'mikeyandfriends/PixelWave_FLUX.1-dev_03',
         | 
| 35 | 
            +
                'terminusresearch/FluxBooru-v0.3',
         | 
| 36 | 
            +
                'black-forest-labs/FLUX.1-schnell',
         | 
| 37 | 
            +
                # 'ostris/OpenFLUX.1',
         | 
| 38 | 
            +
                'shuttleai/shuttle-3-diffusion',
         | 
| 39 | 
            +
                'Laxhar/noobai-XL-1.0',
         | 
| 40 | 
            +
                'John6666/noobai-xl-nai-xl-epsilonpred10version-sdxl',
         | 
| 41 | 
            +
                'Laxhar/noobai-XL-0.77',
         | 
| 42 | 
            +
                'John6666/noobai-xl-nai-xl-epsilonpred075version-sdxl',
         | 
| 43 | 
            +
                'Laxhar/noobai-XL-0.6',
         | 
| 44 | 
            +
                'John6666/noobai-xl-nai-xl-epsilonpred05version-sdxl',
         | 
| 45 | 
            +
                'John6666/noobai-cyberfix-v10-sdxl',
         | 
| 46 | 
            +
                'John6666/noobaiiter-xl-vpred-v075-sdxl',
         | 
| 47 | 
            +
                'John6666/ntr-mix-illustrious-xl-noob-xl-v40-sdxl',
         | 
| 48 | 
            +
                'John6666/ntr-mix-illustrious-xl-noob-xl-ntrmix35-sdxl',
         | 
| 49 | 
            +
                'John6666/ntr-mix-illustrious-xl-noob-xl-v777-sdxl',
         | 
| 50 | 
            +
                'John6666/ntr-mix-illustrious-xl-noob-xl-v777forlora-sdxl',
         | 
| 51 | 
            +
                'John6666/ntr-mix-illustrious-xl-noob-xl-xi-sdxl',
         | 
| 52 | 
            +
                'John6666/ntr-mix-illustrious-xl-noob-xl-xii-sdxl',
         | 
| 53 | 
            +
                'John6666/ntr-mix-illustrious-xl-noob-xl-xiii-sdxl',
         | 
| 54 | 
            +
                'John6666/mistoon-anime-v10illustrious-sdxl',
         | 
| 55 | 
            +
                'John6666/hassaku-xl-illustrious-v10-sdxl',
         | 
| 56 | 
            +
                'John6666/hassaku-xl-illustrious-v10style-sdxl',
         | 
| 57 | 
            +
                'John6666/haruki-mix-illustrious-v10-sdxl',
         | 
| 58 | 
            +
                'John6666/noobreal-v10-sdxl',
         | 
| 59 | 
            +
                'John6666/complicated-noobai-merge-vprediction-sdxl',
         | 
| 60 | 
            +
                'Laxhar/noobai-XL-Vpred-0.9r',
         | 
| 61 | 
            +
                'Laxhar/noobai-XL-Vpred-0.75s',
         | 
| 62 | 
            +
                'Laxhar/noobai-XL-Vpred-0.75',
         | 
| 63 | 
            +
                'Laxhar/noobai-XL-Vpred-0.65s',
         | 
| 64 | 
            +
                'Laxhar/noobai-XL-Vpred-0.65',
         | 
| 65 | 
            +
                'Laxhar/noobai-XL-Vpred-0.6',
         | 
| 66 | 
            +
                'John6666/cat-tower-noobai-xl-checkpoint-v14vpred-sdxl',
         | 
| 67 | 
            +
                'John6666/noobai-xl-nai-xl-vpred05version-sdxl',
         | 
| 68 | 
            +
                'John6666/noobai-fusion2-vpred-itercomp-v1-sdxl',
         | 
| 69 | 
            +
                'John6666/noobai-xl-nai-xl-vpredtestversion-sdxl',
         | 
| 70 | 
            +
                'John6666/chadmix-noobai075-illustrious01-v10-sdxl',
         | 
| 71 | 
            +
                'OnomaAIResearch/Illustrious-xl-early-release-v0',
         | 
| 72 | 
            +
                'John6666/illustriousxl-mmmix-v50-sdxl',
         | 
| 73 | 
            +
                'John6666/illustrious-pencil-xl-v200-sdxl',
         | 
| 74 | 
            +
                'John6666/obsession-illustriousxl-v21-sdxl',
         | 
| 75 | 
            +
                'John6666/obsession-illustriousxl-v30-sdxl',
         | 
| 76 | 
            +
                'John6666/obsession-illustriousxl-v31-sdxl',
         | 
| 77 | 
            +
                'John6666/wai-nsfw-illustrious-v70-sdxl',
         | 
| 78 | 
            +
                'John6666/illustrious-pony-mix-v3-sdxl',
         | 
| 79 | 
            +
                'John6666/nova-anime-xl-illustriousv10-sdxl',
         | 
| 80 | 
            +
                'John6666/nova-orange-xl-v30-sdxl',
         | 
| 81 | 
            +
                'John6666/silvermoon-mix03-illustrious-v10-sdxl',
         | 
| 82 | 
            +
                'eienmojiki/Anything-XL',
         | 
| 83 | 
            +
                'eienmojiki/Starry-XL-v5.2',
         | 
| 84 | 
            +
                'John6666/meinaxl-v2-sdxl',
         | 
| 85 | 
            +
                'Eugeoter/artiwaifu-diffusion-2.0',
         | 
| 86 | 
            +
                'comin/IterComp',
         | 
| 87 | 
            +
                'John6666/epicrealism-xl-vxiabeast-sdxl',
         | 
| 88 | 
            +
                'John6666/epicrealism-xl-v10kiss2-sdxl',
         | 
| 89 | 
            +
                'John6666/epicrealism-xl-v8kiss-sdxl',
         | 
| 90 | 
            +
                'misri/zavychromaxl_v80',
         | 
| 91 | 
            +
                'SG161222/RealVisXL_V4.0',
         | 
| 92 | 
            +
                'SG161222/RealVisXL_V5.0',
         | 
| 93 | 
            +
                'misri/newrealityxlAllInOne_Newreality40',
         | 
| 94 | 
            +
                'gsdf/CounterfeitXL',
         | 
| 95 | 
            +
                'WhiteAiZ/autismmixSDXL_autismmixConfetti_diffusers',
         | 
| 96 | 
            +
                'kitty7779/ponyDiffusionV6XL',
         | 
| 97 | 
            +
                'GraydientPlatformAPI/aniverse-pony',
         | 
| 98 | 
            +
                'John6666/ras-real-anime-screencap-v1-sdxl',
         | 
| 99 | 
            +
                'John6666/duchaiten-pony-xl-no-score-v60-sdxl',
         | 
| 100 | 
            +
                'John6666/mistoon-anime-ponyalpha-sdxl',
         | 
| 101 | 
            +
                'John6666/mistoon-xl-copper-v20fast-sdxl',
         | 
| 102 | 
            +
                'John6666/ebara-mfcg-pony-mix-v12-sdxl',
         | 
| 103 | 
            +
                'John6666/t-ponynai3-v51-sdxl',
         | 
| 104 | 
            +
                'John6666/t-ponynai3-v65-sdxl',
         | 
| 105 | 
            +
                'John6666/prefect-pony-xl-v3-sdxl',
         | 
| 106 | 
            +
                'John6666/prefect-pony-xl-v4-sdxl',
         | 
| 107 | 
            +
                'John6666/mala-anime-mix-nsfw-pony-xl-v5-sdxl',
         | 
| 108 | 
            +
                'John6666/wai-ani-nsfw-ponyxl-v10-sdxl',
         | 
| 109 | 
            +
                'John6666/wai-real-mix-v11-sdxl',
         | 
| 110 | 
            +
                'John6666/wai-shuffle-pdxl-v2-sdxl',
         | 
| 111 | 
            +
                'John6666/wai-c-v6-sdxl',
         | 
| 112 | 
            +
                'John6666/iniverse-mix-xl-sfwnsfw-pony-guofeng-v43-sdxl',
         | 
| 113 | 
            +
                'John6666/sifw-annihilation-xl-v2-sdxl',
         | 
| 114 | 
            +
                'John6666/photo-realistic-pony-v5-sdxl',
         | 
| 115 | 
            +
                'John6666/pony-realism-v21main-sdxl',
         | 
| 116 | 
            +
                'John6666/pony-realism-v22main-sdxl',
         | 
| 117 | 
            +
                'John6666/cyberrealistic-pony-v63-sdxl',
         | 
| 118 | 
            +
                'John6666/cyberrealistic-pony-v64-sdxl',
         | 
| 119 | 
            +
                'John6666/cyberrealistic-pony-v65-sdxl',
         | 
| 120 | 
            +
                'John6666/cyberrealistic-pony-v7-sdxl',
         | 
| 121 | 
            +
                'GraydientPlatformAPI/realcartoon-pony-diffusion',
         | 
| 122 | 
            +
                'John6666/nova-anime-xl-pony-v5-sdxl',
         | 
| 123 | 
            +
                'John6666/autismmix-sdxl-autismmix-pony-sdxl',
         | 
| 124 | 
            +
                'John6666/aimz-dream-real-pony-mix-v3-sdxl',
         | 
| 125 | 
            +
                'John6666/prefectious-xl-nsfw-v10-sdxl',
         | 
| 126 | 
            +
                'GraydientPlatformAPI/iniverseponyRealGuofeng49',
         | 
| 127 | 
            +
                'John6666/duchaiten-pony-real-v11fix-sdxl',
         | 
| 128 | 
            +
                'John6666/duchaiten-pony-real-v20-sdxl',
         | 
| 129 | 
            +
                'John6666/duchaiten-pony-xl-no-score-v70-sdxl',
         | 
| 130 | 
            +
                'Spestly/OdysseyXL-3.0',
         | 
| 131 | 
            +
                'Spestly/OdysseyXL-4.0',
         | 
| 132 | 
            +
                'KBlueLeaf/Kohaku-XL-Zeta',
         | 
| 133 | 
            +
                'cagliostrolab/animagine-xl-3.1',
         | 
| 134 | 
            +
                'yodayo-ai/kivotos-xl-2.0',
         | 
| 135 | 
            +
                'yodayo-ai/holodayo-xl-2.1',
         | 
| 136 | 
            +
                'yodayo-ai/clandestine-xl-1.0',
         | 
| 137 | 
            +
                'digiplay/majicMIX_sombre_v2',
         | 
| 138 | 
            +
                'digiplay/majicMIX_realistic_v6',
         | 
| 139 | 
            +
                'digiplay/majicMIX_realistic_v7',
         | 
| 140 | 
            +
                'digiplay/DreamShaper_8',
         | 
| 141 | 
            +
                'digiplay/BeautifulArt_v1',
         | 
| 142 | 
            +
                'digiplay/DarkSushi2.5D_v1',
         | 
| 143 | 
            +
                'digiplay/darkphoenix3D_v1.1',
         | 
| 144 | 
            +
                'digiplay/BeenYouLiteL11_diffusers',
         | 
| 145 | 
            +
                'GraydientPlatformAPI/rev-animated2',
         | 
| 146 | 
            +
                'myxlmynx/cyberrealistic_classic40',
         | 
| 147 | 
            +
                'GraydientPlatformAPI/cyberreal6',
         | 
| 148 | 
            +
                'GraydientPlatformAPI/cyberreal5',
         | 
| 149 | 
            +
                'youknownothing/deliberate-v6',
         | 
| 150 | 
            +
                'GraydientPlatformAPI/deliberate-cyber3',
         | 
| 151 | 
            +
                'GraydientPlatformAPI/picx-real',
         | 
| 152 | 
            +
                'GraydientPlatformAPI/perfectworld6',
         | 
| 153 | 
            +
                'emilianJR/epiCRealism',
         | 
| 154 | 
            +
                'votepurchase/counterfeitV30_v30',
         | 
| 155 | 
            +
                'votepurchase/ChilloutMix',
         | 
| 156 | 
            +
                'Meina/MeinaMix_V11',
         | 
| 157 | 
            +
                'Meina/MeinaUnreal_V5',
         | 
| 158 | 
            +
                'Meina/MeinaPastel_V7',
         | 
| 159 | 
            +
                'GraydientPlatformAPI/realcartoon3d-17',
         | 
| 160 | 
            +
                'GraydientPlatformAPI/realcartoon-pixar11',
         | 
| 161 | 
            +
                'GraydientPlatformAPI/realcartoon-real17',
         | 
| 162 | 
            +
                'nitrosocke/Ghibli-Diffusion',
         | 
| 163 | 
            +
            ]
         | 
| 164 | 
            +
             | 
| 165 | 
            +
            DIFFUSERS_FORMAT_LORAS = [
         | 
| 166 | 
            +
                "nerijs/animation2k-flux",
         | 
| 167 | 
            +
                "XLabs-AI/flux-RealismLora",
         | 
| 168 | 
            +
                "Shakker-Labs/FLUX.1-dev-LoRA-Logo-Design",
         | 
| 169 | 
            +
            ]
         | 
| 170 | 
            +
             | 
| 171 | 
            +
            DOWNLOAD_EMBEDS = [
         | 
| 172 | 
            +
                'https://huggingface.co/datasets/Nerfgun3/bad_prompt/blob/main/bad_prompt_version2.pt',
         | 
| 173 | 
            +
                # 'https://huggingface.co/embed/negative/resolve/main/EasyNegativeV2.safetensors',
         | 
| 174 | 
            +
                # 'https://huggingface.co/embed/negative/resolve/main/bad-hands-5.pt',
         | 
| 175 | 
            +
            ]
         | 
| 176 | 
            +
             | 
| 177 | 
            +
            CIVITAI_API_KEY = os.environ.get("CIVITAI_API_KEY")
         | 
| 178 | 
            +
            HF_TOKEN = os.environ.get("HF_READ_TOKEN")
         | 
| 179 | 
            +
             | 
| 180 | 
            +
            DIRECTORY_MODELS = 'models'
         | 
| 181 | 
            +
            DIRECTORY_LORAS = 'loras'
         | 
| 182 | 
            +
            DIRECTORY_VAES = 'vaes'
         | 
| 183 | 
            +
            DIRECTORY_EMBEDS = 'embedings'
         | 
| 184 | 
            +
            DIRECTORY_UPSCALERS = 'upscalers'
         | 
| 185 | 
            +
             | 
| 186 | 
            +
            CACHE_HF = "/home/user/.cache/huggingface/hub/"
         | 
| 187 | 
            +
            STORAGE_ROOT = "/home/user/"
         | 
| 188 | 
            +
             | 
| 189 | 
            +
            TASK_STABLEPY = {
         | 
| 190 | 
            +
                'txt2img': 'txt2img',
         | 
| 191 | 
            +
                'img2img': 'img2img',
         | 
| 192 | 
            +
                'inpaint': 'inpaint',
         | 
| 193 | 
            +
                # 'canny T2I Adapter': 'sdxl_canny_t2i',  # NO HAVE STEP CALLBACK PARAMETERS SO NOT WORKS WITH DIFFUSERS 0.29.0
         | 
| 194 | 
            +
                # 'sketch  T2I Adapter': 'sdxl_sketch_t2i',
         | 
| 195 | 
            +
                # 'lineart  T2I Adapter': 'sdxl_lineart_t2i',
         | 
| 196 | 
            +
                # 'depth-midas  T2I Adapter': 'sdxl_depth-midas_t2i',
         | 
| 197 | 
            +
                # 'openpose  T2I Adapter': 'sdxl_openpose_t2i',
         | 
| 198 | 
            +
                'openpose ControlNet': 'openpose',
         | 
| 199 | 
            +
                'canny ControlNet': 'canny',
         | 
| 200 | 
            +
                'mlsd ControlNet': 'mlsd',
         | 
| 201 | 
            +
                'scribble ControlNet': 'scribble',
         | 
| 202 | 
            +
                'softedge ControlNet': 'softedge',
         | 
| 203 | 
            +
                'segmentation ControlNet': 'segmentation',
         | 
| 204 | 
            +
                'depth ControlNet': 'depth',
         | 
| 205 | 
            +
                'normalbae ControlNet': 'normalbae',
         | 
| 206 | 
            +
                'lineart ControlNet': 'lineart',
         | 
| 207 | 
            +
                'lineart_anime ControlNet': 'lineart_anime',
         | 
| 208 | 
            +
                'shuffle ControlNet': 'shuffle',
         | 
| 209 | 
            +
                'ip2p ControlNet': 'ip2p',
         | 
| 210 | 
            +
                'optical pattern ControlNet': 'pattern',
         | 
| 211 | 
            +
                'recolor ControlNet': 'recolor',
         | 
| 212 | 
            +
                'tile ControlNet': 'tile',
         | 
| 213 | 
            +
                'repaint ControlNet': 'repaint',
         | 
| 214 | 
            +
            }
         | 
| 215 | 
            +
             | 
| 216 | 
            +
            TASK_MODEL_LIST = list(TASK_STABLEPY.keys())
         | 
| 217 | 
            +
             | 
| 218 | 
            +
            UPSCALER_DICT_GUI = {
         | 
| 219 | 
            +
                None: None,
         | 
| 220 | 
            +
                **{bu: bu for bu in ALL_BUILTIN_UPSCALERS if bu not in ["HAT x4", "DAT x4", "DAT x3", "DAT x2", "SwinIR 4x"]},
         | 
| 221 | 
            +
                # "RealESRGAN_x4plus": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth",
         | 
| 222 | 
            +
                "RealESRNet_x4plus": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/RealESRNet_x4plus.pth",
         | 
| 223 | 
            +
                # "RealESRGAN_x4plus_anime_6B": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth",
         | 
| 224 | 
            +
                # "RealESRGAN_x2plus": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth",
         | 
| 225 | 
            +
                # "realesr-animevideov3": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-animevideov3.pth",
         | 
| 226 | 
            +
                # "realesr-general-x4v3": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth",
         | 
| 227 | 
            +
                # "realesr-general-wdn-x4v3": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-wdn-x4v3.pth",
         | 
| 228 | 
            +
                "4x-UltraSharp": "https://huggingface.co/Shandypur/ESRGAN-4x-UltraSharp/resolve/main/4x-UltraSharp.pth",
         | 
| 229 | 
            +
                "4x_foolhardy_Remacri": "https://huggingface.co/FacehugmanIII/4x_foolhardy_Remacri/resolve/main/4x_foolhardy_Remacri.pth",
         | 
| 230 | 
            +
                "Remacri4xExtraSmoother": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/Remacri%204x%20ExtraSmoother.pth",
         | 
| 231 | 
            +
                "AnimeSharp4x": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/AnimeSharp%204x.pth",
         | 
| 232 | 
            +
                "lollypop": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/lollypop.pth",
         | 
| 233 | 
            +
                "RealisticRescaler4x": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/RealisticRescaler%204x.pth",
         | 
| 234 | 
            +
                "NickelbackFS4x": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/NickelbackFS%204x.pth"
         | 
| 235 | 
            +
            }
         | 
| 236 | 
            +
             | 
| 237 | 
            +
            UPSCALER_KEYS = list(UPSCALER_DICT_GUI.keys())
         | 
| 238 | 
            +
             | 
| 239 | 
            +
            DIFFUSERS_CONTROLNET_MODEL = [
         | 
| 240 | 
            +
                "Automatic",
         | 
| 241 | 
            +
             | 
| 242 | 
            +
                "brad-twinkl/controlnet-union-sdxl-1.0-promax",
         | 
| 243 | 
            +
                "xinsir/controlnet-union-sdxl-1.0",
         | 
| 244 | 
            +
                "xinsir/anime-painter",
         | 
| 245 | 
            +
                "Eugeoter/noob-sdxl-controlnet-canny",
         | 
| 246 | 
            +
                "Eugeoter/noob-sdxl-controlnet-lineart_anime",
         | 
| 247 | 
            +
                "Eugeoter/noob-sdxl-controlnet-depth",
         | 
| 248 | 
            +
                "Eugeoter/noob-sdxl-controlnet-normal",
         | 
| 249 | 
            +
                "Eugeoter/noob-sdxl-controlnet-softedge_hed",
         | 
| 250 | 
            +
                "Eugeoter/noob-sdxl-controlnet-scribble_pidinet",
         | 
| 251 | 
            +
                "Eugeoter/noob-sdxl-controlnet-scribble_hed",
         | 
| 252 | 
            +
                "Eugeoter/noob-sdxl-controlnet-manga_line",
         | 
| 253 | 
            +
                "Eugeoter/noob-sdxl-controlnet-lineart_realistic",
         | 
| 254 | 
            +
                "Eugeoter/noob-sdxl-controlnet-depth_midas-v1-1",
         | 
| 255 | 
            +
                "dimitribarbot/controlnet-openpose-sdxl-1.0-safetensors",
         | 
| 256 | 
            +
                "r3gm/controlnet-openpose-sdxl-1.0-fp16",
         | 
| 257 | 
            +
                "r3gm/controlnet-canny-scribble-integrated-sdxl-v2-fp16",
         | 
| 258 | 
            +
                "r3gm/controlnet-union-sdxl-1.0-fp16",
         | 
| 259 | 
            +
                "r3gm/controlnet-lineart-anime-sdxl-fp16",
         | 
| 260 | 
            +
                "r3gm/control_v1p_sdxl_qrcode_monster_fp16",
         | 
| 261 | 
            +
                "r3gm/controlnet-tile-sdxl-1.0-fp16",
         | 
| 262 | 
            +
                "r3gm/controlnet-recolor-sdxl-fp16",
         | 
| 263 | 
            +
                "r3gm/controlnet-openpose-twins-sdxl-1.0-fp16",
         | 
| 264 | 
            +
                "r3gm/controlnet-qr-pattern-sdxl-fp16",
         | 
| 265 | 
            +
                "Yakonrus/SDXL_Controlnet_Tile_Realistic_v2",
         | 
| 266 | 
            +
                "TheMistoAI/MistoLine",
         | 
| 267 | 
            +
                "briaai/BRIA-2.3-ControlNet-Recoloring",
         | 
| 268 | 
            +
                "briaai/BRIA-2.3-ControlNet-Canny",
         | 
| 269 | 
            +
             | 
| 270 | 
            +
                "lllyasviel/control_v11p_sd15_openpose",
         | 
| 271 | 
            +
                "lllyasviel/control_v11p_sd15_canny",
         | 
| 272 | 
            +
                "lllyasviel/control_v11p_sd15_mlsd",
         | 
| 273 | 
            +
                "lllyasviel/control_v11p_sd15_scribble",
         | 
| 274 | 
            +
                "lllyasviel/control_v11p_sd15_softedge",
         | 
| 275 | 
            +
                "lllyasviel/control_v11p_sd15_seg",
         | 
| 276 | 
            +
                "lllyasviel/control_v11f1p_sd15_depth",
         | 
| 277 | 
            +
                "lllyasviel/control_v11p_sd15_normalbae",
         | 
| 278 | 
            +
                "lllyasviel/control_v11p_sd15_lineart",
         | 
| 279 | 
            +
                "lllyasviel/control_v11p_sd15s2_lineart_anime",
         | 
| 280 | 
            +
                "lllyasviel/control_v11e_sd15_shuffle",
         | 
| 281 | 
            +
                "lllyasviel/control_v11e_sd15_ip2p",
         | 
| 282 | 
            +
                "lllyasviel/control_v11p_sd15_inpaint",
         | 
| 283 | 
            +
                "monster-labs/control_v1p_sd15_qrcode_monster",
         | 
| 284 | 
            +
                "lllyasviel/control_v11f1e_sd15_tile",
         | 
| 285 | 
            +
                "latentcat/control_v1p_sd15_brightness",
         | 
| 286 | 
            +
                "yuanqiuye/qrcode_controlnet_v3",
         | 
| 287 | 
            +
             | 
| 288 | 
            +
                "Shakker-Labs/FLUX.1-dev-ControlNet-Union-Pro",
         | 
| 289 | 
            +
                # "Shakker-Labs/FLUX.1-dev-ControlNet-Pose",
         | 
| 290 | 
            +
                # "Shakker-Labs/FLUX.1-dev-ControlNet-Depth",
         | 
| 291 | 
            +
                # "jasperai/Flux.1-dev-Controlnet-Upscaler",
         | 
| 292 | 
            +
                # "jasperai/Flux.1-dev-Controlnet-Depth",
         | 
| 293 | 
            +
                # "jasperai/Flux.1-dev-Controlnet-Surface-Normals",
         | 
| 294 | 
            +
                # "XLabs-AI/flux-controlnet-canny-diffusers",
         | 
| 295 | 
            +
                # "XLabs-AI/flux-controlnet-hed-diffusers",
         | 
| 296 | 
            +
                # "XLabs-AI/flux-controlnet-depth-diffusers",
         | 
| 297 | 
            +
                # "InstantX/FLUX.1-dev-Controlnet-Union",
         | 
| 298 | 
            +
                # "InstantX/FLUX.1-dev-Controlnet-Canny",
         | 
| 299 | 
            +
            ]
         | 
| 300 | 
            +
             | 
| 301 | 
            +
            PROMPT_W_OPTIONS = [
         | 
| 302 | 
            +
                ("Compel format: (word)weight", "Compel"),
         | 
| 303 | 
            +
                ("Classic format: (word:weight)", "Classic"),
         | 
| 304 | 
            +
                ("Classic-original format: (word:weight)", "Classic-original"),
         | 
| 305 | 
            +
                ("Classic-no_norm format: (word:weight)", "Classic-no_norm"),
         | 
| 306 | 
            +
                ("Classic-sd_embed format: (word:weight)", "Classic-sd_embed"),
         | 
| 307 | 
            +
                ("Classic-ignore", "Classic-ignore"),
         | 
| 308 | 
            +
                ("None", "None"),
         | 
| 309 | 
            +
            ]
         | 
| 310 | 
            +
             | 
| 311 | 
            +
            WARNING_MSG_VAE = (
         | 
| 312 | 
            +
                "Use the right VAE for your model to maintain image quality. The wrong"
         | 
| 313 | 
            +
                " VAE can lead to poor results, like blurriness in the generated images."
         | 
| 314 | 
            +
            )
         | 
| 315 | 
            +
             | 
| 316 | 
            +
            SDXL_TASK = [k for k, v in TASK_STABLEPY.items() if v in SDXL_TASKS]
         | 
| 317 | 
            +
            SD_TASK = [k for k, v in TASK_STABLEPY.items() if v in SD15_TASKS]
         | 
| 318 | 
            +
            FLUX_TASK = list(TASK_STABLEPY.keys())[:3] + [k for k, v in TASK_STABLEPY.items() if v in FLUX_CN_UNION_MODES.keys()]
         | 
| 319 | 
            +
             | 
| 320 | 
            +
            MODEL_TYPE_TASK = {
         | 
| 321 | 
            +
                "SD 1.5": SD_TASK,
         | 
| 322 | 
            +
                "SDXL": SDXL_TASK,
         | 
| 323 | 
            +
                "FLUX": FLUX_TASK,
         | 
| 324 | 
            +
            }
         | 
| 325 | 
            +
             | 
| 326 | 
            +
            MODEL_TYPE_CLASS = {
         | 
| 327 | 
            +
                "diffusers:StableDiffusionPipeline": "SD 1.5",
         | 
| 328 | 
            +
                "diffusers:StableDiffusionXLPipeline": "SDXL",
         | 
| 329 | 
            +
                "diffusers:FluxPipeline": "FLUX",
         | 
| 330 | 
            +
            }
         | 
| 331 | 
            +
             | 
| 332 | 
            +
            DIFFUSECRAFT_CHECKPOINT_NAME = {
         | 
| 333 | 
            +
                "sd1.5": "SD 1.5",
         | 
| 334 | 
            +
                "sdxl": "SDXL",
         | 
| 335 | 
            +
                "flux-dev": "FLUX",
         | 
| 336 | 
            +
                "flux-schnell": "FLUX",
         | 
| 337 | 
            +
            }
         | 
| 338 | 
            +
             | 
| 339 | 
            +
            POST_PROCESSING_SAMPLER = ["Use same sampler"] + [
         | 
| 340 | 
            +
                name_s for name_s in scheduler_names if "Auto-Loader" not in name_s
         | 
| 341 | 
            +
            ]
         | 
| 342 | 
            +
             | 
| 343 | 
            +
            IP_MODELS = []
         | 
| 344 | 
            +
            ALL_IPA = sorted(set(IP_ADAPTERS_SD + IP_ADAPTERS_SDXL))
         | 
| 345 | 
            +
             | 
| 346 | 
            +
            for origin_name in ALL_IPA:
         | 
| 347 | 
            +
                suffixes = []
         | 
| 348 | 
            +
                if origin_name in IP_ADAPTERS_SD:
         | 
| 349 | 
            +
                    suffixes.append("sd1.5")
         | 
| 350 | 
            +
                if origin_name in IP_ADAPTERS_SDXL:
         | 
| 351 | 
            +
                    suffixes.append("sdxl")
         | 
| 352 | 
            +
                ref_name = f"{origin_name} ({'/'.join(suffixes)})"
         | 
| 353 | 
            +
                IP_MODELS.append((ref_name, origin_name))
         | 
| 354 | 
            +
             | 
| 355 | 
            +
            MODE_IP_OPTIONS = ["original", "style", "layout", "style+layout"]
         | 
| 356 | 
            +
             | 
| 357 | 
            +
            SUBTITLE_GUI = (
         | 
| 358 | 
            +
                "### This demo uses [diffusers](https://github.com/huggingface/diffusers)"
         | 
| 359 | 
            +
                " to perform different tasks in image generation."
         | 
| 360 | 
            +
            )
         | 
| 361 | 
            +
             | 
| 362 | 
            +
            HELP_GUI = (
         | 
| 363 | 
            +
                """### Help:
         | 
| 364 | 
            +
                - The current space runs on a ZERO GPU which is assigned for approximately 60 seconds; Therefore, if you submit expensive tasks, the operation may be canceled upon reaching the maximum allowed time with 'GPU TASK ABORTED'.
         | 
| 365 | 
            +
                - Distorted or strange images often result from high prompt weights, so it's best to use low weights and scales, and consider using Classic variants like 'Classic-original'.
         | 
| 366 | 
            +
                - For better results with Pony Diffusion, try using sampler DPM++ 1s or DPM2 with Compel or Classic prompt weights.
         | 
| 367 | 
            +
                """
         | 
| 368 | 
            +
            )
         | 
| 369 | 
            +
             | 
| 370 | 
            +
            EXAMPLES_GUI_HELP = (
         | 
| 371 | 
            +
                """### The following examples perform specific tasks:
         | 
| 372 | 
            +
                1. Generation with SDXL and upscale
         | 
| 373 | 
            +
                2. Generation with FLUX dev
         | 
| 374 | 
            +
                3. ControlNet Canny SDXL
         | 
| 375 | 
            +
                4. Optical pattern (Optical illusion) SDXL
         | 
| 376 | 
            +
                5. Convert an image to a coloring drawing
         | 
| 377 | 
            +
                6. V prediction model inference
         | 
| 378 | 
            +
                7. V prediction model sd_embed variant inference
         | 
| 379 | 
            +
                8. ControlNet OpenPose SD 1.5 and Latent upscale
         | 
| 380 | 
            +
             | 
| 381 | 
            +
                - Different tasks can be performed, such as img2img or using the IP adapter, to preserve a person's appearance or a specific style based on an image.
         | 
| 382 | 
            +
                """
         | 
| 383 | 
            +
            )
         | 
| 384 | 
            +
             | 
| 385 | 
            +
            EXAMPLES_GUI = [
         | 
| 386 | 
            +
                [
         | 
| 387 | 
            +
                    "splatter paint theme, 1girl, frame center, pretty face, face with artistic paint artwork, feminism, long hair, upper body view, futuristic expression illustrative painted background, origami, stripes, explosive paint splashes behind her, hand on cheek pose, strobe lighting, masterpiece photography creative artwork, golden morning light, highly detailed, masterpiece, best quality, very aesthetic, absurdres",
         | 
| 388 | 
            +
                    "logo, artist name, (worst quality, normal quality), bad-artist, ((bad anatomy)), ((bad hands)), ((bad proportions)), ((duplicate limbs)), ((fused limbs)), ((interlocking fingers)), ((poorly drawn face)), high contrast., score_6, score_5, score_4, lowres, (bad), text, error, fewer, extra, missing, worst quality, jpeg artifacts, low quality, watermark, unfinished, displeasing, oldest, early, chromatic aberration, signature, extra digits, artistic error, username, scan, [abstract]",
         | 
| 389 | 
            +
                    28,
         | 
| 390 | 
            +
                    5.0,
         | 
| 391 | 
            +
                    -1,
         | 
| 392 | 
            +
                    "None",
         | 
| 393 | 
            +
                    0.33,
         | 
| 394 | 
            +
                    "DPM++ 2M SDE",
         | 
| 395 | 
            +
                    1152,
         | 
| 396 | 
            +
                    896,
         | 
| 397 | 
            +
                    "John6666/noobai-xl-nai-xl-epsilonpred10version-sdxl",
         | 
| 398 | 
            +
                    "txt2img",
         | 
| 399 | 
            +
                    "image.webp",  # img conttol
         | 
| 400 | 
            +
                    1024,  # img resolution
         | 
| 401 | 
            +
                    0.35,  # strength
         | 
| 402 | 
            +
                    1.0,  # cn scale
         | 
| 403 | 
            +
                    0.0,  # cn start
         | 
| 404 | 
            +
                    1.0,  # cn end
         | 
| 405 | 
            +
                    "Classic-no_norm",
         | 
| 406 | 
            +
                    "Nearest",
         | 
| 407 | 
            +
                    45,
         | 
| 408 | 
            +
                    False,
         | 
| 409 | 
            +
                ],
         | 
| 410 | 
            +
                [
         | 
| 411 | 
            +
                    "a digital illustration of a movie poster titled 'Finding Emo', finding nemo parody poster, featuring a depressed cartoon clownfish with black emo hair, eyeliner, and piercings, bored expression, swimming in a dark underwater scene, in the background, movie title in a dripping, grungy font, moody blue and purple color palette",
         | 
| 412 | 
            +
                    "",
         | 
| 413 | 
            +
                    24,
         | 
| 414 | 
            +
                    3.5,
         | 
| 415 | 
            +
                    -1,
         | 
| 416 | 
            +
                    "None",
         | 
| 417 | 
            +
                    0.33,
         | 
| 418 | 
            +
                    "FlowMatch Euler",
         | 
| 419 | 
            +
                    1152,
         | 
| 420 | 
            +
                    896,
         | 
| 421 | 
            +
                    "black-forest-labs/FLUX.1-dev",
         | 
| 422 | 
            +
                    "txt2img",
         | 
| 423 | 
            +
                    None,  # img conttol
         | 
| 424 | 
            +
                    1024,  # img resolution
         | 
| 425 | 
            +
                    0.35,  # strength
         | 
| 426 | 
            +
                    1.0,  # cn scale
         | 
| 427 | 
            +
                    0.0,  # cn start
         | 
| 428 | 
            +
                    1.0,  # cn end
         | 
| 429 | 
            +
                    "Classic",
         | 
| 430 | 
            +
                    None,
         | 
| 431 | 
            +
                    70,
         | 
| 432 | 
            +
                    True,
         | 
| 433 | 
            +
                ],
         | 
| 434 | 
            +
                [
         | 
| 435 | 
            +
                    "((masterpiece)), best quality, blonde disco girl, detailed face, realistic face, realistic hair, dynamic pose, pink pvc, intergalactic disco background, pastel lights, dynamic contrast, airbrush, fine detail, 70s vibe, midriff",
         | 
| 436 | 
            +
                    "(worst quality:1.2), (bad quality:1.2), (poor quality:1.2), (missing fingers:1.2), bad-artist-anime, bad-artist, bad-picture-chill-75v",
         | 
| 437 | 
            +
                    48,
         | 
| 438 | 
            +
                    3.5,
         | 
| 439 | 
            +
                    -1,
         | 
| 440 | 
            +
                    "None",
         | 
| 441 | 
            +
                    0.33,
         | 
| 442 | 
            +
                    "DPM++ 2M SDE Ef",
         | 
| 443 | 
            +
                    1024,
         | 
| 444 | 
            +
                    1024,
         | 
| 445 | 
            +
                    "John6666/epicrealism-xl-v10kiss2-sdxl",
         | 
| 446 | 
            +
                    "canny ControlNet",
         | 
| 447 | 
            +
                    "image.webp",  # img conttol
         | 
| 448 | 
            +
                    1024,  # img resolution
         | 
| 449 | 
            +
                    0.35,  # strength
         | 
| 450 | 
            +
                    1.0,  # cn scale
         | 
| 451 | 
            +
                    0.0,  # cn start
         | 
| 452 | 
            +
                    1.0,  # cn end
         | 
| 453 | 
            +
                    "Classic",
         | 
| 454 | 
            +
                    None,
         | 
| 455 | 
            +
                    44,
         | 
| 456 | 
            +
                    False,
         | 
| 457 | 
            +
                ],
         | 
| 458 | 
            +
                [
         | 
| 459 | 
            +
                    "cinematic scenery old city ruins",
         | 
| 460 | 
            +
                    "(worst quality, low quality, illustration, 3d, 2d, painting, cartoons, sketch), (illustration, 3d, 2d, painting, cartoons, sketch, blurry, film grain, noise), (low quality, worst quality:1.2)",
         | 
| 461 | 
            +
                    50,
         | 
| 462 | 
            +
                    4.0,
         | 
| 463 | 
            +
                    -1,
         | 
| 464 | 
            +
                    "None",
         | 
| 465 | 
            +
                    0.33,
         | 
| 466 | 
            +
                    "Euler a",
         | 
| 467 | 
            +
                    1024,
         | 
| 468 | 
            +
                    1024,
         | 
| 469 | 
            +
                    "SG161222/RealVisXL_V5.0",
         | 
| 470 | 
            +
                    "optical pattern ControlNet",
         | 
| 471 | 
            +
                    "spiral_no_transparent.png",  # img conttol
         | 
| 472 | 
            +
                    1024,  # img resolution
         | 
| 473 | 
            +
                    0.35,  # strength
         | 
| 474 | 
            +
                    1.0,  # cn scale
         | 
| 475 | 
            +
                    0.05,  # cn start
         | 
| 476 | 
            +
                    0.8,  # cn end
         | 
| 477 | 
            +
                    "Classic",
         | 
| 478 | 
            +
                    None,
         | 
| 479 | 
            +
                    35,
         | 
| 480 | 
            +
                    False,
         | 
| 481 | 
            +
                ],
         | 
| 482 | 
            +
                [
         | 
| 483 | 
            +
                    "black and white, line art, coloring drawing, clean line art, black strokes, no background, white, black, free lines, black scribbles, on paper, A blend of comic book art and lineart full of black and white color, masterpiece, high-resolution, trending on Pixiv fan box, palette knife, brush strokes, two-dimensional, planar vector, T-shirt design, stickers, and T-shirt design, vector art, fantasy art, Adobe Illustrator, hand-painted, digital painting, low polygon, soft lighting, aerial view, isometric style, retro aesthetics, 8K resolution, black sketch lines, monochrome, invert color",
         | 
| 484 | 
            +
                    "color, red, green, yellow, colored, duplicate, blurry, abstract, disfigured, deformed, animated, toy, figure, framed, 3d, bad art, poorly drawn, extra limbs, close up, b&w, weird colors, blurry, watermark, blur haze, 2 heads, long neck, watermark, elongated body, cropped image, out of frame, draft, deformed hands, twisted fingers, double image, malformed hands, multiple heads, extra limb, ugly, poorly drawn hands, missing limb, cut-off, over satured, grain, lowères, bad anatomy, poorly drawn face, mutation, mutated, floating limbs, disconnected limbs, out of focus, long body, disgusting, extra fingers, groos proportions, missing arms, mutated hands, cloned face, missing legs, ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, extra limbs, disfigured, deformed, body out of frame, blurry, bad anatomy, blurred, watermark, grainy, signature, cut off, draft, deformed, blurry, bad anatomy, disfigured, poorly drawn face, mutation, bluelish, blue",
         | 
| 485 | 
            +
                    20,
         | 
| 486 | 
            +
                    4.0,
         | 
| 487 | 
            +
                    -1,
         | 
| 488 | 
            +
                    "loras/Coloring_book_-_LineArt.safetensors",
         | 
| 489 | 
            +
                    1.0,
         | 
| 490 | 
            +
                    "DPM++ 2M SDE",
         | 
| 491 | 
            +
                    1024,
         | 
| 492 | 
            +
                    1024,
         | 
| 493 | 
            +
                    "eienmojiki/Anything-XL",
         | 
| 494 | 
            +
                    "lineart ControlNet",
         | 
| 495 | 
            +
                    "color_image.png",  # img conttol
         | 
| 496 | 
            +
                    896,  # img resolution
         | 
| 497 | 
            +
                    0.35,  # strength
         | 
| 498 | 
            +
                    1.0,  # cn scale
         | 
| 499 | 
            +
                    0.0,  # cn start
         | 
| 500 | 
            +
                    1.0,  # cn end
         | 
| 501 | 
            +
                    "Compel",
         | 
| 502 | 
            +
                    None,
         | 
| 503 | 
            +
                    35,
         | 
| 504 | 
            +
                    False,
         | 
| 505 | 
            +
                ],
         | 
| 506 | 
            +
                [
         | 
| 507 | 
            +
                    "[mochizuki_shiina], [syuri22], newest, reimu, solo, outdoors, water, flower, lantern",
         | 
| 508 | 
            +
                    "worst quality, normal quality, old, sketch,",
         | 
| 509 | 
            +
                    28,
         | 
| 510 | 
            +
                    7.0,
         | 
| 511 | 
            +
                    -1,
         | 
| 512 | 
            +
                    "None",
         | 
| 513 | 
            +
                    0.33,
         | 
| 514 | 
            +
                    "DPM 3M Ef",
         | 
| 515 | 
            +
                    1600,
         | 
| 516 | 
            +
                    1024,
         | 
| 517 | 
            +
                    "Laxhar/noobai-XL-Vpred-1.0",
         | 
| 518 | 
            +
                    "txt2img",
         | 
| 519 | 
            +
                    "color_image.png",  # img conttol
         | 
| 520 | 
            +
                    1024,  # img resolution
         | 
| 521 | 
            +
                    0.35,  # strength
         | 
| 522 | 
            +
                    1.0,  # cn scale
         | 
| 523 | 
            +
                    0.0,  # cn start
         | 
| 524 | 
            +
                    1.0,  # cn end
         | 
| 525 | 
            +
                    "Classic",
         | 
| 526 | 
            +
                    None,
         | 
| 527 | 
            +
                    30,
         | 
| 528 | 
            +
                    False,
         | 
| 529 | 
            +
                ],
         | 
| 530 | 
            +
                [
         | 
| 531 | 
            +
                    "[mochizuki_shiina], [syuri22], newest, multiple girls, 2girls, earrings, jewelry, gloves, purple eyes, black hair, looking at viewer, nail polish, hat, smile, open mouth, fingerless gloves, sleeveless, :d, upper body, blue eyes, closed mouth, black gloves, hands up, long hair, shirt, bare shoulders, white headwear, blush, black headwear, blue nails, upper teeth only, short hair, white gloves, white shirt, teeth, rabbit hat, star earrings, purple nails, pink hair, detached sleeves, fingernails, fake animal ears, animal hat, sleeves past wrists, black shirt, medium hair, fur trim, sleeveless shirt, turtleneck, long sleeves, rabbit ears, star \\(symbol\\)",
         | 
| 532 | 
            +
                    "worst quality, normal quality, old, sketch,",
         | 
| 533 | 
            +
                    28,
         | 
| 534 | 
            +
                    7.0,
         | 
| 535 | 
            +
                    -1,
         | 
| 536 | 
            +
                    "None",
         | 
| 537 | 
            +
                    0.33,
         | 
| 538 | 
            +
                    "DPM 3M Ef",
         | 
| 539 | 
            +
                    1600,
         | 
| 540 | 
            +
                    1024,
         | 
| 541 | 
            +
                    "Laxhar/noobai-XL-Vpred-1.0",
         | 
| 542 | 
            +
                    "txt2img",
         | 
| 543 | 
            +
                    "color_image.png",  # img conttol
         | 
| 544 | 
            +
                    1024,  # img resolution
         | 
| 545 | 
            +
                    0.35,  # strength
         | 
| 546 | 
            +
                    1.0,  # cn scale
         | 
| 547 | 
            +
                    0.0,  # cn start
         | 
| 548 | 
            +
                    1.0,  # cn end
         | 
| 549 | 
            +
                    "Classic-sd_embed",
         | 
| 550 | 
            +
                    None,
         | 
| 551 | 
            +
                    30,
         | 
| 552 | 
            +
                    False,
         | 
| 553 | 
            +
                ],
         | 
| 554 | 
            +
                [
         | 
| 555 | 
            +
                    "1girl,face,curly hair,red hair,white background,",
         | 
| 556 | 
            +
                    "(worst quality:2),(low quality:2),(normal quality:2),lowres,watermark,",
         | 
| 557 | 
            +
                    38,
         | 
| 558 | 
            +
                    5.0,
         | 
| 559 | 
            +
                    -1,
         | 
| 560 | 
            +
                    "None",
         | 
| 561 | 
            +
                    0.33,
         | 
| 562 | 
            +
                    "DPM++ 2M SDE",
         | 
| 563 | 
            +
                    512,
         | 
| 564 | 
            +
                    512,
         | 
| 565 | 
            +
                    "digiplay/majicMIX_realistic_v7",
         | 
| 566 | 
            +
                    "openpose ControlNet",
         | 
| 567 | 
            +
                    "image.webp",  # img conttol
         | 
| 568 | 
            +
                    1024,  # img resolution
         | 
| 569 | 
            +
                    0.35,  # strength
         | 
| 570 | 
            +
                    1.0,  # cn scale
         | 
| 571 | 
            +
                    0.0,  # cn start
         | 
| 572 | 
            +
                    0.9,  # cn end
         | 
| 573 | 
            +
                    "Classic-original",
         | 
| 574 | 
            +
                    "Latent (antialiased)",
         | 
| 575 | 
            +
                    46,
         | 
| 576 | 
            +
                    False,
         | 
| 577 | 
            +
                ],
         | 
| 578 | 
            +
            ]
         | 
| 579 | 
            +
             | 
| 580 | 
            +
            RESOURCES = (
         | 
| 581 | 
            +
                """### Resources
         | 
| 582 | 
            +
                - John6666's space has some great features you might find helpful [link](https://huggingface.co/spaces/John6666/DiffuseCraftMod).
         | 
| 583 | 
            +
                - You can also try the image generator in Colab’s free tier, which provides free GPU [link](https://github.com/R3gm/SD_diffusers_interactive).
         | 
| 584 | 
            +
                """
         | 
| 585 | 
            +
            )
         | 
    	
        image.webp
    ADDED
    
    |   | 
    	
        image_processor.py
    ADDED
    
    | @@ -0,0 +1,130 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            import spaces
         | 
| 2 | 
            +
            import gradio as gr
         | 
| 3 | 
            +
            from stablepy import Preprocessor
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            PREPROCESSOR_TASKS_LIST = [
         | 
| 6 | 
            +
                "Canny",
         | 
| 7 | 
            +
                "Openpose",
         | 
| 8 | 
            +
                "DPT",
         | 
| 9 | 
            +
                "Midas",
         | 
| 10 | 
            +
                "ZoeDepth",
         | 
| 11 | 
            +
                "DepthAnything",
         | 
| 12 | 
            +
                "HED",
         | 
| 13 | 
            +
                "PidiNet",
         | 
| 14 | 
            +
                "TEED",
         | 
| 15 | 
            +
                "Lineart",
         | 
| 16 | 
            +
                "LineartAnime",
         | 
| 17 | 
            +
                "Anyline",
         | 
| 18 | 
            +
                "Lineart standard",
         | 
| 19 | 
            +
                "SegFormer",
         | 
| 20 | 
            +
                "UPerNet",
         | 
| 21 | 
            +
                "ContentShuffle",
         | 
| 22 | 
            +
                "Recolor",
         | 
| 23 | 
            +
                "Blur",
         | 
| 24 | 
            +
                "MLSD",
         | 
| 25 | 
            +
                "NormalBae",
         | 
| 26 | 
            +
            ]
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            preprocessor = Preprocessor()
         | 
| 29 | 
            +
             | 
| 30 | 
            +
             | 
| 31 | 
            +
            def process_inputs(
         | 
| 32 | 
            +
                image,
         | 
| 33 | 
            +
                name,
         | 
| 34 | 
            +
                resolution,
         | 
| 35 | 
            +
                precessor_resolution,
         | 
| 36 | 
            +
                low_threshold,
         | 
| 37 | 
            +
                high_threshold,
         | 
| 38 | 
            +
                value_threshod,
         | 
| 39 | 
            +
                distance_threshold,
         | 
| 40 | 
            +
                recolor_mode,
         | 
| 41 | 
            +
                recolor_gamma_correction,
         | 
| 42 | 
            +
                blur_k_size,
         | 
| 43 | 
            +
                pre_openpose_extra,
         | 
| 44 | 
            +
                hed_scribble,
         | 
| 45 | 
            +
                pre_pidinet_safe,
         | 
| 46 | 
            +
                pre_lineart_coarse,
         | 
| 47 | 
            +
                use_cuda,
         | 
| 48 | 
            +
            ):
         | 
| 49 | 
            +
                if not image:
         | 
| 50 | 
            +
                    raise ValueError("To use this, simply upload an image.")
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                preprocessor.load(name, False)
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                params = dict(
         | 
| 55 | 
            +
                    image_resolution=resolution,
         | 
| 56 | 
            +
                    detect_resolution=precessor_resolution,
         | 
| 57 | 
            +
                    low_threshold=low_threshold,
         | 
| 58 | 
            +
                    high_threshold=high_threshold,
         | 
| 59 | 
            +
                    thr_v=value_threshod,
         | 
| 60 | 
            +
                    thr_d=distance_threshold,
         | 
| 61 | 
            +
                    mode=recolor_mode,
         | 
| 62 | 
            +
                    gamma_correction=recolor_gamma_correction,
         | 
| 63 | 
            +
                    blur_sigma=blur_k_size,
         | 
| 64 | 
            +
                    hand_and_face=pre_openpose_extra,
         | 
| 65 | 
            +
                    scribble=hed_scribble,
         | 
| 66 | 
            +
                    safe=pre_pidinet_safe,
         | 
| 67 | 
            +
                    coarse=pre_lineart_coarse,
         | 
| 68 | 
            +
                )
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                if use_cuda:
         | 
| 71 | 
            +
                    @spaces.GPU(duration=15)
         | 
| 72 | 
            +
                    def wrapped_func():
         | 
| 73 | 
            +
                        preprocessor.to("cuda")
         | 
| 74 | 
            +
                        return preprocessor(image, **params)
         | 
| 75 | 
            +
                    return wrapped_func()
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                return preprocessor(image, **params)
         | 
| 78 | 
            +
             | 
| 79 | 
            +
             | 
| 80 | 
            +
            def preprocessor_tab():
         | 
| 81 | 
            +
                with gr.Row():
         | 
| 82 | 
            +
                    with gr.Column():
         | 
| 83 | 
            +
                        pre_image = gr.Image(label="Image", type="pil", sources=["upload"])
         | 
| 84 | 
            +
                        pre_options = gr.Dropdown(label="Preprocessor", choices=PREPROCESSOR_TASKS_LIST, value=PREPROCESSOR_TASKS_LIST[0])
         | 
| 85 | 
            +
                        pre_img_resolution = gr.Slider(
         | 
| 86 | 
            +
                            minimum=64, maximum=4096, step=64, value=1024, label="Image Resolution",
         | 
| 87 | 
            +
                            info="The maximum proportional size of the generated image based on the uploaded image."
         | 
| 88 | 
            +
                        )
         | 
| 89 | 
            +
                        pre_start = gr.Button(value="PROCESS IMAGE", variant="primary")
         | 
| 90 | 
            +
                        with gr.Accordion("Advanced Settings", open=False):
         | 
| 91 | 
            +
                            with gr.Column():
         | 
| 92 | 
            +
                                pre_processor_resolution = gr.Slider(minimum=64, maximum=2048, step=64, value=512, label="Preprocessor Resolution")
         | 
| 93 | 
            +
                                pre_low_threshold = gr.Slider(minimum=1, maximum=255, step=1, value=100, label="'CANNY' low threshold")
         | 
| 94 | 
            +
                                pre_high_threshold = gr.Slider(minimum=1, maximum=255, step=1, value=200, label="'CANNY' high threshold")
         | 
| 95 | 
            +
                                pre_value_threshold = gr.Slider(minimum=1, maximum=2.0, step=0.01, value=0.1, label="'MLSD' Hough value threshold")
         | 
| 96 | 
            +
                                pre_distance_threshold = gr.Slider(minimum=1, maximum=20.0, step=0.01, value=0.1, label="'MLSD' Hough distance threshold")
         | 
| 97 | 
            +
                                pre_recolor_mode = gr.Dropdown(label="'RECOLOR' mode", choices=["luminance", "intensity"], value="luminance")
         | 
| 98 | 
            +
                                pre_recolor_gamma_correction = gr.Number(minimum=0., maximum=25., value=1., step=0.001, label="'RECOLOR' gamma correction")
         | 
| 99 | 
            +
                                pre_blur_k_size = gr.Number(minimum=0, maximum=100, value=9, step=1, label="'BLUR' sigma")
         | 
| 100 | 
            +
                                pre_openpose_extra = gr.Checkbox(value=True, label="'OPENPOSE' face and hand")
         | 
| 101 | 
            +
                                pre_hed_scribble = gr.Checkbox(value=False, label="'HED' scribble")
         | 
| 102 | 
            +
                                pre_pidinet_safe = gr.Checkbox(value=False, label="'PIDINET' safe")
         | 
| 103 | 
            +
                                pre_lineart_coarse = gr.Checkbox(value=False, label="'LINEART' coarse")
         | 
| 104 | 
            +
                                pre_use_cuda = gr.Checkbox(value=False, label="Use CUDA")
         | 
| 105 | 
            +
             | 
| 106 | 
            +
                    with gr.Column():
         | 
| 107 | 
            +
                        pre_result = gr.Image(label="Result", type="pil", interactive=False, format="png")
         | 
| 108 | 
            +
             | 
| 109 | 
            +
                        pre_start.click(
         | 
| 110 | 
            +
                            fn=process_inputs,
         | 
| 111 | 
            +
                            inputs=[
         | 
| 112 | 
            +
                                pre_image,
         | 
| 113 | 
            +
                                pre_options,
         | 
| 114 | 
            +
                                pre_img_resolution,
         | 
| 115 | 
            +
                                pre_processor_resolution,
         | 
| 116 | 
            +
                                pre_low_threshold,
         | 
| 117 | 
            +
                                pre_high_threshold,
         | 
| 118 | 
            +
                                pre_value_threshold,
         | 
| 119 | 
            +
                                pre_distance_threshold,
         | 
| 120 | 
            +
                                pre_recolor_mode,
         | 
| 121 | 
            +
                                pre_recolor_gamma_correction,
         | 
| 122 | 
            +
                                pre_blur_k_size,
         | 
| 123 | 
            +
                                pre_openpose_extra,
         | 
| 124 | 
            +
                                pre_hed_scribble,
         | 
| 125 | 
            +
                                pre_pidinet_safe,
         | 
| 126 | 
            +
                                pre_lineart_coarse,
         | 
| 127 | 
            +
                                pre_use_cuda,
         | 
| 128 | 
            +
                            ],
         | 
| 129 | 
            +
                            outputs=[pre_result],
         | 
| 130 | 
            +
                        )
         | 
    	
        packages.txt
    ADDED
    
    | @@ -0,0 +1,3 @@ | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            git-lfs
         | 
| 2 | 
            +
            aria2 -y
         | 
| 3 | 
            +
            ffmpeg
         | 
    	
        requirements.txt
    ADDED
    
    | @@ -0,0 +1,5 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            stablepy==0.6.0
         | 
| 2 | 
            +
            torch==2.2.0
         | 
| 3 | 
            +
            gdown
         | 
| 4 | 
            +
            opencv-python
         | 
| 5 | 
            +
            unidecode
         | 
    	
        spiral_no_transparent.png
    ADDED
    
    |   | 
    	
        utils.py
    ADDED
    
    | @@ -0,0 +1,485 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            import os
         | 
| 2 | 
            +
            import re
         | 
| 3 | 
            +
            import gradio as gr
         | 
| 4 | 
            +
            from constants import (
         | 
| 5 | 
            +
                DIFFUSERS_FORMAT_LORAS,
         | 
| 6 | 
            +
                CIVITAI_API_KEY,
         | 
| 7 | 
            +
                HF_TOKEN,
         | 
| 8 | 
            +
                MODEL_TYPE_CLASS,
         | 
| 9 | 
            +
                DIRECTORY_LORAS,
         | 
| 10 | 
            +
                DIRECTORY_MODELS,
         | 
| 11 | 
            +
                DIFFUSECRAFT_CHECKPOINT_NAME,
         | 
| 12 | 
            +
                CACHE_HF,
         | 
| 13 | 
            +
                STORAGE_ROOT,
         | 
| 14 | 
            +
            )
         | 
| 15 | 
            +
            from huggingface_hub import HfApi
         | 
| 16 | 
            +
            from huggingface_hub import snapshot_download
         | 
| 17 | 
            +
            from diffusers import DiffusionPipeline
         | 
| 18 | 
            +
            from huggingface_hub import model_info as model_info_data
         | 
| 19 | 
            +
            from diffusers.pipelines.pipeline_loading_utils import variant_compatible_siblings
         | 
| 20 | 
            +
            from stablepy.diffusers_vanilla.utils import checkpoint_model_type
         | 
| 21 | 
            +
            from pathlib import PosixPath
         | 
| 22 | 
            +
            from unidecode import unidecode
         | 
| 23 | 
            +
            import urllib.parse
         | 
| 24 | 
            +
            import copy
         | 
| 25 | 
            +
            import requests
         | 
| 26 | 
            +
            from requests.adapters import HTTPAdapter
         | 
| 27 | 
            +
            from urllib3.util import Retry
         | 
| 28 | 
            +
            import shutil
         | 
| 29 | 
            +
            import subprocess
         | 
| 30 | 
            +
             | 
| 31 | 
            +
            USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0'
         | 
| 32 | 
            +
             | 
| 33 | 
            +
             | 
| 34 | 
            +
            def request_json_data(url):
         | 
| 35 | 
            +
                model_version_id = url.split('/')[-1]
         | 
| 36 | 
            +
                if "?modelVersionId=" in model_version_id:
         | 
| 37 | 
            +
                    match = re.search(r'modelVersionId=(\d+)', url)
         | 
| 38 | 
            +
                    model_version_id = match.group(1)
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                endpoint_url = f"https://civitai.com/api/v1/model-versions/{model_version_id}"
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                params = {}
         | 
| 43 | 
            +
                headers = {'User-Agent': USER_AGENT, 'content-type': 'application/json'}
         | 
| 44 | 
            +
                session = requests.Session()
         | 
| 45 | 
            +
                retries = Retry(total=5, backoff_factor=1, status_forcelist=[500, 502, 503, 504])
         | 
| 46 | 
            +
                session.mount("https://", HTTPAdapter(max_retries=retries))
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                try:
         | 
| 49 | 
            +
                    result = session.get(endpoint_url, params=params, headers=headers, stream=True, timeout=(3.0, 15))
         | 
| 50 | 
            +
                    result.raise_for_status()
         | 
| 51 | 
            +
                    json_data = result.json()
         | 
| 52 | 
            +
                    return json_data if json_data else None
         | 
| 53 | 
            +
                except Exception as e:
         | 
| 54 | 
            +
                    print(f"Error: {e}")
         | 
| 55 | 
            +
                    return None
         | 
| 56 | 
            +
             | 
| 57 | 
            +
             | 
| 58 | 
            +
            class ModelInformation:
         | 
| 59 | 
            +
                def __init__(self, json_data):
         | 
| 60 | 
            +
                    self.model_version_id = json_data.get("id", "")
         | 
| 61 | 
            +
                    self.model_id = json_data.get("modelId", "")
         | 
| 62 | 
            +
                    self.download_url = json_data.get("downloadUrl", "")
         | 
| 63 | 
            +
                    self.model_url = f"https://civitai.com/models/{self.model_id}?modelVersionId={self.model_version_id}"
         | 
| 64 | 
            +
                    self.filename_url = next(
         | 
| 65 | 
            +
                        (v.get("name", "") for v in json_data.get("files", []) if str(self.model_version_id) in v.get("downloadUrl", "") and v.get("type", "Model") == "Model"), ""
         | 
| 66 | 
            +
                    )
         | 
| 67 | 
            +
                    self.filename_url = self.filename_url if self.filename_url else ""
         | 
| 68 | 
            +
                    self.description = json_data.get("description", "")
         | 
| 69 | 
            +
                    if self.description is None: self.description = ""
         | 
| 70 | 
            +
                    self.model_name = json_data.get("model", {}).get("name", "")
         | 
| 71 | 
            +
                    self.model_type = json_data.get("model", {}).get("type", "")
         | 
| 72 | 
            +
                    self.nsfw = json_data.get("model", {}).get("nsfw", False)
         | 
| 73 | 
            +
                    self.poi = json_data.get("model", {}).get("poi", False)
         | 
| 74 | 
            +
                    self.images = [img.get("url", "") for img in json_data.get("images", [])]
         | 
| 75 | 
            +
                    self.example_prompt = json_data.get("trainedWords", [""])[0] if json_data.get("trainedWords") else ""
         | 
| 76 | 
            +
                    self.original_json = copy.deepcopy(json_data)
         | 
| 77 | 
            +
             | 
| 78 | 
            +
             | 
| 79 | 
            +
            def retrieve_model_info(url):
         | 
| 80 | 
            +
                json_data = request_json_data(url)
         | 
| 81 | 
            +
                if not json_data:
         | 
| 82 | 
            +
                    return None
         | 
| 83 | 
            +
                model_descriptor = ModelInformation(json_data)
         | 
| 84 | 
            +
                return model_descriptor
         | 
| 85 | 
            +
             | 
| 86 | 
            +
             | 
| 87 | 
            +
            def download_things(directory, url, hf_token="", civitai_api_key="", romanize=False):
         | 
| 88 | 
            +
                url = url.strip()
         | 
| 89 | 
            +
                downloaded_file_path = None
         | 
| 90 | 
            +
             | 
| 91 | 
            +
                if "drive.google.com" in url:
         | 
| 92 | 
            +
                    original_dir = os.getcwd()
         | 
| 93 | 
            +
                    os.chdir(directory)
         | 
| 94 | 
            +
                    os.system(f"gdown --fuzzy {url}")
         | 
| 95 | 
            +
                    os.chdir(original_dir)
         | 
| 96 | 
            +
                elif "huggingface.co" in url:
         | 
| 97 | 
            +
                    url = url.replace("?download=true", "")
         | 
| 98 | 
            +
                    # url = urllib.parse.quote(url, safe=':/')  # fix encoding
         | 
| 99 | 
            +
                    if "/blob/" in url:
         | 
| 100 | 
            +
                        url = url.replace("/blob/", "/resolve/")
         | 
| 101 | 
            +
                    user_header = f'"Authorization: Bearer {hf_token}"'
         | 
| 102 | 
            +
             | 
| 103 | 
            +
                    filename = unidecode(url.split('/')[-1]) if romanize else url.split('/')[-1]
         | 
| 104 | 
            +
             | 
| 105 | 
            +
                    if hf_token:
         | 
| 106 | 
            +
                        os.system(f"aria2c --console-log-level=error --summary-interval=10 --header={user_header} -c -x 16 -k 1M -s 16 {url} -d {directory}  -o {filename}")
         | 
| 107 | 
            +
                    else:
         | 
| 108 | 
            +
                        os.system(f"aria2c --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -c -x 16 -k 1M -s 16 {url} -d {directory}  -o {filename}")
         | 
| 109 | 
            +
             | 
| 110 | 
            +
                    downloaded_file_path = os.path.join(directory, filename)
         | 
| 111 | 
            +
             | 
| 112 | 
            +
                elif "civitai.com" in url:
         | 
| 113 | 
            +
             | 
| 114 | 
            +
                    if not civitai_api_key:
         | 
| 115 | 
            +
                        print("\033[91mYou need an API key to download Civitai models.\033[0m")
         | 
| 116 | 
            +
             | 
| 117 | 
            +
                    model_profile = retrieve_model_info(url)
         | 
| 118 | 
            +
                    if (
         | 
| 119 | 
            +
                        model_profile is not None
         | 
| 120 | 
            +
                        and model_profile.download_url
         | 
| 121 | 
            +
                        and model_profile.filename_url
         | 
| 122 | 
            +
                    ):
         | 
| 123 | 
            +
                        url = model_profile.download_url
         | 
| 124 | 
            +
                        filename = unidecode(model_profile.filename_url) if romanize else model_profile.filename_url
         | 
| 125 | 
            +
                    else:
         | 
| 126 | 
            +
                        if "?" in url:
         | 
| 127 | 
            +
                            url = url.split("?")[0]
         | 
| 128 | 
            +
                        filename = ""
         | 
| 129 | 
            +
             | 
| 130 | 
            +
                    url_dl = url + f"?token={civitai_api_key}"
         | 
| 131 | 
            +
                    print(f"Filename: {filename}")
         | 
| 132 | 
            +
             | 
| 133 | 
            +
                    param_filename = ""
         | 
| 134 | 
            +
                    if filename:
         | 
| 135 | 
            +
                        param_filename = f"-o '{filename}'"
         | 
| 136 | 
            +
             | 
| 137 | 
            +
                    aria2_command = (
         | 
| 138 | 
            +
                        f'aria2c --console-log-level=error --summary-interval=10 -c -x 16 '
         | 
| 139 | 
            +
                        f'-k 1M -s 16 -d "{directory}" {param_filename} "{url_dl}"'
         | 
| 140 | 
            +
                    )
         | 
| 141 | 
            +
                    os.system(aria2_command)
         | 
| 142 | 
            +
             | 
| 143 | 
            +
                    if param_filename and os.path.exists(os.path.join(directory, filename)):
         | 
| 144 | 
            +
                        downloaded_file_path = os.path.join(directory, filename)
         | 
| 145 | 
            +
             | 
| 146 | 
            +
                    # # PLAN B
         | 
| 147 | 
            +
                    # # Follow the redirect to get the actual download URL
         | 
| 148 | 
            +
                    # curl_command = (
         | 
| 149 | 
            +
                    #     f'curl -L -sI --connect-timeout 5 --max-time 5 '
         | 
| 150 | 
            +
                    #     f'-H "Content-Type: application/json" '
         | 
| 151 | 
            +
                    #     f'-H "Authorization: Bearer {civitai_api_key}" "{url}"'
         | 
| 152 | 
            +
                    # )
         | 
| 153 | 
            +
             | 
| 154 | 
            +
                    # headers = os.popen(curl_command).read()
         | 
| 155 | 
            +
             | 
| 156 | 
            +
                    # # Look for the redirected "Location" URL
         | 
| 157 | 
            +
                    # location_match = re.search(r'location: (.+)', headers, re.IGNORECASE)
         | 
| 158 | 
            +
             | 
| 159 | 
            +
                    # if location_match:
         | 
| 160 | 
            +
                    #     redirect_url = location_match.group(1).strip()
         | 
| 161 | 
            +
             | 
| 162 | 
            +
                    #     # Extract the filename from the redirect URL's "Content-Disposition"
         | 
| 163 | 
            +
                    #     filename_match = re.search(r'filename%3D%22(.+?)%22', redirect_url)
         | 
| 164 | 
            +
                    #     if filename_match:
         | 
| 165 | 
            +
                    #         encoded_filename = filename_match.group(1)
         | 
| 166 | 
            +
                    #         # Decode the URL-encoded filename
         | 
| 167 | 
            +
                    #         decoded_filename = urllib.parse.unquote(encoded_filename)
         | 
| 168 | 
            +
             | 
| 169 | 
            +
                    #         filename = unidecode(decoded_filename) if romanize else decoded_filename
         | 
| 170 | 
            +
                    #         print(f"Filename: {filename}")
         | 
| 171 | 
            +
             | 
| 172 | 
            +
                    #         aria2_command = (
         | 
| 173 | 
            +
                    #             f'aria2c --console-log-level=error --summary-interval=10 -c -x 16 '
         | 
| 174 | 
            +
                    #             f'-k 1M -s 16 -d "{directory}" -o "{filename}" "{redirect_url}"'
         | 
| 175 | 
            +
                    #         )
         | 
| 176 | 
            +
                    #         return_code = os.system(aria2_command)
         | 
| 177 | 
            +
             | 
| 178 | 
            +
                    #         # if return_code != 0:
         | 
| 179 | 
            +
                    #         #     raise RuntimeError(f"Failed to download file: {filename}. Error code: {return_code}")
         | 
| 180 | 
            +
                    #         downloaded_file_path = os.path.join(directory, filename)
         | 
| 181 | 
            +
                    #         if not os.path.exists(downloaded_file_path):
         | 
| 182 | 
            +
                    #             downloaded_file_path = None
         | 
| 183 | 
            +
             | 
| 184 | 
            +
                    # if not downloaded_file_path:
         | 
| 185 | 
            +
                    #     # Old method
         | 
| 186 | 
            +
                    #     if "?" in url:
         | 
| 187 | 
            +
                    #         url = url.split("?")[0]
         | 
| 188 | 
            +
                    #     url = url + f"?token={civitai_api_key}"
         | 
| 189 | 
            +
                    #     os.system(f"aria2c --console-log-level=error --summary-interval=10 -c -x 16 -k 1M -s 16 -d {directory} {url}")
         | 
| 190 | 
            +
             | 
| 191 | 
            +
                else:
         | 
| 192 | 
            +
                    os.system(f"aria2c --console-log-level=error --summary-interval=10 -c -x 16 -k 1M -s 16 -d {directory} {url}")
         | 
| 193 | 
            +
             | 
| 194 | 
            +
                return downloaded_file_path
         | 
| 195 | 
            +
             | 
| 196 | 
            +
             | 
| 197 | 
            +
            def get_model_list(directory_path):
         | 
| 198 | 
            +
                model_list = []
         | 
| 199 | 
            +
                valid_extensions = {'.ckpt', '.pt', '.pth', '.safetensors', '.bin'}
         | 
| 200 | 
            +
             | 
| 201 | 
            +
                for filename in os.listdir(directory_path):
         | 
| 202 | 
            +
                    if os.path.splitext(filename)[1] in valid_extensions:
         | 
| 203 | 
            +
                        # name_without_extension = os.path.splitext(filename)[0]
         | 
| 204 | 
            +
                        file_path = os.path.join(directory_path, filename)
         | 
| 205 | 
            +
                        # model_list.append((name_without_extension, file_path))
         | 
| 206 | 
            +
                        model_list.append(file_path)
         | 
| 207 | 
            +
                        print('\033[34mFILE: ' + file_path + '\033[0m')
         | 
| 208 | 
            +
                return model_list
         | 
| 209 | 
            +
             | 
| 210 | 
            +
             | 
| 211 | 
            +
            def extract_parameters(input_string):
         | 
| 212 | 
            +
                parameters = {}
         | 
| 213 | 
            +
                input_string = input_string.replace("\n", "")
         | 
| 214 | 
            +
             | 
| 215 | 
            +
                if "Negative prompt:" not in input_string:
         | 
| 216 | 
            +
                    if "Steps:" in input_string:
         | 
| 217 | 
            +
                        input_string = input_string.replace("Steps:", "Negative prompt: Steps:")
         | 
| 218 | 
            +
                    else:
         | 
| 219 | 
            +
                        print("Invalid metadata")
         | 
| 220 | 
            +
                        parameters["prompt"] = input_string
         | 
| 221 | 
            +
                        return parameters
         | 
| 222 | 
            +
             | 
| 223 | 
            +
                parm = input_string.split("Negative prompt:")
         | 
| 224 | 
            +
                parameters["prompt"] = parm[0].strip()
         | 
| 225 | 
            +
                if "Steps:" not in parm[1]:
         | 
| 226 | 
            +
                    print("Steps not detected")
         | 
| 227 | 
            +
                    parameters["neg_prompt"] = parm[1].strip()
         | 
| 228 | 
            +
                    return parameters
         | 
| 229 | 
            +
                parm = parm[1].split("Steps:")
         | 
| 230 | 
            +
                parameters["neg_prompt"] = parm[0].strip()
         | 
| 231 | 
            +
                input_string = "Steps:" + parm[1]
         | 
| 232 | 
            +
             | 
| 233 | 
            +
                # Extracting Steps
         | 
| 234 | 
            +
                steps_match = re.search(r'Steps: (\d+)', input_string)
         | 
| 235 | 
            +
                if steps_match:
         | 
| 236 | 
            +
                    parameters['Steps'] = int(steps_match.group(1))
         | 
| 237 | 
            +
             | 
| 238 | 
            +
                # Extracting Size
         | 
| 239 | 
            +
                size_match = re.search(r'Size: (\d+x\d+)', input_string)
         | 
| 240 | 
            +
                if size_match:
         | 
| 241 | 
            +
                    parameters['Size'] = size_match.group(1)
         | 
| 242 | 
            +
                    width, height = map(int, parameters['Size'].split('x'))
         | 
| 243 | 
            +
                    parameters['width'] = width
         | 
| 244 | 
            +
                    parameters['height'] = height
         | 
| 245 | 
            +
             | 
| 246 | 
            +
                # Extracting other parameters
         | 
| 247 | 
            +
                other_parameters = re.findall(r'([^,:]+): (.*?)(?=, [^,:]+:|$)', input_string)
         | 
| 248 | 
            +
                for param in other_parameters:
         | 
| 249 | 
            +
                    parameters[param[0].strip()] = param[1].strip('"')
         | 
| 250 | 
            +
             | 
| 251 | 
            +
                return parameters
         | 
| 252 | 
            +
             | 
| 253 | 
            +
             | 
| 254 | 
            +
            def get_my_lora(link_url, romanize):
         | 
| 255 | 
            +
                l_name = ""
         | 
| 256 | 
            +
                for url in [url.strip() for url in link_url.split(',')]:
         | 
| 257 | 
            +
                    if not os.path.exists(f"./loras/{url.split('/')[-1]}"):
         | 
| 258 | 
            +
                        l_name = download_things(DIRECTORY_LORAS, url, HF_TOKEN, CIVITAI_API_KEY, romanize)
         | 
| 259 | 
            +
                new_lora_model_list = get_model_list(DIRECTORY_LORAS)
         | 
| 260 | 
            +
                new_lora_model_list.insert(0, "None")
         | 
| 261 | 
            +
                new_lora_model_list = new_lora_model_list + DIFFUSERS_FORMAT_LORAS
         | 
| 262 | 
            +
                msg_lora = "Downloaded"
         | 
| 263 | 
            +
                if l_name:
         | 
| 264 | 
            +
                    msg_lora += f": <b>{l_name}</b>"
         | 
| 265 | 
            +
                    print(msg_lora)
         | 
| 266 | 
            +
             | 
| 267 | 
            +
                return gr.update(
         | 
| 268 | 
            +
                    choices=new_lora_model_list
         | 
| 269 | 
            +
                ), gr.update(
         | 
| 270 | 
            +
                    choices=new_lora_model_list
         | 
| 271 | 
            +
                ), gr.update(
         | 
| 272 | 
            +
                    choices=new_lora_model_list
         | 
| 273 | 
            +
                ), gr.update(
         | 
| 274 | 
            +
                    choices=new_lora_model_list
         | 
| 275 | 
            +
                ), gr.update(
         | 
| 276 | 
            +
                    choices=new_lora_model_list
         | 
| 277 | 
            +
                ), gr.update(
         | 
| 278 | 
            +
                    choices=new_lora_model_list
         | 
| 279 | 
            +
                ), gr.update(
         | 
| 280 | 
            +
                    choices=new_lora_model_list
         | 
| 281 | 
            +
                ), gr.update(
         | 
| 282 | 
            +
                    value=msg_lora
         | 
| 283 | 
            +
                )
         | 
| 284 | 
            +
             | 
| 285 | 
            +
             | 
| 286 | 
            +
            def info_html(json_data, title, subtitle):
         | 
| 287 | 
            +
                return f"""
         | 
| 288 | 
            +
                    <div style='padding: 0; border-radius: 10px;'>
         | 
| 289 | 
            +
                        <p style='margin: 0; font-weight: bold;'>{title}</p>
         | 
| 290 | 
            +
                        <details>
         | 
| 291 | 
            +
                            <summary>Details</summary>
         | 
| 292 | 
            +
                            <p style='margin: 0; font-weight: bold;'>{subtitle}</p>
         | 
| 293 | 
            +
                        </details>
         | 
| 294 | 
            +
                    </div>
         | 
| 295 | 
            +
                    """
         | 
| 296 | 
            +
             | 
| 297 | 
            +
             | 
| 298 | 
            +
            def get_model_type(repo_id: str):
         | 
| 299 | 
            +
                api = HfApi(token=os.environ.get("HF_TOKEN"))  # if use private or gated model
         | 
| 300 | 
            +
                default = "SD 1.5"
         | 
| 301 | 
            +
                try:
         | 
| 302 | 
            +
                    if os.path.exists(repo_id):
         | 
| 303 | 
            +
                        tag, _, _, _ = checkpoint_model_type(repo_id)
         | 
| 304 | 
            +
                        return DIFFUSECRAFT_CHECKPOINT_NAME[tag]
         | 
| 305 | 
            +
                    else:
         | 
| 306 | 
            +
                        model = api.model_info(repo_id=repo_id, timeout=5.0)
         | 
| 307 | 
            +
                        tags = model.tags
         | 
| 308 | 
            +
                        for tag in tags:
         | 
| 309 | 
            +
                            if tag in MODEL_TYPE_CLASS.keys(): return MODEL_TYPE_CLASS.get(tag, default)
         | 
| 310 | 
            +
             | 
| 311 | 
            +
                except Exception:
         | 
| 312 | 
            +
                    return default
         | 
| 313 | 
            +
                return default
         | 
| 314 | 
            +
             | 
| 315 | 
            +
             | 
| 316 | 
            +
            def restart_space(repo_id: str, factory_reboot: bool):
         | 
| 317 | 
            +
                api = HfApi(token=os.environ.get("HF_TOKEN"))
         | 
| 318 | 
            +
                try:
         | 
| 319 | 
            +
                    runtime = api.get_space_runtime(repo_id=repo_id)
         | 
| 320 | 
            +
                    if runtime.stage == "RUNNING":
         | 
| 321 | 
            +
                        api.restart_space(repo_id=repo_id, factory_reboot=factory_reboot)
         | 
| 322 | 
            +
                        print(f"Restarting space: {repo_id}")
         | 
| 323 | 
            +
                    else:
         | 
| 324 | 
            +
                        print(f"Space {repo_id} is in stage: {runtime.stage}")
         | 
| 325 | 
            +
                except Exception as e:
         | 
| 326 | 
            +
                    print(e)
         | 
| 327 | 
            +
             | 
| 328 | 
            +
             | 
| 329 | 
            +
            def extract_exif_data(image):
         | 
| 330 | 
            +
                if image is None:
         | 
| 331 | 
            +
                    return ""
         | 
| 332 | 
            +
             | 
| 333 | 
            +
                try:
         | 
| 334 | 
            +
                    metadata_keys = ['parameters', 'metadata', 'prompt', 'Comment']
         | 
| 335 | 
            +
             | 
| 336 | 
            +
                    for key in metadata_keys:
         | 
| 337 | 
            +
                        if key in image.info:
         | 
| 338 | 
            +
                            return image.info[key]
         | 
| 339 | 
            +
             | 
| 340 | 
            +
                    return str(image.info)
         | 
| 341 | 
            +
             | 
| 342 | 
            +
                except Exception as e:
         | 
| 343 | 
            +
                    return f"Error extracting metadata: {str(e)}"
         | 
| 344 | 
            +
             | 
| 345 | 
            +
             | 
| 346 | 
            +
            def create_mask_now(img, invert):
         | 
| 347 | 
            +
                import numpy as np
         | 
| 348 | 
            +
                import time
         | 
| 349 | 
            +
             | 
| 350 | 
            +
                time.sleep(0.5)
         | 
| 351 | 
            +
             | 
| 352 | 
            +
                transparent_image = img["layers"][0]
         | 
| 353 | 
            +
             | 
| 354 | 
            +
                # Extract the alpha channel
         | 
| 355 | 
            +
                alpha_channel = np.array(transparent_image)[:, :, 3]
         | 
| 356 | 
            +
             | 
| 357 | 
            +
                # Create a binary mask by thresholding the alpha channel
         | 
| 358 | 
            +
                binary_mask = alpha_channel > 1
         | 
| 359 | 
            +
             | 
| 360 | 
            +
                if invert:
         | 
| 361 | 
            +
                    print("Invert")
         | 
| 362 | 
            +
                    # Invert the binary mask so that the drawn shape is white and the rest is black
         | 
| 363 | 
            +
                    binary_mask = np.invert(binary_mask)
         | 
| 364 | 
            +
             | 
| 365 | 
            +
                # Convert the binary mask to a 3-channel RGB mask
         | 
| 366 | 
            +
                rgb_mask = np.stack((binary_mask,) * 3, axis=-1)
         | 
| 367 | 
            +
             | 
| 368 | 
            +
                # Convert the mask to uint8
         | 
| 369 | 
            +
                rgb_mask = rgb_mask.astype(np.uint8) * 255
         | 
| 370 | 
            +
             | 
| 371 | 
            +
                return img["background"], rgb_mask
         | 
| 372 | 
            +
             | 
| 373 | 
            +
             | 
| 374 | 
            +
            def download_diffuser_repo(repo_name: str, model_type: str, revision: str = "main", token=True):
         | 
| 375 | 
            +
             | 
| 376 | 
            +
                variant = None
         | 
| 377 | 
            +
                if token is True and not os.environ.get("HF_TOKEN"):
         | 
| 378 | 
            +
                    token = None
         | 
| 379 | 
            +
             | 
| 380 | 
            +
                if model_type == "SDXL":
         | 
| 381 | 
            +
                    info = model_info_data(
         | 
| 382 | 
            +
                        repo_name,
         | 
| 383 | 
            +
                        token=token,
         | 
| 384 | 
            +
                        revision=revision,
         | 
| 385 | 
            +
                        timeout=5.0,
         | 
| 386 | 
            +
                    )
         | 
| 387 | 
            +
             | 
| 388 | 
            +
                    filenames = {sibling.rfilename for sibling in info.siblings}
         | 
| 389 | 
            +
                    model_filenames, variant_filenames = variant_compatible_siblings(
         | 
| 390 | 
            +
                        filenames, variant="fp16"
         | 
| 391 | 
            +
                    )
         | 
| 392 | 
            +
             | 
| 393 | 
            +
                    if len(variant_filenames):
         | 
| 394 | 
            +
                        variant = "fp16"
         | 
| 395 | 
            +
             | 
| 396 | 
            +
                if model_type == "FLUX":
         | 
| 397 | 
            +
                    cached_folder = snapshot_download(
         | 
| 398 | 
            +
                        repo_id=repo_name,
         | 
| 399 | 
            +
                        allow_patterns="transformer/*"
         | 
| 400 | 
            +
                    )
         | 
| 401 | 
            +
                else:
         | 
| 402 | 
            +
                    cached_folder = DiffusionPipeline.download(
         | 
| 403 | 
            +
                        pretrained_model_name=repo_name,
         | 
| 404 | 
            +
                        force_download=False,
         | 
| 405 | 
            +
                        token=token,
         | 
| 406 | 
            +
                        revision=revision,
         | 
| 407 | 
            +
                        # mirror="https://hf-mirror.com",
         | 
| 408 | 
            +
                        variant=variant,
         | 
| 409 | 
            +
                        use_safetensors=True,
         | 
| 410 | 
            +
                        trust_remote_code=False,
         | 
| 411 | 
            +
                        timeout=5.0,
         | 
| 412 | 
            +
                    )
         | 
| 413 | 
            +
             | 
| 414 | 
            +
                if isinstance(cached_folder, PosixPath):
         | 
| 415 | 
            +
                    cached_folder = cached_folder.as_posix()
         | 
| 416 | 
            +
             | 
| 417 | 
            +
                # Task model
         | 
| 418 | 
            +
                # from huggingface_hub import hf_hub_download
         | 
| 419 | 
            +
                # hf_hub_download(
         | 
| 420 | 
            +
                #     task_model,
         | 
| 421 | 
            +
                #     filename="diffusion_pytorch_model.safetensors",  # fix fp16 variant
         | 
| 422 | 
            +
                # )
         | 
| 423 | 
            +
             | 
| 424 | 
            +
                return cached_folder
         | 
| 425 | 
            +
             | 
| 426 | 
            +
             | 
| 427 | 
            +
            def get_folder_size_gb(folder_path):
         | 
| 428 | 
            +
                result = subprocess.run(["du", "-s", folder_path], capture_output=True, text=True)
         | 
| 429 | 
            +
             | 
| 430 | 
            +
                total_size_kb = int(result.stdout.split()[0])
         | 
| 431 | 
            +
                total_size_gb = total_size_kb / (1024 ** 2)
         | 
| 432 | 
            +
             | 
| 433 | 
            +
                return total_size_gb
         | 
| 434 | 
            +
             | 
| 435 | 
            +
             | 
| 436 | 
            +
            def get_used_storage_gb():
         | 
| 437 | 
            +
                try:
         | 
| 438 | 
            +
                    used_gb = get_folder_size_gb(STORAGE_ROOT)
         | 
| 439 | 
            +
                    print(f"Used Storage: {used_gb:.2f} GB")
         | 
| 440 | 
            +
                except Exception as e:
         | 
| 441 | 
            +
                    used_gb = 999
         | 
| 442 | 
            +
                    print(f"Error while retrieving the used storage: {e}.")
         | 
| 443 | 
            +
             | 
| 444 | 
            +
                return used_gb
         | 
| 445 | 
            +
             | 
| 446 | 
            +
             | 
| 447 | 
            +
            def delete_model(removal_candidate):
         | 
| 448 | 
            +
                print(f"Removing: {removal_candidate}")
         | 
| 449 | 
            +
             | 
| 450 | 
            +
                if os.path.exists(removal_candidate):
         | 
| 451 | 
            +
                    os.remove(removal_candidate)
         | 
| 452 | 
            +
                else:
         | 
| 453 | 
            +
                    diffusers_model = f"{CACHE_HF}{DIRECTORY_MODELS}--{removal_candidate.replace('/', '--')}"
         | 
| 454 | 
            +
                    if os.path.isdir(diffusers_model):
         | 
| 455 | 
            +
                        shutil.rmtree(diffusers_model)
         | 
| 456 | 
            +
             | 
| 457 | 
            +
             | 
| 458 | 
            +
            def progress_step_bar(step, total):
         | 
| 459 | 
            +
                # Calculate the percentage for the progress bar width
         | 
| 460 | 
            +
                percentage = min(100, ((step / total) * 100))
         | 
| 461 | 
            +
             | 
| 462 | 
            +
                return f"""
         | 
| 463 | 
            +
                    <div style="position: relative; width: 100%; background-color: gray; border-radius: 5px; overflow: hidden;">
         | 
| 464 | 
            +
                        <div style="width: {percentage}%; height: 17px; background-color: #800080; transition: width 0.5s;"></div>
         | 
| 465 | 
            +
                        <div style="position: absolute; width: 100%; text-align: center; color: white; top: 0; line-height: 19px; font-size: 13px;">
         | 
| 466 | 
            +
                            {int(percentage)}%
         | 
| 467 | 
            +
                        </div>
         | 
| 468 | 
            +
                    </div>
         | 
| 469 | 
            +
                    """
         | 
| 470 | 
            +
             | 
| 471 | 
            +
             | 
| 472 | 
            +
            def html_template_message(msg):
         | 
| 473 | 
            +
                return f"""
         | 
| 474 | 
            +
                    <div style="position: relative; width: 100%; background-color: gray; border-radius: 5px; overflow: hidden;">
         | 
| 475 | 
            +
                        <div style="width: 0%; height: 17px; background-color: #800080; transition: width 0.5s;"></div>
         | 
| 476 | 
            +
                        <div style="position: absolute; width: 100%; text-align: center; color: white; top: 0; line-height: 19px; font-size: 14px; font-weight: bold; text-shadow: 1px 1px 2px black;">
         | 
| 477 | 
            +
                            {msg}
         | 
| 478 | 
            +
                        </div>
         | 
| 479 | 
            +
                    </div>
         | 
| 480 | 
            +
                    """
         | 
| 481 | 
            +
             | 
| 482 | 
            +
             | 
| 483 | 
            +
            def escape_html(text):
         | 
| 484 | 
            +
                """Escapes HTML special characters in the input text."""
         | 
| 485 | 
            +
                return text.replace("<", "<").replace(">", ">").replace("\n", "<br>")
         | 

