Spaces:
				
			
			
	
			
			
		Running
		
			on 
			
			Zero
	
	
	
			
			
	
	
	
	
		
		
		Running
		
			on 
			
			Zero
	Upload 2 files
Browse files- constants.py +453 -0
 - utils.py +270 -0
 
    	
        constants.py
    ADDED
    
    | 
         @@ -0,0 +1,453 @@ 
     | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
| 
         | 
|
| 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 | 
         
            +
            )
         
     | 
| 8 | 
         
            +
             
     | 
| 9 | 
         
            +
            # - **Download Models**
         
     | 
| 10 | 
         
            +
            DOWNLOAD_MODEL = "https://civitai.com/api/download/models/574369, https://huggingface.co/TechnoByte/MilkyWonderland/resolve/main/milkyWonderland_v40.safetensors"
         
     | 
| 11 | 
         
            +
             
     | 
| 12 | 
         
            +
            # - **Download VAEs**
         
     | 
| 13 | 
         
            +
            DOWNLOAD_VAE = "https://huggingface.co/nubby/blessed-sdxl-vae-fp16-fix/resolve/main/sdxl_vae-fp16fix-c-1.1-b-0.5.safetensors?download=true, https://huggingface.co/nubby/blessed-sdxl-vae-fp16-fix/resolve/main/sdxl_vae-fp16fix-blessed.safetensors?download=true, https://huggingface.co/digiplay/VAE/resolve/main/vividReal_v20.safetensors?download=true, 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"
         
     | 
| 14 | 
         
            +
             
     | 
| 15 | 
         
            +
            # - **Download LoRAs**
         
     | 
| 16 | 
         
            +
            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"
         
     | 
| 17 | 
         
            +
             
     | 
| 18 | 
         
            +
            LOAD_DIFFUSERS_FORMAT_MODEL = [
         
     | 
| 19 | 
         
            +
                'stabilityai/stable-diffusion-xl-base-1.0',
         
     | 
| 20 | 
         
            +
                'black-forest-labs/FLUX.1-dev',
         
     | 
| 21 | 
         
            +
                'John6666/blue-pencil-flux1-v021-fp8-flux',
         
     | 
| 22 | 
         
            +
                'John6666/wai-ani-flux-v10forfp8-fp8-flux',
         
     | 
| 23 | 
         
            +
                'John6666/xe-anime-flux-v04-fp8-flux',
         
     | 
| 24 | 
         
            +
                'John6666/lyh-anime-flux-v2a1-fp8-flux',
         
     | 
| 25 | 
         
            +
                'John6666/carnival-unchained-v10-fp8-flux',
         
     | 
| 26 | 
         
            +
                'cagliostrolab/animagine-xl-3.1',
         
     | 
| 27 | 
         
            +
                'John6666/epicrealism-xl-v8kiss-sdxl',
         
     | 
| 28 | 
         
            +
                'misri/epicrealismXL_v7FinalDestination',
         
     | 
| 29 | 
         
            +
                'misri/juggernautXL_juggernautX',
         
     | 
| 30 | 
         
            +
                'misri/zavychromaxl_v80',
         
     | 
| 31 | 
         
            +
                'SG161222/RealVisXL_V4.0',
         
     | 
| 32 | 
         
            +
                'SG161222/RealVisXL_V5.0',
         
     | 
| 33 | 
         
            +
                'misri/newrealityxlAllInOne_Newreality40',
         
     | 
| 34 | 
         
            +
                'eienmojiki/Anything-XL',
         
     | 
| 35 | 
         
            +
                'eienmojiki/Starry-XL-v5.2',
         
     | 
| 36 | 
         
            +
                'gsdf/CounterfeitXL',
         
     | 
| 37 | 
         
            +
                'KBlueLeaf/Kohaku-XL-Zeta',
         
     | 
| 38 | 
         
            +
                'John6666/silvermoon-mix-01xl-v11-sdxl',
         
     | 
| 39 | 
         
            +
                'WhiteAiZ/autismmixSDXL_autismmixConfetti_diffusers',
         
     | 
| 40 | 
         
            +
                'kitty7779/ponyDiffusionV6XL',
         
     | 
| 41 | 
         
            +
                'GraydientPlatformAPI/aniverse-pony',
         
     | 
| 42 | 
         
            +
                'John6666/ras-real-anime-screencap-v1-sdxl',
         
     | 
| 43 | 
         
            +
                'John6666/duchaiten-pony-xl-no-score-v60-sdxl',
         
     | 
| 44 | 
         
            +
                'John6666/mistoon-anime-ponyalpha-sdxl',
         
     | 
| 45 | 
         
            +
                'John6666/3x3x3mixxl-v2-sdxl',
         
     | 
| 46 | 
         
            +
                'John6666/3x3x3mixxl-3dv01-sdxl',
         
     | 
| 47 | 
         
            +
                'John6666/ebara-mfcg-pony-mix-v12-sdxl',
         
     | 
| 48 | 
         
            +
                'John6666/t-ponynai3-v51-sdxl',
         
     | 
| 49 | 
         
            +
                'John6666/t-ponynai3-v65-sdxl',
         
     | 
| 50 | 
         
            +
                'John6666/prefect-pony-xl-v3-sdxl',
         
     | 
| 51 | 
         
            +
                'John6666/mala-anime-mix-nsfw-pony-xl-v5-sdxl',
         
     | 
| 52 | 
         
            +
                'John6666/wai-real-mix-v11-sdxl',
         
     | 
| 53 | 
         
            +
                'John6666/wai-c-v6-sdxl',
         
     | 
| 54 | 
         
            +
                'John6666/iniverse-mix-xl-sfwnsfw-pony-guofeng-v43-sdxl',
         
     | 
| 55 | 
         
            +
                'John6666/photo-realistic-pony-v5-sdxl',
         
     | 
| 56 | 
         
            +
                'John6666/pony-realism-v21main-sdxl',
         
     | 
| 57 | 
         
            +
                'John6666/pony-realism-v22main-sdxl',
         
     | 
| 58 | 
         
            +
                'John6666/cyberrealistic-pony-v63-sdxl',
         
     | 
| 59 | 
         
            +
                'John6666/cyberrealistic-pony-v64-sdxl',
         
     | 
| 60 | 
         
            +
                'John6666/cyberrealistic-pony-v65-sdxl',
         
     | 
| 61 | 
         
            +
                'GraydientPlatformAPI/realcartoon-pony-diffusion',
         
     | 
| 62 | 
         
            +
                'John6666/nova-anime-xl-pony-v5-sdxl',
         
     | 
| 63 | 
         
            +
                'John6666/autismmix-sdxl-autismmix-pony-sdxl',
         
     | 
| 64 | 
         
            +
                'John6666/aimz-dream-real-pony-mix-v3-sdxl',
         
     | 
| 65 | 
         
            +
                'John6666/duchaiten-pony-real-v11fix-sdxl',
         
     | 
| 66 | 
         
            +
                'John6666/duchaiten-pony-real-v20-sdxl',
         
     | 
| 67 | 
         
            +
                'yodayo-ai/kivotos-xl-2.0',
         
     | 
| 68 | 
         
            +
                'yodayo-ai/holodayo-xl-2.1',
         
     | 
| 69 | 
         
            +
                'yodayo-ai/clandestine-xl-1.0',
         
     | 
| 70 | 
         
            +
                'digiplay/majicMIX_sombre_v2',
         
     | 
| 71 | 
         
            +
                'digiplay/majicMIX_realistic_v6',
         
     | 
| 72 | 
         
            +
                'digiplay/majicMIX_realistic_v7',
         
     | 
| 73 | 
         
            +
                'digiplay/DreamShaper_8',
         
     | 
| 74 | 
         
            +
                'digiplay/BeautifulArt_v1',
         
     | 
| 75 | 
         
            +
                'digiplay/DarkSushi2.5D_v1',
         
     | 
| 76 | 
         
            +
                'digiplay/darkphoenix3D_v1.1',
         
     | 
| 77 | 
         
            +
                'digiplay/BeenYouLiteL11_diffusers',
         
     | 
| 78 | 
         
            +
                'Yntec/RevAnimatedV2Rebirth',
         
     | 
| 79 | 
         
            +
                'youknownothing/cyberrealistic_v50',
         
     | 
| 80 | 
         
            +
                'youknownothing/deliberate-v6',
         
     | 
| 81 | 
         
            +
                'GraydientPlatformAPI/deliberate-cyber3',
         
     | 
| 82 | 
         
            +
                'GraydientPlatformAPI/picx-real',
         
     | 
| 83 | 
         
            +
                'GraydientPlatformAPI/perfectworld6',
         
     | 
| 84 | 
         
            +
                'emilianJR/epiCRealism',
         
     | 
| 85 | 
         
            +
                'votepurchase/counterfeitV30_v30',
         
     | 
| 86 | 
         
            +
                'votepurchase/ChilloutMix',
         
     | 
| 87 | 
         
            +
                'Meina/MeinaMix_V11',
         
     | 
| 88 | 
         
            +
                'Meina/MeinaUnreal_V5',
         
     | 
| 89 | 
         
            +
                'Meina/MeinaPastel_V7',
         
     | 
| 90 | 
         
            +
                'GraydientPlatformAPI/realcartoon3d-17',
         
     | 
| 91 | 
         
            +
                'GraydientPlatformAPI/realcartoon-pixar11',
         
     | 
| 92 | 
         
            +
                'GraydientPlatformAPI/realcartoon-real17',
         
     | 
| 93 | 
         
            +
            ]
         
     | 
