Manjushri commited on
Commit
01807fb
1 Parent(s): f1f51db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -3,16 +3,20 @@ import torch
3
  import numpy as np
4
  import modin.pandas as pd
5
  from PIL import Image
6
- from diffusers import DiffusionPipeline
7
 
8
  device = "cuda" if torch.cuda.is_available() else "cpu"
9
  pipe = DiffusionPipeline.from_pretrained("prompthero/openjourney-v4", torch_dtype=torch.float16, safety_checker=None)
 
 
10
  pipe = pipe.to(device)
11
 
12
  def genie (prompt, scale, steps, Seed):
13
- generator = torch.Generator(device=device).manual_seed(Seed)
14
- images = pipe(prompt, num_inference_steps=steps, guidance_scale=scale, generator=generator).images[0]
15
- return images
 
 
16
 
17
  gr.Interface(fn=genie, inputs=[gr.Textbox(label='What you want the AI to generate. 77 Token Limit.'),
18
  gr.Slider(1, maximum=25, value=10, step=.25, label='Prompt Guidance Scale:', interactive=True),
 
3
  import numpy as np
4
  import modin.pandas as pd
5
  from PIL import Image
6
+ from diffusers import DiffusionPipeline, StableDiffusionLatentUpscalePipeline
7
 
8
  device = "cuda" if torch.cuda.is_available() else "cpu"
9
  pipe = DiffusionPipeline.from_pretrained("prompthero/openjourney-v4", torch_dtype=torch.float16, safety_checker=None)
10
+ upscaler = StableDiffusionLatentUpscalePipeline.from_pretrained("stabilityai/sd-x2-latent-upscaler", torch_dtype=torch.float16)
11
+ upscaler = upscaler.to(device)
12
  pipe = pipe.to(device)
13
 
14
  def genie (prompt, scale, steps, Seed):
15
+ generator = torch.Generator(device=device).manual_seed(Seed)
16
+ #images = pipe(prompt, num_inference_steps=steps, guidance_scale=scale, generator=generator).images[0]
17
+ low_res_latents = pipeline(prompt, num_inference_steps=steps, guidance_scale=scale, generator=generator, output_type="latent").images
18
+ upscaled_image = upscaler(prompt=prompt, image=low_res_latents, num_inference_steps=20, guidance_scale=0, generator=generator).images[0]
19
+ return upscaled_image
20
 
21
  gr.Interface(fn=genie, inputs=[gr.Textbox(label='What you want the AI to generate. 77 Token Limit.'),
22
  gr.Slider(1, maximum=25, value=10, step=.25, label='Prompt Guidance Scale:', interactive=True),