owiedotch commited on
Commit
081465c
1 Parent(s): 7eda457

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -3
app.py CHANGED
@@ -69,7 +69,7 @@ sampler = SpacedSampler(model, var_type="fixed_small")
69
  def process(
70
  control_img: Image.Image,
71
  num_samples: int,
72
- sr_scale: int,
73
  strength: float,
74
  positive_prompt: str,
75
  negative_prompt: str,
@@ -159,14 +159,28 @@ def process(
159
 
160
  return preds
161
 
 
 
 
 
 
 
162
  block = gr.Blocks().queue()
163
  with block:
164
  with gr.Row():
165
  input_image = gr.Image(type="pil", label="Input Image")
 
 
 
 
 
 
 
166
  run_button = gr.Button(value="Run")
167
- with gr.Accordion("Options", open=True):
 
 
168
  num_samples = gr.Slider(label="Number Of Samples", minimum=1, maximum=12, value=1, step=1, info="Number of output images to generate.")
169
- sr_scale = gr.Dropdown(label="SR Scale", choices=["2x", "4x", "8x"], value="4x", info="Super-resolution scale factor.")
170
  strength = gr.Slider(label="Control Strength", minimum=0.0, maximum=2.0, value=1.0, step=0.01, info="Strength of the control signal.")
171
  positive_prompt = gr.Textbox(label="Positive Prompt", value="", info="Positive text prompt to guide the image generation.")
172
  negative_prompt = gr.Textbox(
@@ -184,6 +198,7 @@ with block:
184
  tile_vae = gr.Checkbox(label="Tile VAE", value=True, info="Enable tiled VAE for large images.")
185
  vae_encoder_tile_size = gr.Slider(label="Encoder tile size", minimum=512, maximum=5000, value=1024, step=256, info="Size of each tile for the VAE encoder.")
186
  vae_decoder_tile_size = gr.Slider(label="Decoder tile size", minimum=64, maximum=512, value=224, step=128, info="Size of each tile for the VAE decoder.")
 
187
  with gr.Column():
188
  result_gallery = gr.Gallery(label="Output", show_label=False, elem_id="gallery")
189
 
@@ -207,4 +222,15 @@ with block:
207
  ]
208
  run_button.click(fn=process, inputs=inputs, outputs=[result_gallery])
209
 
 
 
 
 
 
 
 
 
 
 
 
210
  block.launch()
 
69
  def process(
70
  control_img: Image.Image,
71
  num_samples: int,
72
+ sr_scale: float,
73
  strength: float,
74
  positive_prompt: str,
75
  negative_prompt: str,
 
159
 
160
  return preds
161
 
162
+ def update_output_resolution(image):
163
+ if image is not None:
164
+ width, height = image.size
165
+ return f"Current resolution: {width}x{height}. Output resolution: {int(width*sr_scale.value)}x{int(height*sr_scale.value)}"
166
+ return "Upload an image to see the output resolution"
167
+
168
  block = gr.Blocks().queue()
169
  with block:
170
  with gr.Row():
171
  input_image = gr.Image(type="pil", label="Input Image")
172
+
173
+ with gr.Row():
174
+ sr_scale = gr.Slider(label="SR Scale", minimum=1, maximum=8, value=4, step=0.1, info="Super-resolution scale factor.")
175
+
176
+ output_resolution = gr.Markdown("Upload an image to see the output resolution")
177
+
178
+ with gr.Row():
179
  run_button = gr.Button(value="Run")
180
+
181
+ with gr.Accordion("Options", open=False):
182
+ with gr.Column():
183
  num_samples = gr.Slider(label="Number Of Samples", minimum=1, maximum=12, value=1, step=1, info="Number of output images to generate.")
 
184
  strength = gr.Slider(label="Control Strength", minimum=0.0, maximum=2.0, value=1.0, step=0.01, info="Strength of the control signal.")
185
  positive_prompt = gr.Textbox(label="Positive Prompt", value="", info="Positive text prompt to guide the image generation.")
186
  negative_prompt = gr.Textbox(
 
198
  tile_vae = gr.Checkbox(label="Tile VAE", value=True, info="Enable tiled VAE for large images.")
199
  vae_encoder_tile_size = gr.Slider(label="Encoder tile size", minimum=512, maximum=5000, value=1024, step=256, info="Size of each tile for the VAE encoder.")
200
  vae_decoder_tile_size = gr.Slider(label="Decoder tile size", minimum=64, maximum=512, value=224, step=128, info="Size of each tile for the VAE decoder.")
201
+
202
  with gr.Column():
203
  result_gallery = gr.Gallery(label="Output", show_label=False, elem_id="gallery")
204
 
 
222
  ]
223
  run_button.click(fn=process, inputs=inputs, outputs=[result_gallery])
224
 
225
+ # Update output resolution when image is uploaded or SR scale is changed
226
+ input_image.change(update_output_resolution, inputs=[input_image], outputs=[output_resolution])
227
+ sr_scale.change(update_output_resolution, inputs=[input_image], outputs=[output_resolution])
228
+
229
+ # Disable SR scale slider when no image is uploaded
230
+ input_image.change(
231
+ lambda x: gr.update(interactive=x is not None),
232
+ inputs=[input_image],
233
+ outputs=[sr_scale]
234
+ )
235
+
236
  block.launch()