| 94 | 
         
            +
             
     | 
| 95 | 
         
            +
            DIFFUSERS_FORMAT_LORAS = [
         
     | 
| 96 | 
         
            +
                "nerijs/animation2k-flux",
         
     | 
| 97 | 
         
            +
                "XLabs-AI/flux-RealismLora",
         
     | 
| 98 | 
         
            +
            ]
         
     | 
| 99 | 
         
            +
             
     | 
| 100 | 
         
            +
            DOWNLOAD_EMBEDS = [
         
     | 
| 101 | 
         
            +
                'https://huggingface.co/datasets/Nerfgun3/bad_prompt/blob/main/bad_prompt_version2.pt',
         
     | 
| 102 | 
         
            +
                'https://huggingface.co/embed/negative/resolve/main/EasyNegativeV2.safetensors',
         
     | 
| 103 | 
         
            +
                'https://huggingface.co/embed/negative/resolve/main/bad-hands-5.pt',
         
     | 
| 104 | 
         
            +
                ]
         
     | 
| 105 | 
         
            +
             
     | 
| 106 | 
         
            +
            CIVITAI_API_KEY = os.environ.get("CIVITAI_API_KEY")
         
     | 
| 107 | 
         
            +
            HF_TOKEN = os.environ.get("HF_READ_TOKEN")
         
     | 
| 108 | 
         
            +
             
     | 
| 109 | 
         
            +
            DIRECTORY_MODELS = 'models'
         
     | 
| 110 | 
         
            +
            DIRECTORY_LORAS = 'loras'
         
     | 
| 111 | 
         
            +
            DIRECTORY_VAES = 'vaes'
         
     | 
| 112 | 
         
            +
            DIRECTORY_EMBEDS = 'embedings'
         
     | 
| 113 | 
         
            +
             
     | 
| 114 | 
         
            +
            PREPROCESSOR_CONTROLNET = {
         
     | 
| 115 | 
         
            +
              "openpose": [
         
     | 
| 116 | 
         
            +
                "Openpose",
         
     | 
| 117 | 
         
            +
                "None",
         
     | 
| 118 | 
         
            +
              ],
         
     | 
| 119 | 
         
            +
              "scribble": [
         
     | 
| 120 | 
         
            +
                "HED",
         
     | 
| 121 | 
         
            +
                "PidiNet",
         
     | 
| 122 | 
         
            +
                "None",
         
     | 
| 123 | 
         
            +
              ],
         
     | 
| 124 | 
         
            +
              "softedge": [
         
     | 
| 125 | 
         
            +
                "PidiNet",
         
     | 
| 126 | 
         
            +
                "HED",
         
     | 
| 127 | 
         
            +
                "HED safe",
         
     | 
| 128 | 
         
            +
                "PidiNet safe",
         
     | 
| 129 | 
         
            +
                "None",
         
     | 
| 130 | 
         
            +
              ],
         
     | 
| 131 | 
         
            +
              "segmentation": [
         
     | 
| 132 | 
         
            +
                "UPerNet",
         
     | 
| 133 | 
         
            +
                "None",
         
     | 
| 134 | 
         
            +
              ],
         
     | 
| 135 | 
         
            +
              "depth": [
         
     | 
| 136 | 
         
            +
                "DPT",
         
     | 
| 137 | 
         
            +
                "Midas",
         
     | 
| 138 | 
         
            +
                "None",
         
     | 
| 139 | 
         
            +
              ],
         
     | 
| 140 | 
         
            +
              "normalbae": [
         
     | 
| 141 | 
         
            +
                "NormalBae",
         
     | 
| 142 | 
         
            +
                "None",
         
     | 
| 143 | 
         
            +
              ],
         
     | 
| 144 | 
         
            +
              "lineart": [
         
     | 
| 145 | 
         
            +
                "Lineart",
         
     | 
| 146 | 
         
            +
                "Lineart coarse",
         
     | 
| 147 | 
         
            +
                "Lineart (anime)",
         
     | 
| 148 | 
         
            +
                "None",
         
     | 
| 149 | 
         
            +
                "None (anime)",
         
     | 
| 150 | 
         
            +
              ],
         
     | 
| 151 | 
         
            +
              "lineart_anime": [
         
     | 
| 152 | 
         
            +
                "Lineart",
         
     | 
| 153 | 
         
            +
                "Lineart coarse",
         
     | 
| 154 | 
         
            +
                "Lineart (anime)",
         
     | 
| 155 | 
         
            +
                "None",
         
     | 
| 156 | 
         
            +
                "None (anime)",
         
     | 
| 157 | 
         
            +
              ],
         
     | 
| 158 | 
         
            +
              "shuffle": [
         
     | 
| 159 | 
         
            +
                "ContentShuffle",
         
     | 
| 160 | 
         
            +
                "None",
         
     | 
| 161 | 
         
            +
              ],
         
     | 
| 162 | 
         
            +
              "canny": [
         
     | 
| 163 | 
         
            +
                "Canny",
         
     | 
| 164 | 
         
            +
                "None",
         
     | 
| 165 | 
         
            +
              ],
         
     | 
| 166 | 
         
            +
              "mlsd": [
         
     | 
| 167 | 
         
            +
                "MLSD",
         
     | 
| 168 | 
         
            +
                "None",
         
     | 
| 169 | 
         
            +
              ],
         
     | 
| 170 | 
         
            +
              "ip2p": [
         
     | 
| 171 | 
         
            +
                "ip2p"
         
     | 
| 172 | 
         
            +
              ],
         
     | 
| 173 | 
         
            +
              "recolor": [
         
     | 
| 174 | 
         
            +
                "Recolor luminance",
         
     | 
| 175 | 
         
            +
                "Recolor intensity",
         
     | 
| 176 | 
         
            +
                "None",
         
     | 
| 177 | 
         
            +
              ],
         
     | 
| 178 | 
         
            +
              "tile": [
         
     | 
| 179 | 
         
            +
                "Mild Blur",
         
     | 
| 180 | 
         
            +
                "Moderate Blur",
         
     | 
| 181 | 
         
            +
                "Heavy Blur",
         
     | 
| 182 | 
         
            +
                "None",
         
     | 
| 183 | 
         
            +
              ],
         
     | 
| 184 | 
         
            +
             
     | 
| 185 | 
         
            +
            }
         
     | 
