Spaces:
Runtime error
Runtime error
Himanshu-AT
commited on
Commit
·
ed7e1f3
1
Parent(s):
c1581f5
increae res
Browse files
app.py
CHANGED
|
@@ -22,16 +22,16 @@ pipe.enable_lora()
|
|
| 22 |
# vae = AutoencoderKL.from_pretrained("black-forest-labs/FLUX.1-dev", subfolder="vae")
|
| 23 |
# processor = DepthPreprocessor.from_pretrained("LiheYoung/depth-anything-large-hf")
|
| 24 |
|
| 25 |
-
preprocess = transforms.Compose(
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
)
|
| 35 |
#
|
| 36 |
# image_np = image[0].cpu().numpy() # Move to CPU and convert to NumPy
|
| 37 |
|
|
@@ -42,49 +42,49 @@ preprocess = transforms.Compose(
|
|
| 42 |
|
| 43 |
# image = Image.fromarray(image_np)
|
| 44 |
|
| 45 |
-
def calculate_optimal_dimensions(image: Image.Image):
|
| 46 |
-
|
| 47 |
-
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
|
| 80 |
-
|
| 81 |
|
| 82 |
@spaces.GPU(durations=300)
|
| 83 |
-
def infer(edit_images, prompt,
|
| 84 |
# pipe.enable_xformers_memory_efficient_attention()
|
| 85 |
|
| 86 |
image = edit_images["background"]
|
| 87 |
-
width, height = calculate_optimal_dimensions(image)
|
| 88 |
mask = edit_images["layers"][0]
|
| 89 |
if randomize_seed:
|
| 90 |
seed = random.randint(0, MAX_SEED)
|
|
@@ -93,7 +93,7 @@ def infer(edit_images, prompt, prompt_2, seed=42, randomize_seed=False, width=10
|
|
| 93 |
image = pipe(
|
| 94 |
# mask_image_latent=vae.encode(controlImage),
|
| 95 |
prompt=prompt,
|
| 96 |
-
prompt_2=
|
| 97 |
image=image,
|
| 98 |
mask_image=mask,
|
| 99 |
height=height,
|
|
@@ -147,7 +147,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 147 |
placeholder="Enter your prompt",
|
| 148 |
container=False,
|
| 149 |
)
|
| 150 |
-
|
| 151 |
label="Prompt2",
|
| 152 |
show_label=False,
|
| 153 |
max_lines=2,
|
|
@@ -208,10 +208,28 @@ with gr.Blocks(css=css) as demo:
|
|
| 208 |
value=28,
|
| 209 |
)
|
| 210 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
gr.on(
|
| 212 |
triggers=[run_button.click, prompt.submit],
|
| 213 |
fn = infer,
|
| 214 |
-
inputs = [edit_image, prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
|
| 215 |
outputs = [result, seed]
|
| 216 |
)
|
| 217 |
|
|
|
|
| 22 |
# vae = AutoencoderKL.from_pretrained("black-forest-labs/FLUX.1-dev", subfolder="vae")
|
| 23 |
# processor = DepthPreprocessor.from_pretrained("LiheYoung/depth-anything-large-hf")
|
| 24 |
|
| 25 |
+
# preprocess = transforms.Compose(
|
| 26 |
+
# [
|
| 27 |
+
# transforms.Resize(
|
| 28 |
+
# (vae.config.sample_size, vae.config.sample_size),
|
| 29 |
+
# interpolation=transforms.InterpolationMode.BILINEAR,
|
| 30 |
+
# ),
|
| 31 |
+
# transforms.ToTensor(),
|
| 32 |
+
# transforms.Normalize([0.5], [0.5]),
|
| 33 |
+
# ]
|
| 34 |
+
# )
|
| 35 |
#
|
| 36 |
# image_np = image[0].cpu().numpy() # Move to CPU and convert to NumPy
|
| 37 |
|
|
|
|
| 42 |
|
| 43 |
# image = Image.fromarray(image_np)
|
| 44 |
|
| 45 |
+
# def calculate_optimal_dimensions(image: Image.Image):
|
| 46 |
+
# # Extract the original dimensions
|
| 47 |
+
# original_width, original_height = image.size
|
| 48 |
|
| 49 |
+
# # Set constants
|
| 50 |
+
# MIN_ASPECT_RATIO = 9 / 16
|
| 51 |
+
# MAX_ASPECT_RATIO = 16 / 9
|
| 52 |
+
# FIXED_DIMENSION = 1024
|
| 53 |
|
| 54 |
+
# # Calculate the aspect ratio of the original image
|
| 55 |
+
# original_aspect_ratio = original_width / original_height
|
| 56 |
|
| 57 |
+
# # Determine which dimension to fix
|
| 58 |
+
# if original_aspect_ratio > 1: # Wider than tall
|
| 59 |
+
# width = FIXED_DIMENSION
|
| 60 |
+
# height = round(FIXED_DIMENSION / original_aspect_ratio)
|
| 61 |
+
# else: # Taller than wide
|
| 62 |
+
# height = FIXED_DIMENSION
|
| 63 |
+
# width = round(FIXED_DIMENSION * original_aspect_ratio)
|
| 64 |
|
| 65 |
+
# # Ensure dimensions are multiples of 8
|
| 66 |
+
# width = (width // 8) * 8
|
| 67 |
+
# height = (height // 8) * 8
|
| 68 |
|
| 69 |
+
# # Enforce aspect ratio limits
|
| 70 |
+
# calculated_aspect_ratio = width / height
|
| 71 |
+
# if calculated_aspect_ratio > MAX_ASPECT_RATIO:
|
| 72 |
+
# width = (height * MAX_ASPECT_RATIO // 8) * 8
|
| 73 |
+
# elif calculated_aspect_ratio < MIN_ASPECT_RATIO:
|
| 74 |
+
# height = (width / MIN_ASPECT_RATIO // 8) * 8
|
| 75 |
|
| 76 |
+
# # Ensure width and height remain above the minimum dimensions
|
| 77 |
+
# width = max(width, 576) if width == FIXED_DIMENSION else width
|
| 78 |
+
# height = max(height, 576) if height == FIXED_DIMENSION else height
|
| 79 |
|
| 80 |
+
# return width, height
|
| 81 |
|
| 82 |
@spaces.GPU(durations=300)
|
| 83 |
+
def infer(edit_images, prompt, prompt2, width, height, seed=42, randomize_seed=False, guidance_scale=3.5, num_inference_steps=28, progress=gr.Progress(track_tqdm=True)):
|
| 84 |
# pipe.enable_xformers_memory_efficient_attention()
|
| 85 |
|
| 86 |
image = edit_images["background"]
|
| 87 |
+
# width, height = calculate_optimal_dimensions(image)
|
| 88 |
mask = edit_images["layers"][0]
|
| 89 |
if randomize_seed:
|
| 90 |
seed = random.randint(0, MAX_SEED)
|
|
|
|
| 93 |
image = pipe(
|
| 94 |
# mask_image_latent=vae.encode(controlImage),
|
| 95 |
prompt=prompt,
|
| 96 |
+
prompt_2=prompt2,
|
| 97 |
image=image,
|
| 98 |
mask_image=mask,
|
| 99 |
height=height,
|
|
|
|
| 147 |
placeholder="Enter your prompt",
|
| 148 |
container=False,
|
| 149 |
)
|
| 150 |
+
prompt2 = gr.Text(
|
| 151 |
label="Prompt2",
|
| 152 |
show_label=False,
|
| 153 |
max_lines=2,
|
|
|
|
| 208 |
value=28,
|
| 209 |
)
|
| 210 |
|
| 211 |
+
with gr.Row():
|
| 212 |
+
|
| 213 |
+
width = gr.Slider(
|
| 214 |
+
label="width",
|
| 215 |
+
minimum=512,
|
| 216 |
+
maximum=3072,
|
| 217 |
+
step=1,
|
| 218 |
+
value=1024,
|
| 219 |
+
)
|
| 220 |
+
|
| 221 |
+
num_inference_steps = gr.Slider(
|
| 222 |
+
label="height",
|
| 223 |
+
minimum=512,
|
| 224 |
+
maximum=3072,
|
| 225 |
+
step=1,
|
| 226 |
+
value=1024,
|
| 227 |
+
)
|
| 228 |
+
|
| 229 |
gr.on(
|
| 230 |
triggers=[run_button.click, prompt.submit],
|
| 231 |
fn = infer,
|
| 232 |
+
inputs = [edit_image, prompt, prompt2, width, height, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
|
| 233 |
outputs = [result, seed]
|
| 234 |
)
|
| 235 |
|