fffiloni commited on
Commit
5bc9409
1 Parent(s): 4ab7724

UI changes for advanced settings + keep presets available

Browse files
Files changed (1) hide show
  1. app.py +56 -30
app.py CHANGED
@@ -110,6 +110,17 @@ def infer(image, model_selection, width, height, overlap_width, num_inference_st
110
 
111
  yield background, cnet_image
112
 
 
 
 
 
 
 
 
 
 
 
 
113
 
114
  def clear_result():
115
  return gr.update(value=None)
@@ -117,7 +128,7 @@ def clear_result():
117
 
118
  css = """
119
  .gradio-container {
120
- width: 1024px !important;
121
  }
122
  """
123
 
@@ -138,41 +149,50 @@ with gr.Blocks(css=css) as demo:
138
  sources=["upload"],
139
  )
140
 
 
 
 
 
 
 
141
  with gr.Row():
142
  with gr.Column(scale=2):
143
  prompt_input = gr.Textbox(label="Prompt (Optional)")
144
  with gr.Column(scale=1):
145
  run_button = gr.Button("Generate")
146
 
147
- with gr.Row():
148
- width_slider = gr.Slider(
149
- label="Width",
150
- minimum=720,
151
- maximum=1440,
152
- step=8,
153
- value=1440, # Set a default value
154
- )
155
- height_slider = gr.Slider(
156
- label="Height",
157
- minimum=720,
158
- maximum=1440,
159
- step=8,
160
- value=1024, # Set a default value
161
- )
162
- model_selection = gr.Dropdown(
163
- choices=list(MODELS.keys()),
164
- value="RealVisXL V5.0 Lightning",
165
- label="Model",
166
- )
167
- num_inference_steps = gr.Slider(label="Steps", minimum=4, maximum=12, step=1, value=8 )
168
-
169
- overlap_width = gr.Slider(
170
- label="Mask overlap width",
171
- minimum=1,
172
- maximum=50,
173
- value=42,
174
- step=1
175
- )
 
 
 
176
 
177
  gr.Examples(
178
  examples=[
@@ -189,6 +209,12 @@ with gr.Blocks(css=css) as demo:
189
  label="Generated Image",
190
  )
191
 
 
 
 
 
 
 
192
  run_button.click(
193
  fn=clear_result,
194
  inputs=None,
 
110
 
111
  yield background, cnet_image
112
 
113
+ def preload_presets(target_ratio):
114
+ if target_ratio == "9:16":
115
+ changed_width = 720
116
+ changed_height = 1024
117
+ return changed_width, changed_height, gr.update(open=False)
118
+ elif target_ratio == "16:9":
119
+ changed_width = 1024
120
+ changed_height = 720
121
+ return changed_width, changed_height, gr.update(open=False)
122
+ elif target_ratio == "Custom":
123
+ return 720, 1024, gr.update(open=True)
124
 
125
  def clear_result():
126
  return gr.update(value=None)
 
128
 
129
  css = """
130
  .gradio-container {
131
+ width: 1800px !important;
132
  }
133
  """
134
 
 
149
  sources=["upload"],
150
  )
151
 
152
+ target_ratio = gr.Radio(
153
+ label = "Expected Ratio",
154
+ choices = ["9:16", "16:9", "Custom"],
155
+ value = "9:16"
156
+ )
157
+
158
  with gr.Row():
159
  with gr.Column(scale=2):
160
  prompt_input = gr.Textbox(label="Prompt (Optional)")
161
  with gr.Column(scale=1):
162
  run_button = gr.Button("Generate")
163
 
164
+ with gr.Accordion(label="Advanced settings", open=False) as settings_panel:
165
+ with gr.Column():
166
+ with gr.Row():
167
+ width_slider = gr.Slider(
168
+ label="Width",
169
+ minimum=720,
170
+ maximum=1440,
171
+ step=8,
172
+ value=720, # Set a default value
173
+ )
174
+ height_slider = gr.Slider(
175
+ label="Height",
176
+ minimum=720,
177
+ maximum=1440,
178
+ step=8,
179
+ value=1024, # Set a default value
180
+ )
181
+ with gr.Row():
182
+ model_selection = gr.Dropdown(
183
+ choices=list(MODELS.keys()),
184
+ value="RealVisXL V5.0 Lightning",
185
+ label="Model",
186
+ )
187
+ num_inference_steps = gr.Slider(label="Steps", minimum=4, maximum=12, step=1, value=8 )
188
+
189
+ overlap_width = gr.Slider(
190
+ label="Mask overlap width",
191
+ minimum=1,
192
+ maximum=50,
193
+ value=42,
194
+ step=1
195
+ )
196
 
197
  gr.Examples(
198
  examples=[
 
209
  label="Generated Image",
210
  )
211
 
212
+ target_ratio.change(
213
+ fn = preload_presets,
214
+ inputs = [target_ratio],
215
+ outputs = [width_slider, height_slider, settings_panel],
216
+ queue = False
217
+ )
218
  run_button.click(
219
  fn=clear_result,
220
  inputs=None,