| 186 | 
         
            +
             
     | 
| 187 | 
         
            +
            TASK_STABLEPY = {
         
     | 
| 188 | 
         
            +
                'txt2img': 'txt2img',
         
     | 
| 189 | 
         
            +
                'img2img': 'img2img',
         
     | 
| 190 | 
         
            +
                'inpaint': 'inpaint',
         
     | 
| 191 | 
         
            +
                # 'canny T2I Adapter': 'sdxl_canny_t2i',  # NO HAVE STEP CALLBACK PARAMETERS SO NOT WORKS WITH DIFFUSERS 0.29.0
         
     | 
| 192 | 
         
            +
                # 'sketch  T2I Adapter': 'sdxl_sketch_t2i',
         
     | 
| 193 | 
         
            +
                # 'lineart  T2I Adapter': 'sdxl_lineart_t2i',
         
     | 
| 194 | 
         
            +
                # 'depth-midas  T2I Adapter': 'sdxl_depth-midas_t2i',
         
     | 
| 195 | 
         
            +
                # 'openpose  T2I Adapter': 'sdxl_openpose_t2i',
         
     | 
| 196 | 
         
            +
                'openpose ControlNet': 'openpose',
         
     | 
| 197 | 
         
            +
                'canny ControlNet': 'canny',
         
     | 
| 198 | 
         
            +
                'mlsd ControlNet': 'mlsd',
         
     | 
| 199 | 
         
            +
                'scribble ControlNet': 'scribble',
         
     | 
| 200 | 
         
            +
                'softedge ControlNet': 'softedge',
         
     | 
| 201 | 
         
            +
                'segmentation ControlNet': 'segmentation',
         
     | 
| 202 | 
         
            +
                'depth ControlNet': 'depth',
         
     | 
| 203 | 
         
            +
                'normalbae ControlNet': 'normalbae',
         
     | 
| 204 | 
         
            +
                'lineart ControlNet': 'lineart',
         
     | 
| 205 | 
         
            +
                'lineart_anime ControlNet': 'lineart_anime',
         
     | 
| 206 | 
         
            +
                'shuffle ControlNet': 'shuffle',
         
     | 
| 207 | 
         
            +
                'ip2p ControlNet': 'ip2p',
         
     | 
| 208 | 
         
            +
                'optical pattern ControlNet': 'pattern',
         
     | 
| 209 | 
         
            +
                'recolor ControlNet': 'recolor',
         
     | 
| 210 | 
         
            +
                'tile ControlNet': 'tile',
         
     | 
| 211 | 
         
            +
            }
         
     | 
| 212 | 
         
            +
             
     | 
| 213 | 
         
            +
            TASK_MODEL_LIST = list(TASK_STABLEPY.keys())
         
     | 
| 214 | 
         
            +
             
     | 
| 215 | 
         
            +
            UPSCALER_DICT_GUI = {
         
     | 
| 216 | 
         
            +
                None: None,
         
     | 
| 217 | 
         
            +
                "Lanczos": "Lanczos",
         
     | 
| 218 | 
         
            +
                "Nearest": "Nearest",
         
     | 
| 219 | 
         
            +
                'Latent': 'Latent',
         
     | 
| 220 | 
         
            +
                'Latent (antialiased)': 'Latent (antialiased)',
         
     | 
| 221 | 
         
            +
                'Latent (bicubic)': 'Latent (bicubic)',
         
     | 
| 222 | 
         
            +
                'Latent (bicubic antialiased)': 'Latent (bicubic antialiased)',
         
     | 
| 223 | 
         
            +
                'Latent (nearest)': 'Latent (nearest)',
         
     | 
| 224 | 
         
            +
                'Latent (nearest-exact)': 'Latent (nearest-exact)',
         
     | 
| 225 | 
         
            +
                "RealESRGAN_x4plus": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth",
         
     | 
| 226 | 
         
            +
                "RealESRNet_x4plus": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/RealESRNet_x4plus.pth",
         
     | 
| 227 | 
         
            +
                "RealESRGAN_x4plus_anime_6B": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth",
         
     | 
| 228 | 
         
            +
                "RealESRGAN_x2plus": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth",
         
     | 
| 229 | 
         
            +
                "realesr-animevideov3": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-animevideov3.pth",
         
     | 
| 230 | 
         
            +
                "realesr-general-x4v3": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth",
         
     | 
| 231 | 
         
            +
                "realesr-general-wdn-x4v3": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-wdn-x4v3.pth",
         
     | 
| 232 | 
         
            +
                "4x-UltraSharp": "https://huggingface.co/Shandypur/ESRGAN-4x-UltraSharp/resolve/main/4x-UltraSharp.pth",
         
     | 
| 233 | 
         
            +
                "4x_foolhardy_Remacri": "https://huggingface.co/FacehugmanIII/4x_foolhardy_Remacri/resolve/main/4x_foolhardy_Remacri.pth",
         
     | 
| 234 | 
         
            +
                "Remacri4xExtraSmoother": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/Remacri%204x%20ExtraSmoother.pth",
         
     | 
| 235 | 
         
            +
                "AnimeSharp4x": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/AnimeSharp%204x.pth",
         
     | 
| 236 | 
         
            +
                "lollypop": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/lollypop.pth",
         
     | 
| 237 | 
         
            +
                "RealisticRescaler4x": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/RealisticRescaler%204x.pth",
         
     | 
| 238 | 
         
            +
                "NickelbackFS4x": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/NickelbackFS%204x.pth"
         
     | 
| 239 | 
         
            +
            }
         
     | 
| 240 | 
         
            +
             
     | 
| 241 | 
         
            +
            UPSCALER_KEYS = list(UPSCALER_DICT_GUI.keys())
         
     | 
| 242 | 
         
            +
             
     | 
