Manjushri commited on
Commit
3b1a716
1 Parent(s): 85e9d4f

Update app.py

Browse files

Bringing in FXL

Files changed (1) hide show
  1. app.py +35 -15
app.py CHANGED
@@ -3,28 +3,48 @@ import torch
3
  import numpy as np
4
  import modin.pandas as pd
5
  from PIL import Image
 
6
  from huggingface_hub import hf_hub_download
7
- from diffusers import StableDiffusion3Pipeline
8
 
9
- device = 'cuda' #if torch.cuda.is_available() else 'cpu'
10
  torch.cuda.max_memory_allocated(device=device)
11
  torch.cuda.empty_cache()
12
- SD3 = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3-medium-diffusers", torch_dtype=torch.float16).to(device)
13
-
14
- def genie (Prompt, negative_prompt, height, width, scale, steps, seed):
15
  generator = np.random.seed(0) if seed == 0 else torch.manual_seed(seed)
16
- torch.cuda.empty_cache()
17
- image=SD3(
18
- prompt=Prompt,
19
- height=height,
20
- width=width,
21
- negative_prompt=negative_prompt,
22
- guidance_scale=scale,
23
- num_images_per_prompt=1,
24
- num_inference_steps=steps).images[0]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  return image
26
 
27
- gr.Interface(fn=genie, inputs=[gr.Textbox(label='What you want the AI to generate. 77 Token Limit.'),
 
28
  gr.Textbox(label='What you Do Not want the AI to generate. 77 Token Limit'),
29
  gr.Slider(512, 1536, 1024, step=128, label='Height'),
30
  gr.Slider(512, 1536, 1024, step=128, label='Width'),
 
3
  import numpy as np
4
  import modin.pandas as pd
5
  from PIL import Image
6
+ from diffusers import DiffusionPipeline, StableDiffusion3Pipeline
7
  from huggingface_hub import hf_hub_download
 
8
 
9
+ 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):
 
14
  generator = np.random.seed(0) if seed == 0 else torch.manual_seed(seed)
15
+ if Model == "SD3":
16
+
17
+ torch.cuda.empty_cache()
18
+ image=SD3(
19
+ prompt=Prompt,
20
+ height=height,
21
+ width=width,
22
+ negative_prompt=negative_prompt,
23
+ guidance_scale=scale,
24
+ num_images_per_prompt=1,
25
+ num_inference_steps=steps).images[0]
26
+ if Model == "FXL":
27
+
28
+ torch.cuda.empty_cache()
29
+ torch.cuda.max_memory_allocated(device=device)
30
+ 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")
31
+ pipe.enable_xformers_memory_efficient_attention()
32
+ pipe = pipe.to(device)
33
+ torch.cuda.empty_cache()
34
+
35
+ torch.cuda.max_memory_allocated(device=device)
36
+ int_image = pipe(Prompt, negative_prompt=negative_prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=scale, output_type="latent").images
37
+ 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")
38
+ pipe.enable_xformers_memory_efficient_attention()
39
+ pipe = pipe.to(device)
40
+ torch.cuda.empty_cache()
41
+ image = pipe(Prompt, negative_prompt=negative_prompt, image=int_image, denoising_start=high_noise_frac).images[0]
42
+ torch.cuda.empty_cache()
43
+
44
  return image
45
 
46
+ gr.Interface(fn=genie, inputs=[gr.Radio(["SD3", "FXL"], value='SD3', label='Choose Model'),
47
+ gr.Textbox(label='What you want the AI to generate. 77 Token Limit.'),
48
  gr.Textbox(label='What you Do Not want the AI to generate. 77 Token Limit'),
49
  gr.Slider(512, 1536, 1024, step=128, label='Height'),
50
  gr.Slider(512, 1536, 1024, step=128, label='Width'),