ReiPlush64 commited on
Commit
740353d
2 Parent(s): 1a17b1d 0731c3b

Merge branch #aipicasso/cool-japan-diffusion-latest-demo' into 'ReiPlush64/cool-japan-diffusion-latest-demo'

Browse files
Files changed (2) hide show
  1. app.py +10 -16
  2. requirements.txt +2 -8
app.py CHANGED
@@ -5,6 +5,7 @@ import gradio as gr
5
  import torch
6
  from PIL import Image
7
  import random
 
8
 
9
  import requests
10
 
@@ -14,15 +15,15 @@ import requests
14
 
15
  model_id = 'aipicasso/cool-japan-diffusion-2-1-2'
16
 
17
- scheduler = EulerAncestralDiscreteScheduler(prediction_type="v_prediction") # .from_pretrained(model_id) # , subfolder="scheduler"
18
- feature_extractor = CLIPImageProcessor() # .from_pretrained(model_id)
19
 
20
  pipe = StableDiffusionPipeline.from_pretrained(
21
  model_id,
22
  torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
23
  scheduler=scheduler)
24
- pipe.enable_xformers_memory_efficient_attention()
25
- pipe.enable_freeu(s1=0.9, s2=0.2, b1=1.4, b2=1.6)
26
  # b1: 1.4, b2: 1.6, s1: 0.9, s2: 0.2