| 243 | 
         
            +
            PROMPT_W_OPTIONS = [
         
     | 
| 244 | 
         
            +
                ("Compel format: (word)weight", "Compel"),
         
     | 
| 245 | 
         
            +
                ("Classic format: (word:weight)", "Classic"),
         
     | 
| 246 | 
         
            +
                ("Classic-original format: (word:weight)", "Classic-original"),
         
     | 
| 247 | 
         
            +
                ("Classic-no_norm format: (word:weight)", "Classic-no_norm"),
         
     | 
| 248 | 
         
            +
                ("Classic-ignore", "Classic-ignore"),
         
     | 
| 249 | 
         
            +
                ("None", "None"),
         
     | 
| 250 | 
         
            +
            ]
         
     | 
| 251 | 
         
            +
             
     | 
| 252 | 
         
            +
            WARNING_MSG_VAE = (
         
     | 
| 253 | 
         
            +
                "Use the right VAE for your model to maintain image quality. The wrong"
         
     | 
| 254 | 
         
            +
                " VAE can lead to poor results, like blurriness in the generated images."
         
     | 
| 255 | 
         
            +
            )
         
     | 
| 256 | 
         
            +
             
     | 
| 257 | 
         
            +
            SDXL_TASK = [k for k, v in TASK_STABLEPY.items() if v in SDXL_TASKS]
         
     | 
| 258 | 
         
            +
            SD_TASK = [k for k, v in TASK_STABLEPY.items() if v in SD15_TASKS]
         
     | 
| 259 | 
         
            +
            FLUX_TASK = list(TASK_STABLEPY.keys())[:3] + [k for k, v in TASK_STABLEPY.items() if v in FLUX_CN_UNION_MODES.keys()]
         
     | 
| 260 | 
         
            +
             
     | 
| 261 | 
         
            +
            MODEL_TYPE_TASK = {
         
     | 
| 262 | 
         
            +
                "SD 1.5": SD_TASK,
         
     | 
| 263 | 
         
            +
                "SDXL": SDXL_TASK,
         
     | 
| 264 | 
         
            +
                "FLUX": FLUX_TASK,
         
     | 
| 265 | 
         
            +
            }
         
     | 
| 266 | 
         
            +
             
     | 
| 267 | 
         
            +
            MODEL_TYPE_CLASS = {
         
     | 
| 268 | 
         
            +
                "diffusers:StableDiffusionPipeline": "SD 1.5",
         
     | 
| 269 | 
         
            +
                "diffusers:StableDiffusionXLPipeline": "SDXL",
         
     | 
| 270 | 
         
            +
                "diffusers:FluxPipeline": "FLUX",
         
     | 
| 271 | 
         
            +
            }
         
     | 
| 272 | 
         
            +
             
     | 
| 273 | 
         
            +
            POST_PROCESSING_SAMPLER = ["Use same sampler"] + scheduler_names[:-2]
         
     | 
| 274 | 
         
            +
             
     | 
| 275 | 
         
            +
            SUBTITLE_GUI = (
         
     | 
| 276 | 
         
            +
                "### This demo uses [diffusers](https://github.com/huggingface/diffusers)"
         
     | 
| 277 | 
         
            +
                " to perform different tasks in image generation."
         
     | 
| 278 | 
         
            +
            )
         
     | 
| 279 | 
         
            +
             
     | 
| 280 | 
         
            +
            HELP_GUI = (
         
     | 
| 281 | 
         
            +
                """### Help:
         
     | 
| 282 | 
         
            +
                - 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'.
         
     | 
| 283 | 
         
            +
                - 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'.
         
     | 
| 284 | 
         
            +
                - For better results with Pony Diffusion, try using sampler DPM++ 1s or DPM2 with Compel or Classic prompt weights.
         
     | 
| 285 | 
         
            +
                """
         
     | 
| 286 | 
         
            +
            )
         
     | 
| 287 | 
         
            +
             
     | 
| 288 | 
         
            +
            EXAMPLES_GUI_HELP = (
         
     | 
| 289 | 
         
            +
                """### The following examples perform specific tasks:
         
     | 
| 290 | 
         
            +
                1. Generation with SDXL and upscale
         
     | 
| 291 | 
         
            +
                2. Generation with FLUX dev
         
     | 
| 292 | 
         
            +
                3. ControlNet Canny SDXL
         
     | 
| 293 | 
         
            +
                4. Optical pattern (Optical illusion) SDXL
         
     | 
| 294 | 
         
            +
                5. Convert an image to a coloring drawing
         
     | 
| 295 | 
         
            +
                6. ControlNet OpenPose SD 1.5 and Latent upscale
         
     | 
| 296 | 
         
            +
             
     | 
| 297 | 
         
            +
                - 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.
         
     | 
| 298 | 
         
            +
                """
         
     | 
| 299 | 
         
            +
            )
         
     | 
| 300 | 
         
            +
             
     | 
