Bobby commited on
Commit
ef7f209
·
1 Parent(s): 337889a

gr no reload again

Browse files
Files changed (1) hide show
  1. app.py +58 -58
app.py CHANGED
@@ -31,70 +31,70 @@ preprocessor = Preprocessor()
31
 
32
  import spaces
33
 
34
- # if gr.NO_RELOAD:
35
- torch.cuda.max_memory_allocated(device="cuda")
36
- # Controlnet Normal
37
- model_id = "lllyasviel/control_v11p_sd15_normalbae"
38
- print("initializing controlnet")
39
- controlnet = ControlNetModel.from_pretrained(
40
- model_id,
41
- torch_dtype=torch.float16,
42
- attn_implementation="flash_attention_2",
43
- ).to("cuda")
44
 
45
- # Scheduler
46
- scheduler = DPMSolverMultistepScheduler.from_pretrained(
47
- "runwayml/stable-diffusion-v1-5",
48
- solver_order=2,
49
- subfolder="scheduler",
50
- use_karras_sigmas=True,
51
- final_sigmas_type="sigma_min",
52
- algorithm_type="sde-dpmsolver++",
53
- prediction_type="epsilon",
54
- thresholding=False,
55
- denoise_final=True,
56
- device_map="cuda",
57
- torch_dtype=torch.float16,
58
- )
59
 
60
- # Stable Diffusion Pipeline URL
61
- # base_model_url = "https://huggingface.co/broyang/hentaidigitalart_v20/blob/main/realcartoon3d_v15.safetensors"
62
- base_model_url = "https://huggingface.co/Lykon/AbsoluteReality/blob/main/AbsoluteReality_1.8.1_pruned.safetensors"
63
- vae_url = "https://huggingface.co/stabilityai/sd-vae-ft-mse-original/blob/main/vae-ft-mse-840000-ema-pruned.safetensors"
64
 
65
- vae = AutoencoderKL.from_single_file(vae_url, torch_dtype=torch.float16).to("cuda")
66
- vae.to(memory_format=torch.channels_last)
67
 
68
- pipe = StableDiffusionControlNetPipeline.from_single_file(
69
- base_model_url,
70
- # safety_checker=None,
71
- # load_safety_checker=True,
72
- controlnet=controlnet,
73
- scheduler=scheduler,
74
- vae=vae,
75
- torch_dtype=torch.float16,
76
- )
77
 
78
- pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="EasyNegativeV2.safetensors", token="EasyNegativeV2",)
79
- pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="badhandv4.pt", token="badhandv4")
80
- pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="fcNeg-neg.pt", token="fcNeg-neg")
81
- pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Ahegao.pt", token="HDA_Ahegao")
82
- pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Bondage.pt", token="HDA_Bondage")
83
- pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_pet_play.pt", token="HDA_pet_play")
84
- pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_unconventional maid.pt", token="HDA_unconventional_maid")
85
- pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_NakedHoodie.pt", token="HDA_NakedHoodie")
86
- pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_NunDress.pt", token="HDA_NunDress")
87
- pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Shibari.pt", token="HDA_Shibari")
88
- pipe.to("cuda")
89
- print("---------------Loaded controlnet pipeline---------------")
90
 
91
- @spaces.GPU(duration=12)
92
- def init(pipe):
93
- pipe.enable_xformers_memory_efficient_attention()
94
- pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
95
- pipe.unet.set_attn_processor(AttnProcessor2_0())
96
- print("Model Compiled!")
97
- init(pipe)
98
 
99
  def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
100
  if randomize_seed:
 
31
 
32
  import spaces
33
 
34
+ if gr.NO_RELOAD:
35
+ torch.cuda.max_memory_allocated(device="cuda")
36
+ # Controlnet Normal
37
+ model_id = "lllyasviel/control_v11p_sd15_normalbae"
38
+ print("initializing controlnet")
39
+ controlnet = ControlNetModel.from_pretrained(
40
+ model_id,
41
+ torch_dtype=torch.float16,
42
+ attn_implementation="flash_attention_2",
43
+ ).to("cuda")
44
 
45
+ # Scheduler
46
+ scheduler = DPMSolverMultistepScheduler.from_pretrained(
47
+ "runwayml/stable-diffusion-v1-5",
48
+ solver_order=2,
49
+ subfolder="scheduler",
50
+ use_karras_sigmas=True,
51
+ final_sigmas_type="sigma_min",
52
+ algorithm_type="sde-dpmsolver++",
53
+ prediction_type="epsilon",
54
+ thresholding=False,
55
+ denoise_final=True,
56
+ device_map="cuda",
57
+ torch_dtype=torch.float16,
58
+ )
59
 
60
+ # Stable Diffusion Pipeline URL
61
+ # base_model_url = "https://huggingface.co/broyang/hentaidigitalart_v20/blob/main/realcartoon3d_v15.safetensors"
62
+ base_model_url = "https://huggingface.co/Lykon/AbsoluteReality/blob/main/AbsoluteReality_1.8.1_pruned.safetensors"
63
+ vae_url = "https://huggingface.co/stabilityai/sd-vae-ft-mse-original/blob/main/vae-ft-mse-840000-ema-pruned.safetensors"
64
 
65
+ vae = AutoencoderKL.from_single_file(vae_url, torch_dtype=torch.float16).to("cuda")
66
+ vae.to(memory_format=torch.channels_last)
67
 
68
+ pipe = StableDiffusionControlNetPipeline.from_single_file(
69
+ base_model_url,
70
+ # safety_checker=None,
71
+ # load_safety_checker=True,
72
+ controlnet=controlnet,
73
+ scheduler=scheduler,
74
+ vae=vae,
75
+ torch_dtype=torch.float16,
76
+ )
77
 
78
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="EasyNegativeV2.safetensors", token="EasyNegativeV2",)
79
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="badhandv4.pt", token="badhandv4")
80
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="fcNeg-neg.pt", token="fcNeg-neg")
81
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Ahegao.pt", token="HDA_Ahegao")
82
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Bondage.pt", token="HDA_Bondage")
83
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_pet_play.pt", token="HDA_pet_play")
84
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_unconventional maid.pt", token="HDA_unconventional_maid")
85
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_NakedHoodie.pt", token="HDA_NakedHoodie")
86
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_NunDress.pt", token="HDA_NunDress")
87
+ pipe.load_textual_inversion("broyang/hentaidigitalart_v20", weight_name="HDA_Shibari.pt", token="HDA_Shibari")
88
+ pipe.to("cuda")
89
+ print("---------------Loaded controlnet pipeline---------------")
90
 
91
+ @spaces.GPU(duration=12)
92
+ def init(pipe):
93
+ pipe.enable_xformers_memory_efficient_attention()
94
+ pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
95
+ pipe.unet.set_attn_processor(AttnProcessor2_0())
96
+ print("Model Compiled!")
97
+ init(pipe)
98
 
99
  def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
100
  if randomize_seed: