spsancti commited on
Commit
1c3d6f9
·
1 Parent(s): 7130dc7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -6,10 +6,11 @@ from PIL import Image, ImageOps
6
 
7
 
8
  # Load pipeline once
9
- model_id = 'Deci/DeciDiffusion-v1-0'
10
  device = "cuda" if torch.cuda.is_available() else "cpu"
11
- pipe = StableDiffusionPipeline.from_pretrained(model_id, custom_pipeline=model_id, torch_dtype=torch.float32)
12
- pipe.unet = pipe.unet.from_pretrained(model_id, subfolder='flexible_unet', torch_dtype=torch.float32)
 
 
13
  pipe = pipe.to(device)
14
 
15
 
@@ -22,13 +23,14 @@ def read_content(file_path: str) -> str:
22
  return content
23
 
24
 
25
- def predict(_prompt: str, _steps: int = 30, _seed: int = 42, _guidance_scale: float = 7.5, _negative_prompt: str = ""):
26
  _negative_prompt = [_negative_prompt] if _negative_prompt else None
27
 
28
  output = pipe(prompt=[_prompt],
29
  negative_prompt=_negative_prompt,
30
- num_inference_steps=int(_steps),
31
  guidance_scale=_guidance_scale,
 
32
  generator=torch.Generator(device).manual_seed(_seed),
33
  )
34
  output_image = output.images[0]
@@ -79,9 +81,10 @@ with demo:
79
 
80
  with gr.Accordion(label="Advanced Settings", open=False):
81
  with gr.Row(mobile_collapse=False, equal_height=True):
82
- steps = gr.Slider(value=30, minimum=15, maximum=50, step=1, label="steps", interactive=True)
83
  seed = gr.Slider(value=42, minimum=1, maximum=100, step=1, label="seed", interactive=True)
84
- guidance_scale = gr.Slider(value=7.5, minimum=1, maximum=15, step=0.1, label='guidance_scale', interactive=True)
 
 
85
 
86
  with gr.Row(mobile_collapse=False, equal_height=True):
87
  negative_prompt = gr.Textbox(label="negative_prompt", placeholder="Your negative prompt",
@@ -93,7 +96,7 @@ with demo:
93
  image_out = gr.Image(label="Output", elem_id="output-img", height=400)
94
 
95
  btn.click(fn=predict,
96
- inputs=[prompt, steps, seed, guidance_scale, negative_prompt],
97
  outputs=[image_out],
98
  api_name='run')
99
 
 
6
 
7
 
8
  # Load pipeline once
 
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
+ checkpoint = "Deci/DeciDiffusion-v2-0"
11
+
12
+ pipe = StableDiffusionPipeline.from_pretrained(checkpoint, custom_pipeline=checkpoint, torch_dtype=torch.float32)
13
+ pipe.unet = pipe.unet.from_pretrained(checkpoint, subfolder='flexible_unet', torch_dtype=torch.float32)
14
  pipe = pipe.to(device)
15
 
16
 
 
23
  return content
24
 
25
 
26
+ def predict(_prompt: str, _seed: int = 42, _guidance_scale: float = 7.5, _guidance_rescale: float = 0.7, _negative_prompt: str = ""):
27
  _negative_prompt = [_negative_prompt] if _negative_prompt else None
28
 
29
  output = pipe(prompt=[_prompt],
30
  negative_prompt=_negative_prompt,
31
+ num_inference_steps=16,
32
  guidance_scale=_guidance_scale,
33
+ guidance_rescale=_guidance_rescale,
34
  generator=torch.Generator(device).manual_seed(_seed),
35
  )
36
  output_image = output.images[0]
 
81
 
82
  with gr.Accordion(label="Advanced Settings", open=False):
83
  with gr.Row(mobile_collapse=False, equal_height=True):
 
84
  seed = gr.Slider(value=42, minimum=1, maximum=100, step=1, label="seed", interactive=True)
85
+ guidance_scale = gr.Slider(value=7.5, minimum=2, maximum=20, step=0.1, label='guidance_scale', interactive=True)
86
+ guidance_rescale = gr.Slider(value=0.7, minimum=0.0, maximum=0.99, step=0.05, label='guidance_rescale', interactive=True)
87
+
88
 
89
  with gr.Row(mobile_collapse=False, equal_height=True):
90
  negative_prompt = gr.Textbox(label="negative_prompt", placeholder="Your negative prompt",
 
96
  image_out = gr.Image(label="Output", elem_id="output-img", height=400)
97
 
98
  btn.click(fn=predict,
99
+ inputs=[prompt, seed, guidance_scale, guidance_rescale, negative_prompt],
100
  outputs=[image_out],
101
  api_name='run')
102