| 301 | 
         
            +
            EXAMPLES_GUI = [
         
     | 
| 302 | 
         
            +
                [
         
     | 
| 303 | 
         
            +
                    "1girl, souryuu asuka langley, neon genesis evangelion, rebuild of evangelion, lance of longinus, cat hat, plugsuit, pilot suit, red bodysuit, sitting, crossed legs, black eye patch, throne, looking down, from bottom, looking at viewer, outdoors, (masterpiece), (best quality), (ultra-detailed), very aesthetic, illustration, disheveled hair, perfect composition, moist skin, intricate details",
         
     | 
| 304 | 
         
            +
                    "nfsw, lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, unfinished, very displeasing, oldest, early, chromatic aberration, artistic error, scan, abstract",
         
     | 
| 305 | 
         
            +
                    28,
         
     | 
| 306 | 
         
            +
                    7.0,
         
     | 
| 307 | 
         
            +
                    -1,
         
     | 
| 308 | 
         
            +
                    "None",
         
     | 
| 309 | 
         
            +
                    0.33,
         
     | 
| 310 | 
         
            +
                    "Euler a",
         
     | 
| 311 | 
         
            +
                    1152,
         
     | 
| 312 | 
         
            +
                    896,
         
     | 
| 313 | 
         
            +
                    "cagliostrolab/animagine-xl-3.1",
         
     | 
| 314 | 
         
            +
                    "txt2img",
         
     | 
| 315 | 
         
            +
                    "image.webp",  # img conttol
         
     | 
| 316 | 
         
            +
                    1024,  # img resolution
         
     | 
| 317 | 
         
            +
                    0.35,  # strength
         
     | 
| 318 | 
         
            +
                    1.0,  # cn scale
         
     | 
| 319 | 
         
            +
                    0.0,  # cn start
         
     | 
| 320 | 
         
            +
                    1.0,  # cn end
         
     | 
| 321 | 
         
            +
                    "Classic",
         
     | 
| 322 | 
         
            +
                    "Nearest",
         
     | 
| 323 | 
         
            +
                    45,
         
     | 
| 324 | 
         
            +
                    False,
         
     | 
| 325 | 
         
            +
                ],
         
     | 
| 326 | 
         
            +
                [
         
     | 
| 327 | 
         
            +
                    "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",
         
     | 
| 328 | 
         
            +
                    "",
         
     | 
| 329 | 
         
            +
                    24,
         
     | 
| 330 | 
         
            +
                    3.5,
         
     | 
| 331 | 
         
            +
                    -1,
         
     | 
| 332 | 
         
            +
                    "None",
         
     | 
| 333 | 
         
            +
                    0.33,
         
     | 
| 334 | 
         
            +
                    "Euler a",
         
     | 
| 335 | 
         
            +
                    1152,
         
     | 
| 336 | 
         
            +
                    896,
         
     | 
| 337 | 
         
            +
                    "black-forest-labs/FLUX.1-dev",
         
     | 
| 338 | 
         
            +
                    "txt2img",
         
     | 
| 339 | 
         
            +
                    None,  # img conttol
         
     | 
| 340 | 
         
            +
                    1024,  # img resolution
         
     | 
| 341 | 
         
            +
                    0.35,  # strength
         
     | 
| 342 | 
         
            +
                    1.0,  # cn scale
         
     | 
| 343 | 
         
            +
                    0.0,  # cn start
         
     | 
| 344 | 
         
            +
                    1.0,  # cn end
         
     | 
| 345 | 
         
            +
                    "Classic",
         
     | 
| 346 | 
         
            +
                    None,
         
     | 
| 347 | 
         
            +
                    70,
         
     | 
| 348 | 
         
            +
                    True,
         
     | 
| 349 | 
         
            +
                ],
         
     | 
| 350 | 
         
            +
                [
         
     | 
| 351 | 
         
            +
                    "((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",
         
     | 
| 352 | 
         
            +
                    "(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",
         
     | 
| 353 | 
         
            +
                    48,
         
     | 
| 354 | 
         
            +
                    3.5,
         
     | 
| 355 | 
         
            +
                    -1,
         
     | 
| 356 | 
         
            +
                    "None",
         
     | 
| 357 | 
         
            +
                    0.33,
         
     | 
| 358 | 
         
            +
                    "DPM++ 2M SDE Lu",
         
     | 
| 359 | 
         
            +
                    1024,
         
     | 
| 360 | 
         
            +
                    1024,
         
     | 
| 361 | 
         
            +
                    "misri/epicrealismXL_v7FinalDestination",
         
     | 
| 362 | 
         
            +
                    "canny ControlNet",
         
     | 
| 363 | 
         
            +
                    "image.webp",  # img conttol
         
     | 
| 364 | 
         
            +
                    1024,  # img resolution
         
     | 
| 365 | 
         
            +
                    0.35,  # strength
         
     | 
| 366 | 
         
            +
                    1.0,  # cn scale
         
     | 
| 367 | 
         
            +
                    0.0,  # cn start
         
     | 
| 368 | 
         
            +
                    1.0,  # cn end
         
     | 
| 369 | 
         
            +
                    "Classic",
         
     | 
| 370 | 
         
            +
                    None,
         
     | 
| 371 | 
         
            +
                    44,
         
     | 
| 372 | 
         
            +
                    False,
         
     | 
| 373 | 
         
            +
                ],
         
     | 
| 374 | 
         
            +
                [
         
     | 
| 375 | 
         
            +
                    "cinematic scenery old city ruins",
         
     | 
| 376 | 
         
            +
                    "(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)",
         
     | 
| 377 | 
         
            +
                    50,
         
     | 
| 378 | 
         
            +
                    4.0,
         
     | 
| 379 | 
         
            +
                    -1,
         
     | 
| 380 | 
         
            +
                    "None",
         
     | 
| 381 | 
         
            +
                    0.33,
         
     | 
| 382 | 
         
            +
                    "Euler a",
         
     | 
| 383 | 
         
            +
                    1024,
         
     | 
| 384 | 
         
            +
                    1024,
         
     | 
| 385 | 
         
            +
                    "misri/juggernautXL_juggernautX",
         
     | 
| 386 | 
         
            +
                    "optical pattern ControlNet",
         
     | 
| 387 | 
         
            +
                    "spiral_no_transparent.png",  # img conttol
         
     | 
| 388 | 
         
            +
                    1024,  # img resolution
         
     | 
| 389 | 
         
            +
                    0.35,  # strength
         
     | 
| 390 | 
         
            +
                    1.0,  # cn scale
         
     | 
| 391 | 
         
            +
                    0.05,  # cn start
         
     | 
| 392 | 
         
            +
                    0.75,  # cn end
         
     | 
| 393 | 
         
            +
                    "Classic",
         
     | 
| 394 | 
         
            +
                    None,
         
     | 
| 395 | 
         
            +
                    35,
         
     | 
| 396 | 
         
            +
                    False,
         
     | 
| 397 | 
         
            +
                ],
         
     | 
| 398 | 
         
            +
                [
         
     | 
| 399 | 
         
            +
                    "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",
         
     | 
| 400 | 
         
            +
                    "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",
         
     | 
| 401 | 
         
            +
                    20,
         
     | 
| 402 | 
         
            +
                    4.0,
         
     | 
| 403 | 
         
            +
                    -1,
         
     | 
| 404 | 
         
            +
                    "loras/Coloring_book_-_LineArt.safetensors",
         
     | 
| 405 | 
         
            +
                    1.0,
         
     | 
| 406 | 
         
            +
                    "DPM++ 2M SDE Karras",
         
     | 
| 407 | 
         
            +
                    1024,
         
     | 
| 408 | 
         
            +
                    1024,
         
     | 
| 409 | 
         
            +
                    "cagliostrolab/animagine-xl-3.1",
         
     | 
| 410 | 
         
            +
                    "lineart ControlNet",
         
     | 
| 411 | 
         
            +
                    "color_image.png",  # img conttol
         
     | 
| 412 | 
         
            +
                    896,  # img resolution
         
     | 
| 413 | 
         
            +
                    0.35,  # strength
         
     | 
| 414 | 
         
            +
                    1.0,  # cn scale
         
     | 
| 415 | 
         
            +
                    0.0,  # cn start
         
     | 
| 416 | 
         
            +
                    1.0,  # cn end
         
     | 
| 417 | 
         
            +
                    "Compel",
         
     | 
| 418 | 
         
            +
                    None,
         
     | 
| 419 | 
         
            +
                    35,
         
     | 
| 420 | 
         
            +
                    False,
         
     | 
| 421 | 
         
            +
                ],
         
     | 
| 422 | 
         
            +
                [
         
     | 
| 423 | 
         
            +
                    "1girl,face,curly hair,red hair,white background,",
         
     | 
| 424 | 
         
            +
                    "(worst quality:2),(low quality:2),(normal quality:2),lowres,watermark,",
         
     | 
| 425 | 
         
            +
                    38,
         
     | 
| 426 | 
         
            +
                    5.0,
         
     | 
| 427 | 
         
            +
                    -1,
         
     | 
| 428 | 
         
            +
                    "None",
         
     | 
| 429 | 
         
            +
                    0.33,
         
     | 
| 430 | 
         
            +
                    "DPM++ 2M SDE Karras",
         
     | 
| 431 | 
         
            +
                    512,
         
     | 
| 432 | 
         
            +
                    512,
         
     | 
| 433 | 
         
            +
                    "digiplay/majicMIX_realistic_v7",
         
     | 
| 434 | 
         
            +
                    "openpose ControlNet",
         
     | 
| 435 | 
         
            +
                    "image.webp",  # img conttol
         
     | 
| 436 | 
         
            +
                    1024,  # img resolution
         
     | 
| 437 | 
         
            +
                    0.35,  # strength
         
     | 
| 438 | 
         
            +
                    1.0,  # cn scale
         
     | 
| 439 | 
         
            +
                    0.0,  # cn start
         
     | 
| 440 | 
         
            +
                    0.9,  # cn end
         
     | 
| 441 | 
         
            +
                    "Compel",
         
     | 
| 442 | 
         
            +
                    "Latent (antialiased)",
         
     | 
| 443 | 
         
            +
                    46,
         
     | 
| 444 | 
         
            +
                    False,
         
     | 
| 445 | 
         
            +
                ],
         
     | 
| 446 | 
         
            +
            ]
         
     | 
| 447 | 
         
            +
             
     | 
| 448 | 
         
            +
            RESOURCES = (
         
     | 
| 449 | 
         
            +
                """### Resources
         
     | 
| 450 | 
         
            +
                - John6666's space has some great features you might find helpful [link](https://huggingface.co/spaces/John6666/DiffuseCraftMod).
         
     | 
| 451 | 
         
            +
                - You can also try the image generator in Colab’s free tier, which provides free GPU [link](https://github.com/R3gm/SD_diffusers_interactive).
         
     | 
| 452 | 
         
            +
                """
         
     | 
| 453 | 
         
            +
            )
         
     | 
    	
        utils.py
    ADDED
    
    | 
         @@ -0,0 +1,270 @@ 
     | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
| 
         | 
|
| 1 | 
         
            +
             
     | 
| 2 | 
         
            +
            import os
         
     | 
| 3 | 
         
            +
            import re
         
     | 
| 4 | 
         
            +
            import gradio as gr
         
     | 
| 5 | 
         
            +
            from constants import (
         
     | 
| 6 | 
         
            +
                DIFFUSERS_FORMAT_LORAS,
         
     | 
| 7 | 
         
            +
                CIVITAI_API_KEY,
         
     | 
| 8 | 
         
            +
                HF_TOKEN,
         
     | 
| 9 | 
         
            +
                MODEL_TYPE_CLASS,
         
     | 
| 10 | 
         
            +
                DIRECTORY_LORAS,
         
     | 
| 11 | 
         
            +
            )
         
     | 
| 12 | 
         
            +
            from huggingface_hub import HfApi
         
     | 
| 13 | 
         
            +
            from diffusers import DiffusionPipeline
         
     | 
| 14 | 
         
            +
            from huggingface_hub import model_info as model_info_data
         
     | 
| 15 | 
         
            +
            from diffusers.pipelines.pipeline_loading_utils import variant_compatible_siblings
         
     | 
| 16 | 
         
            +
            from pathlib import PosixPath
         
     | 
| 17 | 
         
            +
             
     | 
| 18 | 
         
            +
             
     | 
| 19 | 
         
            +
            def download_things(directory, url, hf_token="", civitai_api_key=""):
         
     | 
| 20 | 
         
            +
                url = url.strip()
         
     | 
| 21 | 
         
            +
             
     | 
| 22 | 
         
            +
                if "drive.google.com" in url:
         
     | 
| 23 | 
         
            +
                    original_dir = os.getcwd()
         
     | 
| 24 | 
         
            +
                    os.chdir(directory)
         
     | 
| 25 | 
         
            +
                    os.system(f"gdown --fuzzy {url}")
         
     | 
| 26 | 
         
            +
                    os.chdir(original_dir)
         
     | 
| 27 | 
         
            +
                elif "huggingface.co" in url:
         
     | 
| 28 | 
         
            +
                    url = url.replace("?download=true", "")
         
     | 
| 29 | 
         
            +
                    # url = urllib.parse.quote(url, safe=':/')  # fix encoding
         
     | 
| 30 | 
         
            +
                    if "/blob/" in url:
         
     | 
| 31 | 
         
            +
                        url = url.replace("/blob/", "/resolve/")
         
     | 
| 32 | 
         
            +
                    user_header = f'"Authorization: Bearer {hf_token}"'
         
     | 
| 33 | 
         
            +
                    if hf_token:
         
     | 
| 34 | 
         
            +
                        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 {url.split('/')[-1]}")
         
     | 
| 35 | 
         
            +
                    else:
         
     | 
| 36 | 
         
            +
                        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 {url.split('/')[-1]}")
         
     | 
| 37 | 
         
            +
                elif "civitai.com" in url:
         
     | 
| 38 | 
         
            +
                    if "?" in url:
         
     | 
| 39 | 
         
            +
                        url = url.split("?")[0]
         
     | 
| 40 | 
         
            +
                    if civitai_api_key:
         
     | 
| 41 | 
         
            +
                        url = url + f"?token={civitai_api_key}"
         
     | 
| 42 | 
         
            +
                        os.system(f"aria2c --console-log-level=error --summary-interval=10 -c -x 16 -k 1M -s 16 -d {directory} {url}")
         
     | 
| 43 | 
         
            +
                    else:
         
     | 
| 44 | 
         
            +
                        print("\033[91mYou need an API key to download Civitai models.\033[0m")
         
     | 
| 45 | 
         
            +
                else:
         
     | 
| 46 | 
         
            +
                    os.system(f"aria2c --console-log-level=error --summary-interval=10 -c -x 16 -k 1M -s 16 -d {directory} {url}")
         
     | 
| 47 | 
         
            +
             
     | 
| 48 | 
         
            +
             
     | 
| 49 | 
         
            +
            def get_model_list(directory_path):
         
     | 
| 50 | 
         
            +
                model_list = []
         
     | 
| 51 | 
         
            +
                valid_extensions = {'.ckpt', '.pt', '.pth', '.safetensors', '.bin'}
         
     | 
| 52 | 
         
            +
             
     | 
| 53 | 
         
            +
                for filename in os.listdir(directory_path):
         
     | 
| 54 | 
         
            +
                    if os.path.splitext(filename)[1] in valid_extensions:
         
     | 
| 55 | 
         
            +
                        # name_without_extension = os.path.splitext(filename)[0]
         
     | 
| 56 | 
         
            +
                        file_path = os.path.join(directory_path, filename)
         
     | 
| 57 | 
         
            +
                        # model_list.append((name_without_extension, file_path))
         
     | 
| 58 | 
         
            +
                        model_list.append(file_path)
         
     | 
| 59 | 
         
            +
                        print('\033[34mFILE: ' + file_path + '\033[0m')
         
     | 
| 60 | 
         
            +
                return model_list
         
     | 
| 61 | 
         
            +
             
     | 
| 62 | 
         
            +
             
     | 
| 63 | 
         
            +
            def extract_parameters(input_string):
         
     | 
| 64 | 
         
            +
                parameters = {}
         
     | 
| 65 | 
         
            +
                input_string = input_string.replace("\n", "")
         
     | 
| 66 | 
         
            +
             
     | 
| 67 | 
         
            +
                if "Negative prompt:" not in input_string:
         
     | 
| 68 | 
         
            +
                    if "Steps:" in input_string:
         
     | 
| 69 | 
         
            +
                        input_string = input_string.replace("Steps:", "Negative prompt: Steps:")
         
     | 
| 70 | 
         
            +
                    else:
         
     | 
| 71 | 
         
            +
                        print("Invalid metadata")
         
     | 
| 72 | 
         
            +
                        parameters["prompt"] = input_string
         
     | 
| 73 | 
         
            +
                        return parameters
         
     | 
| 74 | 
         
            +
             
     | 
| 75 | 
         
            +
                parm = input_string.split("Negative prompt:")
         
     | 
| 76 | 
         
            +
                parameters["prompt"] = parm[0].strip()
         
     | 
