sandz7 commited on
Commit
3a87f05
Β·
1 Parent(s): 1ebf69d

added sliders to the interface

Browse files
Files changed (1) hide show
  1. app.py +45 -7
app.py CHANGED
@@ -12,22 +12,39 @@ DESCRIPTION = '''
12
  </div>
13
  '''
14
 
15
- # pipeline
16
- pipeline = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, use_safetensors=True, variant="fp16").to('cuda')
 
 
 
 
 
 
17
 
18
  # function to take input and generate text tokena
19
  @spaces.GPU(duration=120)
20
  def osiris(prompt: str,
21
  history: list,
22
- temperature: float,
23
- max_new_tokens: int):
24
  """
25
  Takes input, passes it into the pipeline,
26
  get the top 5 scores, and ouput those scores into images
27
  """
28
 
29
  # Generate image based on text
30
- image = pipeline(prompt=prompt).images[0]
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  return image
33
 
@@ -38,8 +55,29 @@ with gr.Blocks(fill_height=True) as demo:
38
  inputs="text",
39
  outputs="image",
40
  fill_height=True,
41
- # additional_inputs_accordion=gr.Accordion(label="βš™οΈ Parameters", open=False, render=False),
42
- # additional_inputs=[]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  )
44
 
45
  if __name__ == "__main__":
 
12
  </div>
13
  '''
14
 
15
+ # load both base and refiner
16
+ base = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, use_safetensors=True, variant="fp16").to('cuda')
17
+ refiner = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0",
18
+ text_encoder_2=base.text_encoder_2,
19
+ vae=base.vae,
20
+ torch_dtype=torch.float16,
21
+ use_safetensor=True,
22
+ variant="fp16").to('cuda')
23
 
24
  # function to take input and generate text tokena
25
  @spaces.GPU(duration=120)
26
  def osiris(prompt: str,
27
  history: list,
28
+ n_steps: int,
29
+ high_noise_frac: float):
30
  """
31
  Takes input, passes it into the pipeline,
32
  get the top 5 scores, and ouput those scores into images
33
  """
34
 
35
  # Generate image based on text
36
+ image_base = base(
37
+ prompt=prompt,
38
+ num_inference_steps=n_steps,
39
+ denoising_end=high_noise_frac,
40
+ output_type="latent"
41
+ ).images
42
+ image = refiner(
43
+ prompt=prompt,
44
+ num_inference_steps=n_steps,
45
+ denoising_start=high_noise_frac,
46
+ image=image_base
47
+ ).images[0]
48
 
49
  return image
50
 
 
55
  inputs="text",
56
  outputs="image",
57
  fill_height=True,
58
+ additional_inputs_accordion=gr.Accordion(label="βš™οΈ Parameters", open=False, render=False),
59
+ additional_inputs=[
60
+ gr.Slider(minimum=20,
61
+ maximum=100,
62
+ step=1,
63
+ value=40,
64
+ label="Number of Inference Steps",
65
+ render=False),
66
+ gr.Slider(minimum=0,
67
+ maximum=1,
68
+ step=0.1,
69
+ value=0.8,
70
+ label="High Noise Fraction",
71
+ render=False),
72
+ ],
73
+ examples=[
74
+ ["A sprawling cyberpunk metropolis at dusk, with towering skyscrapers adorned with neon signs, holographic billboards, and flying cars weaving through the sky. On a crowded street corner, a cybernetically enhanced street artist creates mesmerizing light sculptures with their augmented reality gloves. Rain glistens on the bustling sidewalks as pedestrians with colorful umbrellas rush past."],
75
+ ["A mystical enchanted forest bathed in twilight, where bioluminescent plants cast an ethereal glow. A crystal-clear waterfall cascades into a shimmering pool, surrounded by ancient trees with twisted roots. A lone elf archer, dressed in elegant green and gold attire, stands on a moss-covered rock, her bow drawn as she watches over the tranquil scene. Ethereal fairies with delicate wings flutter around, leaving trails of sparkling dust in the air."],
76
+ ["An elaborate steampunk dirigible floating gracefully above a cloud-covered landscape. The airship, with its brass and copper gears, massive steam-powered engines, and ornate Victorian design, cruises past a golden sunset. A distinguished gentleman in a top hat and goggles stands on the observation deck, holding a brass spyglass to his eye as he surveys the horizon. Passengers in vintage attire marvel at the view."],
77
+ ["A charming, snow-covered log cabin nestled in the heart of a tranquil mountain range during a starry winter night. Smoke gently curls from the stone chimney, and warm light spills from the windows, illuminating the cozy interior. A young woman in a thick woolen coat and a fur-lined hat stands by the front door, holding a lantern that casts a warm glow on the snow. Pine trees, heavy with snow, frame the scene, while the Northern Lights dance across the sky."],
78
+ ["A vibrant underwater kingdom where a colorful coral reef teems with marine life. Schools of iridescent fish swim through the crystal-clear waters, and a sunken pirate ship, encrusted with barnacles and treasure chests, rests on the sandy seabed. A curious mermaid with flowing turquoise hair and a shimmering silver tail explores the depths, holding a glowing pearl in her hand. Playful dolphins swim around her, and a wise old sea turtle watches from a nearby rock."]
79
+ ],
80
+ cache_examples=False
81
  )
82
 
83
  if __name__ == "__main__":