cocktailpeanut commited on
Commit
60875f3
1 Parent(s): 0cb2e17
Files changed (1) hide show
  1. gradio_demo/app.py +13 -2
gradio_demo/app.py CHANGED
@@ -93,7 +93,7 @@ def show_final_preview(preview_row):
93
  @torch.no_grad()
94
  def instantir_restore(
95
  lq, prompt="", steps=30, cfg_scale=7.0, guidance_end=1.0,
96
- creative_restoration=False, seed=3407, height=1024, width=1024, preview_start=0.0, progress=gr.Progress(track_tqdm=True)):
97
 
98
 
99
 
@@ -139,6 +139,15 @@ def instantir_restore(
139
  if "previewer" not in pipe.unet.active_adapters():
140
  pipe.unet.set_adapter('previewer')
141
 
 
 
 
 
 
 
 
 
 
142
  if isinstance(guidance_end, int):
143
  guidance_end = guidance_end / steps
144
  elif guidance_end > 1.0:
@@ -248,6 +257,8 @@ with gr.Blocks() as demo:
248
  preview_start = gr.Slider(label="Preview Start", value=0, minimum=0, maximum=30, step=1)
249
  prompt = gr.Textbox(label="Restoration prompts (Optional)", placeholder="")
250
  mode = gr.Checkbox(label="Creative Restoration", value=False)
 
 
251
 
252
  with gr.Row():
253
  restore_btn = gr.Button("InstantIR magic!")
@@ -266,7 +277,7 @@ with gr.Blocks() as demo:
266
  restore_btn.click(
267
  instantir_restore, inputs=[
268
  lq_img, prompt, steps, cfg_scale, guidance_end,
269
- mode, seed, height, width, preview_start,
270
  ],
271
  outputs=[output, pipe_out], api_name="InstantIR"
272
  )
 
93
  @torch.no_grad()
94
  def instantir_restore(
95
  lq, prompt="", steps=30, cfg_scale=7.0, guidance_end=1.0,
96
+ creative_restoration=False, seed=3407, height=1024, width=1024, preview_start=0.0, cpu_offload, progress=gr.Progress(track_tqdm=True)):
97
 
98
 
99
 
 
139
  if "previewer" not in pipe.unet.active_adapters():
140
  pipe.unet.set_adapter('previewer')
141
 
142
+ print('optimizing')
143
+ pipe.vae.enable_slicing()
144
+ pipe.vae.enable_tiling()
145
+ if cpu_offload:
146
+ pipe.enable_model_cpu_offload()
147
+ pipe.enable_sequential_cpu_offload()
148
+ print('done')
149
+
150
+
151
  if isinstance(guidance_end, int):
152
  guidance_end = guidance_end / steps
153
  elif guidance_end > 1.0:
 
257
  preview_start = gr.Slider(label="Preview Start", value=0, minimum=0, maximum=30, step=1)
258
  prompt = gr.Textbox(label="Restoration prompts (Optional)", placeholder="")
259
  mode = gr.Checkbox(label="Creative Restoration", value=False)
260
+ cpu_offload = gr.Checkbox(label="CPU offload", info="If you have a lot of GPU VRAM, uncheck this option for faster generation", value=False)
261
+
262
 
263
  with gr.Row():
264
  restore_btn = gr.Button("InstantIR magic!")
 
277
  restore_btn.click(
278
  instantir_restore, inputs=[
279
  lq_img, prompt, steps, cfg_scale, guidance_end,
280
+ mode, seed, height, width, preview_start, cpu_offload
281
  ],
282
  outputs=[output, pipe_out], api_name="InstantIR"
283
  )