| 77 | 
         
            +
                if "Steps:" not in parm[1]:
         
     | 
| 78 | 
         
            +
                    print("Steps not detected")
         
     | 
| 79 | 
         
            +
                    parameters["neg_prompt"] = parm[1].strip()
         
     | 
| 80 | 
         
            +
                    return parameters
         
     | 
| 81 | 
         
            +
                parm = parm[1].split("Steps:")
         
     | 
| 82 | 
         
            +
                parameters["neg_prompt"] = parm[0].strip()
         
     | 
| 83 | 
         
            +
                input_string = "Steps:" + parm[1]
         
     | 
| 84 | 
         
            +
             
     | 
| 85 | 
         
            +
                # Extracting Steps
         
     | 
| 86 | 
         
            +
                steps_match = re.search(r'Steps: (\d+)', input_string)
         
     | 
| 87 | 
         
            +
                if steps_match:
         
     | 
| 88 | 
         
            +
                    parameters['Steps'] = int(steps_match.group(1))
         
     | 
| 89 | 
         
            +
             
     | 
| 90 | 
         
            +
                # Extracting Size
         
     | 
| 91 | 
         
            +
                size_match = re.search(r'Size: (\d+x\d+)', input_string)
         
     | 
| 92 | 
         
            +
                if size_match:
         
     | 
| 93 | 
         
            +
                    parameters['Size'] = size_match.group(1)
         
     | 
| 94 | 
         
            +
                    width, height = map(int, parameters['Size'].split('x'))
         
     | 
| 95 | 
         
            +
                    parameters['width'] = width
         
     | 
| 96 | 
         
            +
                    parameters['height'] = height
         
     | 
| 97 | 
         
            +
             
     | 
| 98 | 
         
            +
                # Extracting other parameters
         
     | 
| 99 | 
         
            +
                other_parameters = re.findall(r'(\w+): (.*?)(?=, \w+|$)', input_string)
         
     | 
| 100 | 
         
            +
                for param in other_parameters:
         
     | 
| 101 | 
         
            +
                    parameters[param[0]] = param[1].strip('"')
         
     | 
| 102 | 
         
            +
             
     | 
| 103 | 
         
            +
                return parameters
         
     | 
| 104 | 
         
            +
             
     | 
| 105 | 
         
            +
             
     | 
| 106 | 
         
            +
            def get_my_lora(link_url):
         
     | 
| 107 | 
         
            +
                for url in [url.strip() for url in link_url.split(',')]:
         
     | 
| 108 | 
         
            +
                    if not os.path.exists(f"./loras/{url.split('/')[-1]}"):
         
     | 
| 109 | 
         
            +
                        download_things(DIRECTORY_LORAS, url, HF_TOKEN, CIVITAI_API_KEY)
         
     | 
| 110 | 
         
            +
                new_lora_model_list = get_model_list(DIRECTORY_LORAS)
         
     | 
| 111 | 
         
            +
                new_lora_model_list.insert(0, "None")
         
     | 
| 112 | 
         
            +
                new_lora_model_list = new_lora_model_list + DIFFUSERS_FORMAT_LORAS
         
     | 
| 113 | 
         
            +
             
     | 
| 114 | 
         
            +
                return gr.update(
         
     | 
| 115 | 
         
            +
                    choices=new_lora_model_list
         
     | 
| 116 | 
         
            +
                ), gr.update(
         
     | 
| 117 | 
         
            +
                    choices=new_lora_model_list
         
     | 
| 118 | 
         
            +
                ), gr.update(
         
     | 
| 119 | 
         
            +
                    choices=new_lora_model_list
         
     | 
| 120 | 
         
            +
                ), gr.update(
         
     | 
| 121 | 
         
            +
                    choices=new_lora_model_list
         
     | 
| 122 | 
         
            +
                ), gr.update(
         
     | 
| 123 | 
         
            +
                    choices=new_lora_model_list
         
     | 
| 124 | 
         
            +
                ),
         
     | 
| 125 | 
         
            +
             
     | 
| 126 | 
         
            +
             
     | 
| 127 | 
         
            +
            def info_html(json_data, title, subtitle):
         
     | 
| 128 | 
         
            +
                return f"""
         
     | 
| 129 | 
         
            +
                    <div style='padding: 0; border-radius: 10px;'>
         
     | 
| 130 | 
         
            +
                        <p style='margin: 0; font-weight: bold;'>{title}</p>
         
     | 
| 131 | 
         
            +
                        <details>
         
     | 
| 132 | 
         
            +
                            <summary>Details</summary>
         
     | 
| 133 | 
         
            +
                            <p style='margin: 0; font-weight: bold;'>{subtitle}</p>
         
     | 
| 134 | 
         
            +
                        </details>
         
     | 
| 135 | 
         
            +
                    </div>
         
     | 
| 136 | 
         
            +
                    """
         
     | 
| 137 | 
         
            +
             
     | 
| 138 | 
         
            +
             
     | 
| 139 | 
         
            +
            def get_model_type(repo_id: str):
         
     | 
| 140 | 
         
            +
                api = HfApi(token=os.environ.get("HF_TOKEN"))  # if use private or gated model
         
     | 
| 141 | 
         
            +
                default = "SD 1.5"
         
     | 
| 142 | 
         
            +
                try:
         
     | 
| 143 | 
         
            +
                    model = api.model_info(repo_id=repo_id, timeout=5.0)
         
     | 
| 144 | 
         
            +
                    tags = model.tags
         
     | 
| 145 | 
         
            +
                    for tag in tags:
         
     | 
| 146 | 
         
            +
                        if tag in MODEL_TYPE_CLASS.keys(): return MODEL_TYPE_CLASS.get(tag, default)
         
     | 
| 147 | 
         
            +
                except Exception:
         
     | 
| 148 | 
         
            +
                    return default
         
     | 
| 149 | 
         
            +
                return default
         
     | 
| 150 | 
         
            +
             
     | 
| 151 | 
         
            +
             
     | 
| 152 | 
         
            +
            def restart_space(repo_id: str, factory_reboot: bool, token: str):
         
     | 
| 153 | 
         
            +
                api = HfApi(token=token)
         
     | 
| 154 | 
         
            +
                api.restart_space(repo_id=repo_id, factory_reboot=factory_reboot)
         
     | 
| 155 | 
         
            +
             
     | 
| 156 | 
         
            +
             
     | 
| 157 | 
         
            +
            def extract_exif_data(image):
         
     | 
| 158 | 
         
            +
                if image is None: return ""
         
     | 
| 159 | 
         
            +
             
     | 
| 160 | 
         
            +
                try:
         
     | 
| 161 | 
         
            +
                    metadata_keys = ['parameters', 'metadata', 'prompt', 'Comment']
         
     | 
| 162 | 
         
            +
             
     | 
| 163 | 
         
            +
                    for key in metadata_keys:
         
     | 
| 164 | 
         
            +
                        if key in image.info:
         
     | 
| 165 | 
         
            +
                            return image.info[key]
         
     | 
| 166 | 
         
            +
             
     | 
| 167 | 
         
            +
                    return str(image.info)
         
     | 
| 168 | 
         
            +
             
     | 
| 169 | 
         
            +
                except Exception as e:
         
     | 
| 170 | 
         
            +
                    return f"Error extracting metadata: {str(e)}"
         
     | 
| 171 | 
         
            +
             
     | 
| 172 | 
         
            +
             
     | 
| 173 | 
         
            +
            def create_mask_now(img, invert):
         
     | 
| 174 | 
         
            +
                import numpy as np
         
     | 
| 175 | 
         
            +
                import time
         
     | 
| 176 | 
         
            +
             
     | 
| 177 | 
         
            +
                time.sleep(0.5)
         
     | 
| 178 | 
         
            +
             
     | 
| 179 | 
         
            +
                transparent_image = img["layers"][0]
         
     | 
| 180 | 
         
            +
             
     | 
| 181 | 
         
            +
                # Extract the alpha channel
         
     | 
| 182 | 
         
            +
                alpha_channel = np.array(transparent_image)[:, :, 3]
         
     | 
| 183 | 
         
            +
             
     | 
| 184 | 
         
            +
                # Create a binary mask by thresholding the alpha channel
         
     | 
| 185 | 
         
            +
                binary_mask = alpha_channel > 1
         
     | 
| 186 | 
         
            +
             
     | 
| 187 | 
         
            +
                if invert:
         
     | 
| 188 | 
         
            +
                    print("Invert")
         
     | 
| 189 | 
         
            +
                    # Invert the binary mask so that the drawn shape is white and the rest is black
         
     | 
| 190 | 
         
            +
                    binary_mask = np.invert(binary_mask)
         
     | 
| 191 | 
         
            +
             
     | 
| 192 | 
         
            +
                # Convert the binary mask to a 3-channel RGB mask
         
     | 
| 193 | 
         
            +
                rgb_mask = np.stack((binary_mask,) * 3, axis=-1)
         
     | 
| 194 | 
         
            +
             
     | 
| 195 | 
         
            +
                # Convert the mask to uint8
         
     | 
| 196 | 
         
            +
                rgb_mask = rgb_mask.astype(np.uint8) * 255
         
     | 
| 197 | 
         
            +
             
     | 
| 198 | 
         
            +
                return img["background"], rgb_mask
         
     | 
| 199 | 
         
            +
             
     | 
| 200 | 
         
            +
             
     | 
| 201 | 
         
            +
            def download_diffuser_repo(repo_name: str, model_type: str, revision: str = "main", token=True):
         
     | 
| 202 | 
         
            +
             
     | 
| 203 | 
         
            +
                variant = None
         
     | 
| 204 | 
         
            +
                if token is True and not os.environ.get("HF_TOKEN"):
         
     | 
| 205 | 
         
            +
                    token = None
         
     | 
| 206 | 
         
            +
             
     | 
| 207 | 
         
            +
                if model_type == "SDXL":
         
     | 
| 208 | 
         
            +
                    info = model_info_data(
         
     | 
| 209 | 
         
            +
                        repo_name,
         
     | 
| 210 | 
         
            +
                        token=token,
         
     | 
| 211 | 
         
            +
                        revision=revision,
         
     | 
| 212 | 
         
            +
                        timeout=5.0,
         
     | 
| 213 | 
         
            +
                    )
         
     | 
| 214 | 
         
            +
             
     | 
| 215 | 
         
            +
                    filenames = {sibling.rfilename for sibling in info.siblings}
         
     | 
| 216 | 
         
            +
                    model_filenames, variant_filenames = variant_compatible_siblings(
         
     | 
| 217 | 
         
            +
                        filenames, variant="fp16"
         
     | 
| 218 | 
         
            +
                    )
         
     | 
| 219 | 
         
            +
             
     | 
| 220 | 
         
            +
                    if len(variant_filenames):
         
     | 
| 221 | 
         
            +
                        variant = "fp16"
         
     | 
| 222 | 
         
            +
             
     | 
| 223 | 
         
            +
                cached_folder = DiffusionPipeline.download(
         
     | 
| 224 | 
         
            +
                    pretrained_model_name=repo_name,
         
     | 
| 225 | 
         
            +
                    force_download=False,
         
     | 
| 226 | 
         
            +
                    token=token,
         
     | 
| 227 | 
         
            +
                    revision=revision,
         
     | 
| 228 | 
         
            +
                    # mirror="https://hf-mirror.com",
         
     | 
| 229 | 
         
            +
                    variant=variant,
         
     | 
| 230 | 
         
            +
                    use_safetensors=True,
         
     | 
| 231 | 
         
            +
                    trust_remote_code=False,
         
     | 
| 232 | 
         
            +
                    timeout=5.0,
         
     | 
| 233 | 
         
            +
                )
         
     | 
| 234 | 
         
            +
             
     | 
| 235 | 
         
            +
                if isinstance(cached_folder, PosixPath):
         
     | 
| 236 | 
         
            +
                    cached_folder = cached_folder.as_posix()
         
     | 
| 237 | 
         
            +
             
     | 
| 238 | 
         
            +
                # Task model
         
     | 
| 239 | 
         
            +
                # from huggingface_hub import hf_hub_download
         
     | 
| 240 | 
         
            +
                # hf_hub_download(
         
     | 
| 241 | 
         
            +
                #     task_model,
         
     | 
| 242 | 
         
            +
                #     filename="diffusion_pytorch_model.safetensors",  # fix fp16 variant
         
     | 
| 243 | 
         
            +
                # )
         
     | 
| 244 | 
         
            +
             
     | 
| 245 | 
         
            +
                return cached_folder
         
     | 
| 246 | 
         
            +
             
     | 
| 247 | 
         
            +
             
     | 
| 248 | 
         
            +
            def progress_step_bar(step, total):
         
     | 
| 249 | 
         
            +
                # Calculate the percentage for the progress bar width
         
     | 
| 250 | 
         
            +
                percentage = min(100, ((step / total) * 100))
         
     | 
| 251 | 
         
            +
             
     | 
| 252 | 
         
            +
                return f"""
         
     | 
| 253 | 
         
            +
                    <div style="position: relative; width: 100%; background-color: gray; border-radius: 5px; overflow: hidden;">
         
     | 
| 254 | 
         
            +
                        <div style="width: {percentage}%; height: 17px; background-color: #800080; transition: width 0.5s;"></div>
         
     | 
| 255 | 
         
            +
                        <div style="position: absolute; width: 100%; text-align: center; color: white; top: 0; line-height: 19px; font-size: 13px;">
         
     | 
| 256 | 
         
            +
                            {int(percentage)}%
         
     | 
| 257 | 
         
            +
                        </div>
         
     | 
| 258 | 
         
            +
                    </div>
         
     | 
| 259 | 
         
            +
                    """
         
     | 
| 260 | 
         
            +
             
     | 
| 261 | 
         
            +
             
     | 
| 262 | 
         
            +
            def html_template_message(msg):
         
     | 
| 263 | 
         
            +
                return f"""
         
     | 
| 264 | 
         
            +
                    <div style="position: relative; width: 100%; background-color: gray; border-radius: 5px; overflow: hidden;">
         
     | 
| 265 | 
         
            +
                        <div style="width: 0%; height: 17px; background-color: #800080; transition: width 0.5s;"></div>
         
     | 
| 266 | 
         
            +
                        <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;">
         
     | 
| 267 | 
         
            +
                            {msg}
         
     | 
| 268 | 
         
            +
                        </div>
         
     | 
| 269 | 
         
            +
                    </div>
         
     | 
| 270 | 
         
            +
                    """
         
     |