27
  pipe_i2i = StableDiffusionImg2ImgPipeline.from_pretrained(
28
  model_id,
@@ -32,21 +33,22 @@ pipe_i2i = StableDiffusionImg2ImgPipeline.from_pretrained(
32
  safety_checker=None,
33
  feature_extractor=feature_extractor
34
  )
35
- pipe_i2i.enable_xformers_memory_efficient_attention()
36
 
37
  upscaler = StableDiffusionLatentUpscalePipeline.from_pretrained("alfredplpl/x2-latent-upscaler-for-anime", torch_dtype=torch.float16)
38
- upscaler.enable_xformers_memory_efficient_attention()
39
 
40
 
41
  if torch.cuda.is_available():
42
  pipe = pipe.to("cuda")
43
  pipe_i2i = pipe_i2i.to("cuda")
 
44
 
45
  def error_str(error, title="Error"):
46
  return f"""#### {title}
47
  {error}""" if error else ""
48
 
49
-
50
  def inference(prompt, guidance, steps, image_size="Square", seed=0, img=None, strength=0.5, neg_prompt="", cool_japan_type="Anime", disable_auto_prompt_correction=False):
51
 
52
  generator = torch.Generator('cuda').manual_seed(seed) if seed != 0 else None
@@ -142,7 +144,7 @@ def auto_prompt_correction(prompt_ui,neg_prompt_ui,cool_japan_type_ui,disable_au
142
  neg_prompt=f"(((deformed))), {neg_prompt}, girl, boy, photo, people, low quality, ui, error, lowres, jpeg artifacts, 2d, 3d, cg, text"
143
 
144
  return prompt,neg_prompt
145
-
146
  def txt_to_img(prompt, neg_prompt, guidance, steps, width, height, generator,superreso=False):
147
  global pipe, upscaler
148
  if(superreso):
@@ -155,8 +157,6 @@ def txt_to_img(prompt, neg_prompt, guidance, steps, width, height, generator,sup
155
  height = height,
156
  output_type="latent",
157
  generator = generator).images
158
- pipe=pipe.to("cpu")
159
- upscaler=upscaler.to("cuda")
160
  result = upscaler(
161
  prompt=prompt,
162
  negative_prompt = neg_prompt,
@@ -165,8 +165,6 @@ def txt_to_img(prompt, neg_prompt, guidance, steps, width, height, generator,sup
165
  guidance_scale=0,
166
  generator=generator,
167
  )
168
- pipe=pipe.to("cuda")
169
- upscaler=upscaler.to("cpu")
170
  else:
171
  result = pipe(
172
  prompt,
@@ -194,8 +192,6 @@ def img_to_img(prompt, neg_prompt, img, strength, guidance, steps, width, height
194
  #height = height,
195
  output_type="latent",
196
  generator = generator).images
197
- pipe=pipe.to("cpu")
198
- upscaler=upscaler.to("cuda")
199
  result = upscaler(
200
  prompt=prompt,
201
  negative_prompt = neg_prompt,
@@ -204,8 +200,6 @@ def img_to_img(prompt, neg_prompt, img, strength, guidance, steps, width, height
204
  guidance_scale=0,
205
  generator=generator,
206
  )
207
- pipe=pipe.to("cuda")
208
- upscaler=upscaler.to("cpu")
209
  else:
210
  result = pipe_i2i(
211
  prompt,
 
5
  import torch
6
  from PIL import Image
7
  import random
8
+ import spaces
9
 
10
  import requests
11
 
 
15
 
16
  model_id = 'aipicasso/cool-japan-diffusion-2-1-2'
17
 
18
+ scheduler = EulerAncestralDiscreteScheduler.from_pretrained(model_id, subfolder="scheduler")
19
+ feature_extractor = CLIPImageProcessor.from_pretrained(model_id)
20
 
21
  pipe = StableDiffusionPipeline.from_pretrained(
22
  model_id,
23
  torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
24
  scheduler=scheduler)
25
+ #pipe.enable_xformers_memory_efficient_attention()
26
+ #pipe.enable_freeu(s1=0.9, s2=0.2, b1=1.4, b2=1.6)
27
  # b1: 1.4, b2: 1.6, s1: 0.9, s2: 0.2
28
  pipe_i2i = StableDiffusionImg2ImgPipeline.from_pretrained(
29
  model_id,
 
33
  safety_checker=None,
34
  feature_extractor=feature_extractor
35
  )
36
+ #pipe_i2i.enable_xformers_memory_efficient_attention()
37
 
38
  upscaler = StableDiffusionLatentUpscalePipeline.from_pretrained("alfredplpl/x2-latent-upscaler-for-anime", torch_dtype=torch.float16)
39
+ #upscaler.enable_xformers_memory_efficient_attention()
40
 
41
 
42
  if torch.cuda.is_available():
43
  pipe = pipe.to("cuda")
44
  pipe_i2i = pipe_i2i.to("cuda")
45
+ upscaler=upscaler.to("cuda")
46
 
47
  def error_str(error, title="Error"):
48
  return f"""#### {title}
49
  {error}""" if error else ""
50
 
51
+ @spaces.GPU
52
  def inference(prompt, guidance, steps, image_size="Square", seed=0, img=None, strength=0.5, neg_prompt="", cool_japan_type="Anime", disable_auto_prompt_correction=False):
53
 
54
  generator = torch.Generator('cuda').manual_seed(seed) if seed != 0 else None
 
144
  neg_prompt=f"(((deformed))), {neg_prompt}, girl, boy, photo, people, low quality, ui, error, lowres, jpeg artifacts, 2d, 3d, cg, text"
145
 
146
  return prompt,neg_prompt
147
+
148
  def txt_to_img(prompt, neg_prompt, guidance, steps, width, height, generator,superreso=False):
149
  global pipe, upscaler
150
  if(superreso):
 
157
  height = height,
158
  output_type="latent",
159
  generator = generator).images
 
 
160
  result = upscaler(
161
  prompt=prompt,
162
  negative_prompt = neg_prompt,
 
165
  guidance_scale=0,
166
  generator=generator,
167
  )
 
 
168
  else:
169
  result = pipe(
170
  prompt,
 
192
  #height = height,
193
  output_type="latent",
194
  generator = generator).images
 
 
195
  result = upscaler(
196
  prompt=prompt,
197
  negative_prompt = neg_prompt,
 
200
  guidance_scale=0,
201
  generator=generator,
202
  )
 
 
203
  else:
204
  result = pipe_i2i(
205
  prompt,
requirements.txt CHANGED
@@ -1,9 +1,3 @@
1
- torch
2
- diffusers>=0.26.3
3
- transformers>=4.38.2
4
  accelerate
5
- ftfy
6
- triton
7
- xformers
8
- requests
9
- huggingface_hub>=0.21.4
 
 
 
 
1
  accelerate
2
+ transformers
3
+ diffusers