Lisandro commited on
Commit
81bde47
·
1 Parent(s): 1456767

Please provide the file changes for which you want a commit message.

Browse files
Files changed (1) hide show
  1. app.py +25 -34
app.py CHANGED
@@ -202,35 +202,6 @@ ADAPTER_SPECS = {
202
 
203
  LOADED_ADAPTERS = set()
204
 
205
- def update_dimensions_on_upload(image):
206
- if image is None:
207
- return 1024, 1024
208
-
209
- original_width, original_height = image.size
210
-
211
- if original_width > original_height:
212
- new_width = 1024
213
- aspect_ratio = original_height / original_width
214
- new_height = int(new_width * aspect_ratio)
215
- else:
216
- new_height = 1024
217
- aspect_ratio = original_width / original_height
218
- new_width = int(new_height * aspect_ratio)
219
-
220
- new_width = (new_width // 8) * 8
221
- new_height = (new_height // 8) * 8
222
-
223
- return new_width, new_height
224
-
225
- def update_lora(lora_adapter):
226
- spec = ADAPTER_SPECS.get(lora_adapter)
227
- if not spec:
228
- raise gr.Error(f"Configuration not found for: {lora_adapter}")
229
-
230
- adapter_name = spec["adapter_name"]
231
- prompt = spec['prompt']
232
- return prompt
233
-
234
 
235
  @spaces.GPU(duration=20)
236
  def infer(
@@ -242,6 +213,8 @@ def infer(
242
  randomize_seed,
243
  guidance_scale,
244
  steps,
 
 
245
  progress=gr.Progress(track_tqdm=True)
246
  ):
247
  gc.collect()
@@ -299,7 +272,8 @@ def infer(
299
 
300
  generator = torch.Generator(device=device).manual_seed(seed)
301
 
302
- width, height = update_dimensions_on_upload(pil_images[0])
 
303
 
304
  try:
305
  result_image = pipe(
@@ -334,11 +308,14 @@ def infer_example(images, prompt, lora_adapter):
334
  result, seed = infer(
335
  images=images_list,
336
  prompt=prompt,
 
337
  lora_adapter=lora_adapter,
338
  seed=0,
339
  randomize_seed=True,
340
  guidance_scale=1.0,
341
- steps=4
 
 
342
  )
343
  return result, seed
344
 
@@ -362,7 +339,7 @@ with gr.Blocks() as demo:
362
  type="filepath",
363
  columns=2,
364
  rows=1,
365
- height=300,
366
  allow_preview=True
367
  )
368
 
@@ -385,7 +362,7 @@ with gr.Blocks() as demo:
385
  run_button = gr.Button("Edit Image", variant="primary")
386
 
387
  with gr.Column():
388
- output_image = gr.Image(label="Output Image", interactive=False, format="png", height=363)
389
 
390
  with gr.Row():
391
  lora_adapter = gr.Dropdown(
@@ -399,6 +376,20 @@ with gr.Blocks() as demo:
399
  randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
400
  guidance_scale = gr.Slider(label="Guidance Scale", minimum=1.0, maximum=10.0, step=0.1, value=1.0)
401
  steps = gr.Slider(label="Inference Steps", minimum=1, maximum=50, step=1, value=4)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
402
 
403
  gr.Examples(
404
  examples=[
@@ -427,7 +418,7 @@ with gr.Blocks() as demo:
427
 
428
  run_button.click(
429
  fn=infer,
430
- inputs=[images, prompt, negative_prompt, lora_adapter, seed, randomize_seed, guidance_scale, steps],
431
  outputs=[output_image, seed]
432
  )
433
 
 
202
 
203
  LOADED_ADAPTERS = set()
204
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
 
206
  @spaces.GPU(duration=20)
207
  def infer(
 
213
  randomize_seed,
214
  guidance_scale,
215
  steps,
216
+ width,
217
+ height,
218
  progress=gr.Progress(track_tqdm=True)
219
  ):
220
  gc.collect()
 
272
 
273
  generator = torch.Generator(device=device).manual_seed(seed)
274
 
275
+ if height == 256 and width == 256:
276
+ height, width = None, None
277
 
278
  try:
279
  result_image = pipe(
 
308
  result, seed = infer(
309
  images=images_list,
310
  prompt=prompt,
311
+ negative_prompt="", # Default negative prompt for examples
312
  lora_adapter=lora_adapter,
313
  seed=0,
314
  randomize_seed=True,
315
  guidance_scale=1.0,
316
+ steps=4,
317
+ width=None,
318
+ height=None
319
  )
320
  return result, seed
321
 
 
339
  type="filepath",
340
  columns=2,
341
  rows=1,
342
+ # height=300, # Removed to prevent visual cropping
343
  allow_preview=True
344
  )
345
 
 
362
  run_button = gr.Button("Edit Image", variant="primary")
363
 
364
  with gr.Column():
365
+ output_image = gr.Image(label="Output Image", interactive=False, format="png") # Removed height=363
366
 
367
  with gr.Row():
368
  lora_adapter = gr.Dropdown(
 
376
  randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
377
  guidance_scale = gr.Slider(label="Guidance Scale", minimum=1.0, maximum=10.0, step=0.1, value=1.0)
378
  steps = gr.Slider(label="Inference Steps", minimum=1, maximum=50, step=1, value=4)
379
+ width = gr.Slider(
380
+ label="Width",
381
+ minimum=256,
382
+ maximum=2048,
383
+ step=8,
384
+ value=None,
385
+ )
386
+ height = gr.Slider(
387
+ label="Height",
388
+ minimum=256,
389
+ maximum=2048,
390
+ step=8,
391
+ value=None,
392
+ )
393
 
394
  gr.Examples(
395
  examples=[
 
418
 
419
  run_button.click(
420
  fn=infer,
421
+ inputs=[images, prompt, negative_prompt, lora_adapter, seed, randomize_seed, guidance_scale, steps, width, height],
422
  outputs=[output_image, seed]
423
  )
424