Manjushri commited on
Commit
39c5f37
·
verified ·
1 Parent(s): 41ed172

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -2
app.py CHANGED
@@ -14,6 +14,7 @@ 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)
@@ -24,6 +25,7 @@ def genie (Model, Prompt, negative_prompt, height, width, scale, steps, seed):
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)
@@ -33,10 +35,24 @@ def genie (Model, Prompt, negative_prompt, height, width, scale, steps, seed):
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'),
 
14
  generator = np.random.seed(0) if seed == 0 else torch.manual_seed(seed)
15
 
16
  if Model == "PhotoReal":
17
+ torch.cuda.empty_cache()
18
  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")
19
  pipe.enable_xformers_memory_efficient_attention()
20
  pipe = pipe.to(device)
 
25
  return image
26
 
27
  if Model == "Animagine XL 4":
28
+ torch.cuda.empty_cache()
29
  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")
30
  animagine.enable_xformers_memory_efficient_attention()
31
  animagine = animagine.to(device)
 
35
  torch.cuda.empty_cache()
36
  return image
37
 
38
+ if Model == "SD3.5 Turbo":
39
+ progress=gr.Progress(track_tqdm=True)
40
+ torch.cuda.empty_cache()
41
+ model_repo_id = "stabilityai/stable-diffusion-3.5-large-turbo"
42
+
43
+ if torch.cuda.is_available():
44
+ torch_dtype = torch.bfloat16
45
+ else:
46
+ torch_dtype = torch.float32
47
+
48
+ pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
49
+ pipe = pipe.to(device)
50
+ torch.cuda.empty_cache()
51
+ image = pipe(prompt=Prompt, negative_prompt=negative_prompt, guidance_scale=0.0, num_inference_steps=4, width=1024, height=1024, generator=generator,).images[0]
52
+ torch.cuda.empty_cache()
53
  return image
54
 
55
+ gr.Interface(fn=genie, inputs=[gr.Radio(['PhotoReal', 'Animagine XL 4', "SD3.5 Turbo"], value='PhotoReal', label='Choose Model'),
56
  gr.Textbox(label='What you want the AI to generate. 77 Token Limit.'),
57
  gr.Textbox(label='What you Do Not want the AI to generate. 77 Token Limit'),
58
  gr.Slider(512, 1024, 768, step=128, label='Height'),