multimodalart HF Staff commited on
Commit
884ddb3
·
verified ·
1 Parent(s): a2340ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -3
app.py CHANGED
@@ -151,6 +151,27 @@ def reset_all():
151
  def end_reset():
152
  return False
153
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
 
155
  with gr.Blocks(theme=gr.themes.Citrus(), css=css) as demo:
156
  with gr.Column(elem_id="col-container"):
@@ -209,14 +230,24 @@ with gr.Blocks(theme=gr.themes.Citrus(), css=css) as demo:
209
 
210
  # Manual generation
211
  run_event = run_btn.click(fn=infer_camera_edit, inputs=inputs, outputs=outputs)
212
-
213
- # Image upload resets
214
  image.change(
 
 
 
 
215
  fn=reset_all,
216
  inputs=None,
217
  outputs=[rotate_deg, move_forward, vertical_tilt, wideangle, is_reset],
218
  queue=False
219
- ).then(fn=end_reset, inputs=None, outputs=[is_reset], queue=False)
 
 
 
 
 
 
220
 
221
  # Live updates
222
  def maybe_infer(is_reset, progress=gr.Progress(track_tqdm=True), *args):
 
151
  def end_reset():
152
  return False
153
 
154
+ def update_dimensions_on_upload(image):
155
+ if image is None:
156
+ return 1024, 1024
157
+
158
+ original_width, original_height = image.size
159
+
160
+ if original_width > original_height:
161
+ new_width = 1024
162
+ aspect_ratio = original_height / original_width
163
+ new_height = int(new_width * aspect_ratio)
164
+ else:
165
+ new_height = 1024
166
+ aspect_ratio = original_width / original_height
167
+ new_width = int(new_height * aspect_ratio)
168
+
169
+ # Ensure dimensions are multiples of 8
170
+ new_width = (new_width // 8) * 8
171
+ new_height = (new_height // 8) * 8
172
+
173
+ return new_width, new_height
174
+
175
 
176
  with gr.Blocks(theme=gr.themes.Citrus(), css=css) as demo:
177
  with gr.Column(elem_id="col-container"):
 
230
 
231
  # Manual generation
232
  run_event = run_btn.click(fn=infer_camera_edit, inputs=inputs, outputs=outputs)
233
+
234
+ # Image upload triggers dimension update and control reset
235
  image.change(
236
+ fn=update_dimensions_on_upload,
237
+ inputs=[image],
238
+ outputs=[width, height]
239
+ ).then(
240
  fn=reset_all,
241
  inputs=None,
242
  outputs=[rotate_deg, move_forward, vertical_tilt, wideangle, is_reset],
243
  queue=False
244
+ ).then(
245
+ fn=end_reset,
246
+ inputs=None,
247
+ outputs=[is_reset],
248
+ queue=False
249
+ )
250
+
251
 
252
  # Live updates
253
  def maybe_infer(is_reset, progress=gr.Progress(track_tqdm=True), *args):