Manjushri commited on
Commit
f606112
·
verified ·
1 Parent(s): d767ca6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -87
app.py CHANGED
@@ -10,112 +10,42 @@ device = 'cuda' if torch.cuda.is_available() else 'cpu'
10
  torch.cuda.max_memory_allocated(device=device)
11
  torch.cuda.empty_cache()
12
 
13
- def genie (Model, Prompt, negative_prompt, height, width, scale, steps, seed, refine, high_noise_frac, upscale):
14
  generator = np.random.seed(0) if seed == 0 else torch.manual_seed(seed)
15
 
16
  if Model == "PhotoReal":
17
- pipe = DiffusionPipeline.from_pretrained("circulus/canvers-real-v3.9.1", torch_dtype=torch.float16, safety_checker=None) if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("circulus/canvers-real-v3.8.1")
18
  pipe.enable_xformers_memory_efficient_attention()
19
  pipe = pipe.to(device)
20
  torch.cuda.empty_cache()
21
- if refine == "Yes":
22
- refiner = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", use_safetensors=True, torch_dtype=torch.float16, variant="fp16") if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0")
23
- refiner.enable_xformers_memory_efficient_attention()
24
- refiner = refiner.to(device)
25
- torch.cuda.empty_cache()
26
- int_image = pipe(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images
27
- image = refiner(Prompt, negative_prompt=negative_prompt, image=int_image, denoising_start=high_noise_frac).images[0]
28
- torch.cuda.empty_cache()
29
- return image
30
- else:
31
- image = pipe(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images[0]
32
- torch.cuda.empty_cache()
33
- return image
34
 
35
- if Model == "Animagine XL 3.0":
36
- animagine = DiffusionPipeline.from_pretrained("cagliostrolab/animagine-xl-3.0", torch_dtype=torch.float16, safety_checker=None) if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("cagliostrolab/animagine-xl-3.0")
 
 
 
 
37
  animagine.enable_xformers_memory_efficient_attention()
38
  animagine = animagine.to(device)
39
  torch.cuda.empty_cache()
40
- if refine == "Yes":
41
- torch.cuda.empty_cache()
42
- torch.cuda.max_memory_allocated(device=device)
43
- int_image = animagine(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale, output_type="latent").images
44
- torch.cuda.empty_cache()
45
- animagine = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", use_safetensors=True, torch_dtype=torch.float16, variant="fp16") if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0")
46
- animagine.enable_xformers_memory_efficient_attention()
47
- animagine = animagine.to(device)
48
- torch.cuda.empty_cache()
49
- image = animagine(Prompt, negative_prompt=negative_prompt, image=int_image, denoising_start=high_noise_frac).images[0]
50
- torch.cuda.empty_cache()
51
- return image
52
- else:
53
- image = animagine(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images[0]
54
- torch.cuda.empty_cache()
55
- return image
56
-
57
- if Model == "SDXL 1.0":
58
 
 
59
  torch.cuda.empty_cache()
60
- torch.cuda.max_memory_allocated(device=device)
61
- sdxl = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
62
- sdxl.enable_xformers_memory_efficient_attention()
63
- sdxl = sdxl.to(device)
64
- torch.cuda.empty_cache()
65
-
66
- if refine == "Yes":
67
- torch.cuda.max_memory_allocated(device=device)
68
- torch.cuda.empty_cache()
69
- image = sdxl(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale, output_type="latent").images
70
- torch.cuda.empty_cache()
71
- sdxl = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", use_safetensors=True, torch_dtype=torch.float16, variant="fp16") if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0")
72
- sdxl.enable_xformers_memory_efficient_attention()
73
- sdxl = sdxl.to(device)
74
- torch.cuda.empty_cache()
75
- refined = sdxl(Prompt, negative_prompt=negative_prompt, image=image, denoising_start=high_noise_frac).images[0]
76
- torch.cuda.empty_cache()
77
- return refined
78
- else:
79
- image = sdxl(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images[0]
80
- torch.cuda.empty_cache()
81
- return image
82
-
83
- if Model == 'FusionXL':
84
- torch.cuda.empty_cache()
85
- torch.cuda.max_memory_allocated(device=device)
86
- pipe = DiffusionPipeline.from_pretrained("circulus/canvers-fusionXL-v1", torch_dtype=torch.float16, safety_checker=None) if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("circulus/canvers-real-v3.8.1")
87
- pipe.enable_xformers_memory_efficient_attention()
88
- pipe = pipe.to(device)
89
- torch.cuda.empty_cache()
90
- if refine == "Yes":
91
- torch.cuda.empty_cache()
92
- torch.cuda.max_memory_allocated(device=device)
93
- int_image = pipe(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale, output_type="latent").images
94
- pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", use_safetensors=True, torch_dtype=torch.float16, variant="fp16") if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0")
95
- pipe.enable_xformers_memory_efficient_attention()
96
- pipe = pipe.to(device)
97
- torch.cuda.empty_cache()
98
- image = pipe(Prompt, negative_prompt=negative_prompt, image=int_image, denoising_start=high_noise_frac).images[0]
99
- torch.cuda.empty_cache()
100
- return image
101
- else:
102
- image = pipe(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images[0]
103
- torch.cuda.empty_cache()
104
- return image
105
 
 
106
  return image
107
 
108
- gr.Interface(fn=genie, inputs=[gr.Radio(['PhotoReal', 'Animagine XL 3.0', 'SDXL 1.0', 'FusionXL',], value='PhotoReal', label='Choose Model'),
109
  gr.Textbox(label='What you want the AI to generate. 77 Token Limit.'),
110
  gr.Textbox(label='What you Do Not want the AI to generate. 77 Token Limit'),
111
  gr.Slider(512, 1024, 768, step=128, label='Height'),
112
  gr.Slider(512, 1024, 768, step=128, label='Width'),
113
- gr.Slider(1, maximum=15, value=5, step=.25, label='Guidance Scale'),
114
- gr.Slider(5, maximum=100, value=50, step=5, label='Number of Iterations'),
115
  gr.Slider(minimum=0, step=1, maximum=9999999999999999, randomize=True, label='Seed: 0 is Random'),
116
- gr.Radio(["Yes", "No"], label='SDXL 1.0 Refiner: Use if the Image has too much Noise', value='No'),
117
- gr.Slider(minimum=.9, maximum=.99, value=.95, step=.01, label='Refiner Denoise Start %')],
118
  outputs=gr.Image(label='Generated Image'),
119
- title="Manju Dream Booth V2.1 with SDXL 1.0 Refiner - GPU",
120
  description="<br><br><b/>Warning: This Demo is capable of producing NSFW content.",
121
- article = "If You Enjoyed this Demo and would like to Donate, you can send any amount to any of these Wallets. <br><br>SHIB (BEP20): 0xbE8f2f3B71DFEB84E5F7E3aae1909d60658aB891 <br>PayPal: https://www.paypal.me/ManjushriBodhisattva <br>ETH: 0xbE8f2f3B71DFEB84E5F7E3aae1909d60658aB891 <br>DOGE: D9QdVPtcU1EFH8jDC8jhU9uBcSTqUiA8h6<br><br>Code Monkey: <a href=\"https://huggingface.co/Manjushri\">Manjushri</a>").launch(debug=True, max_threads=80)
 
10
  torch.cuda.max_memory_allocated(device=device)
11
  torch.cuda.empty_cache()
12
 
13
+ def genie (Model, Prompt, negative_prompt, height, width, scale, steps, seed):
14
  generator = np.random.seed(0) if seed == 0 else torch.manual_seed(seed)
15
 
16
  if Model == "PhotoReal":
17
+ pipe = DiffusionPipeline.from_pretrained("circulus/canvers-real-v3.9.1", torch_dtype=torch.float16, safety_checker=None) if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("circulus/canvers-real-v3.9.1")
18
  pipe.enable_xformers_memory_efficient_attention()
19
  pipe = pipe.to(device)
20
  torch.cuda.empty_cache()
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
+ image = pipe(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images[0]
23
+ torch.cuda.empty_cache()
24
+ return image
25
+
26
+ if Model == "Animagine XL 4":
27
+ animagine = DiffusionPipeline.from_pretrained("cagliostrolab/animagine-xl-4.0", torch_dtype=torch.float16, safety_checker=None) if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("cagliostrolab/animagine-xl-4.0")
28
  animagine.enable_xformers_memory_efficient_attention()
29
  animagine = animagine.to(device)
30
  torch.cuda.empty_cache()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
+ image = animagine(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale).images[0]
33
  torch.cuda.empty_cache()
34
+ return image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
+
37
  return image
38
 
39
+ gr.Interface(fn=genie, inputs=[gr.Radio(['PhotoReal', 'Animagine XL 4',], value='PhotoReal', label='Choose Model'),
40
  gr.Textbox(label='What you want the AI to generate. 77 Token Limit.'),
41
  gr.Textbox(label='What you Do Not want the AI to generate. 77 Token Limit'),
42
  gr.Slider(512, 1024, 768, step=128, label='Height'),
43
  gr.Slider(512, 1024, 768, step=128, label='Width'),
44
+ gr.Slider(3, maximum=12, value=5, step=.25, label='Guidance Scale', info="5-7 for PhotoReal and 7-10 for Animagine"),
45
+ gr.Slider(25, maximum=50, value=25, step=25, label='Number of Iterations'),
46
  gr.Slider(minimum=0, step=1, maximum=9999999999999999, randomize=True, label='Seed: 0 is Random'),
47
+ ],
 
48
  outputs=gr.Image(label='Generated Image'),
49
+ title="Manju Dream Booth V2.5 - GPU",
50
  description="<br><br><b/>Warning: This Demo is capable of producing NSFW content.",
51
+ article = "If You Enjoyed this Demo and would like to Donate, you can send any amount to any of these Wallets. <br><br>SHIB (BEP20): 0xbE8f2f3B71DFEB84E5F7E3aae1909d60658aB891 <br>PayPal: https://www.paypal.me/ManjushriBodhisattva <br>ETH: 0xbE8f2f3B71DFEB84E5F7E3aae1909d60658aB891 <br>DOGE: DL5qRkGCzB2ENBKfEhHarvKm1qas3wyHx7<br><br>Code Monkey: <a href=\"https://huggingface.co/Manjushri\">Manjushri</a>").launch(debug=True, max_threads=80)