Himanshu-AT commited on
Commit
ab4297c
·
1 Parent(s): 2143895

add width and height

Browse files
Files changed (2) hide show
  1. .DS_Store +0 -0
  2. app.py +57 -55
.DS_Store CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
 
app.py CHANGED
@@ -39,45 +39,45 @@ for model_name, model_path in lora_models.items():
39
 
40
  lora_models["None"] = None
41
 
42
- def calculate_optimal_dimensions(image: Image.Image):
43
- # Extract the original dimensions
44
- original_width, original_height = image.size
45
-
46
- # Set constants
47
- MIN_ASPECT_RATIO = 9 / 16
48
- MAX_ASPECT_RATIO = 16 / 9
49
- FIXED_DIMENSION = 1024
50
-
51
- # Calculate the aspect ratio of the original image
52
- original_aspect_ratio = original_width / original_height
53
-
54
- # Determine which dimension to fix
55
- if original_aspect_ratio > 1: # Wider than tall
56
- width = FIXED_DIMENSION
57
- height = round(FIXED_DIMENSION / original_aspect_ratio)
58
- else: # Taller than wide
59
- height = FIXED_DIMENSION
60
- width = round(FIXED_DIMENSION * original_aspect_ratio)
61
-
62
- # Ensure dimensions are multiples of 8
63
- width = (width // 8) * 8
64
- height = (height // 8) * 8
65
-
66
- # Enforce aspect ratio limits
67
- calculated_aspect_ratio = width / height
68
- if calculated_aspect_ratio > MAX_ASPECT_RATIO:
69
- width = (height * MAX_ASPECT_RATIO // 8) * 8
70
- elif calculated_aspect_ratio < MIN_ASPECT_RATIO:
71
- height = (width / MIN_ASPECT_RATIO // 8) * 8
72
-
73
- # Ensure width and height remain above the minimum dimensions
74
- width = max(width, 576) if width == FIXED_DIMENSION else width
75
- height = max(height, 576) if height == FIXED_DIMENSION else height
76
-
77
- return width, height
78
 
79
  @spaces.GPU(durations=300)
80
- def infer(edit_images, prompt, lora_model, strength, seed=42, randomize_seed=False, guidance_scale=3.5, num_inference_steps=28, progress=gr.Progress(track_tqdm=True)):
81
  # pipe.enable_xformers_memory_efficient_attention()
82
  gr.Info("Infering")
83
 
@@ -95,7 +95,7 @@ def infer(edit_images, prompt, lora_model, strength, seed=42, randomize_seed=Fal
95
  return None, None
96
 
97
 
98
- width, height = calculate_optimal_dimensions(image)
99
  if randomize_seed:
100
  seed = random.randint(0, MAX_SEED)
101
 
@@ -261,26 +261,28 @@ with gr.Blocks(css=css) as demo:
261
  value=0.85,
262
  )
263
 
264
- # width = gr.Slider(
265
- # label="width",
266
- # minimum=512,
267
- # maximum=3072,
268
- # step=1,
269
- # value=1024,
270
- # )
271
-
272
- # height = gr.Slider(
273
- # label="height",
274
- # minimum=512,
275
- # maximum=3072,
276
- # step=1,
277
- # value=1024,
278
- # )
 
 
279
 
280
  gr.on(
281
  triggers=[run_button.click, prompt.submit],
282
  fn = infer,
283
- inputs = [edit_image, prompt, lora_model, strength, seed, randomize_seed, guidance_scale, num_inference_steps],
284
  outputs = [result, seed]
285
  )
286
 
@@ -324,4 +326,4 @@ def authenticate(username, password):
324
  return False
325
  # Launch the app with authentication
326
 
327
- demo.launch(debug=True, auth=authenticate)
 
39
 
40
  lora_models["None"] = None
41
 
42
+ # def calculate_optimal_dimensions(image: Image.Image):
43
+ # # Extract the original dimensions
44
+ # original_width, original_height = image.size
45
+
46
+ # # Set constants
47
+ # MIN_ASPECT_RATIO = 9 / 16
48
+ # MAX_ASPECT_RATIO = 16 / 9
49
+ # FIXED_DIMENSION = 1024
50
+
51
+ # # Calculate the aspect ratio of the original image
52
+ # original_aspect_ratio = original_width / original_height
53
+
54
+ # # Determine which dimension to fix
55
+ # if original_aspect_ratio > 1: # Wider than tall
56
+ # width = FIXED_DIMENSION
57
+ # height = round(FIXED_DIMENSION / original_aspect_ratio)
58
+ # else: # Taller than wide
59
+ # height = FIXED_DIMENSION
60
+ # width = round(FIXED_DIMENSION * original_aspect_ratio)
61
+
62
+ # # Ensure dimensions are multiples of 8
63
+ # width = (width // 8) * 8
64
+ # height = (height // 8) * 8
65
+
66
+ # # Enforce aspect ratio limits
67
+ # calculated_aspect_ratio = width / height
68
+ # if calculated_aspect_ratio > MAX_ASPECT_RATIO:
69
+ # width = (height * MAX_ASPECT_RATIO // 8) * 8
70
+ # elif calculated_aspect_ratio < MIN_ASPECT_RATIO:
71
+ # height = (width / MIN_ASPECT_RATIO // 8) * 8
72
+
73
+ # # Ensure width and height remain above the minimum dimensions
74
+ # width = max(width, 576) if width == FIXED_DIMENSION else width
75
+ # height = max(height, 576) if height == FIXED_DIMENSION else height
76
+
77
+ # return width, height
78
 
79
  @spaces.GPU(durations=300)
80
+ def infer(edit_images, prompt, width, height, lora_model, strength, seed=42, randomize_seed=False, guidance_scale=3.5, num_inference_steps=28, progress=gr.Progress(track_tqdm=True)):
81
  # pipe.enable_xformers_memory_efficient_attention()
82
  gr.Info("Infering")
83
 
 
95
  return None, None
96
 
97
 
98
+ # width, height = calculate_optimal_dimensions(image)
99
  if randomize_seed:
100
  seed = random.randint(0, MAX_SEED)
101
 
 
261
  value=0.85,
262
  )
263
 
264
+ with gr.Row():
265
+
266
+ width = gr.Slider(
267
+ label="width",
268
+ minimum=512,
269
+ maximum=3072,
270
+ step=1,
271
+ value=1024,
272
+ )
273
+
274
+ height = gr.Slider(
275
+ label="height",
276
+ minimum=512,
277
+ maximum=3072,
278
+ step=1,
279
+ value=1024,
280
+ )
281
 
282
  gr.on(
283
  triggers=[run_button.click, prompt.submit],
284
  fn = infer,
285
+ inputs = [edit_image, prompt, width, height, lora_model, strength, seed, randomize_seed, guidance_scale, num_inference_steps],
286
  outputs = [result, seed]
287
  )
288
 
 
326
  return False
327
  # Launch the app with authentication
328
 
329
+ demo.launch(debug=True, auth=authenticate)