Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,6 +24,32 @@ if torch.cuda.is_available():
|
|
| 24 |
pipe = FluxFillPipeline.from_pretrained(repo_id, torch_dtype=torch.bfloat16).to("cuda")
|
| 25 |
|
| 26 |
@spaces.GPU()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
def inpaintGen(
|
| 28 |
imgMask,
|
| 29 |
inpaint_prompt: str,
|
|
@@ -60,17 +86,16 @@ def inpaintGen(
|
|
| 60 |
seed = random.randint(0, MAX_SEED)
|
| 61 |
generator = torch.Generator("cpu").manual_seed(seed)
|
| 62 |
|
| 63 |
-
result =
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
).images[0]
|
| 74 |
|
| 75 |
return result, seed
|
| 76 |
|
|
@@ -126,7 +151,6 @@ def add_border_and_mask(image, zoom_all=1.0, zoom_left=0, zoom_right=0, zoom_up=
|
|
| 126 |
return bordered_image, mask
|
| 127 |
|
| 128 |
|
| 129 |
-
@spaces.GPU()
|
| 130 |
def outpaintGen(
|
| 131 |
img,
|
| 132 |
outpaint_prompt: str,
|
|
@@ -136,10 +160,10 @@ def outpaintGen(
|
|
| 136 |
zoom_right: float,
|
| 137 |
zoom_up: float,
|
| 138 |
zoom_down: float,
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
):
|
| 144 |
image = Image.open(img)
|
| 145 |
|
|
@@ -155,21 +179,19 @@ def outpaintGen(
|
|
| 155 |
|
| 156 |
width, height = new_image.size
|
| 157 |
|
| 158 |
-
if
|
| 159 |
-
|
| 160 |
-
generator = torch.Generator("cpu").manual_seed(op_seed)
|
| 161 |
|
| 162 |
-
result =
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
mask_image
|
| 166 |
-
width
|
| 167 |
-
height
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
).images[0]
|
| 173 |
|
| 174 |
return result, seed
|
| 175 |
|
|
|
|
| 24 |
pipe = FluxFillPipeline.from_pretrained(repo_id, torch_dtype=torch.bfloat16).to("cuda")
|
| 25 |
|
| 26 |
@spaces.GPU()
|
| 27 |
+
def gen(
|
| 28 |
+
prompt,
|
| 29 |
+
image,
|
| 30 |
+
mask_image,
|
| 31 |
+
width,
|
| 32 |
+
height,
|
| 33 |
+
num_inference_steps,
|
| 34 |
+
seed,
|
| 35 |
+
guidance_scale,
|
| 36 |
+
):
|
| 37 |
+
generator = torch.Generator("cpu").manual_seed(seed)
|
| 38 |
+
result = pipe(
|
| 39 |
+
prompt=prompt,
|
| 40 |
+
image=image,
|
| 41 |
+
mask_image=mask_image,
|
| 42 |
+
width=width,
|
| 43 |
+
height=height,
|
| 44 |
+
num_inference_steps=num_inference_steps,
|
| 45 |
+
generator=generator,
|
| 46 |
+
guidance_scale=guidance_scale,
|
| 47 |
+
max_sequence_length=512,
|
| 48 |
+
).images[0]
|
| 49 |
+
|
| 50 |
+
return result
|
| 51 |
+
|
| 52 |
+
|
| 53 |
def inpaintGen(
|
| 54 |
imgMask,
|
| 55 |
inpaint_prompt: str,
|
|
|
|
| 86 |
seed = random.randint(0, MAX_SEED)
|
| 87 |
generator = torch.Generator("cpu").manual_seed(seed)
|
| 88 |
|
| 89 |
+
result = gen(
|
| 90 |
+
inpaint_prompt,
|
| 91 |
+
source_img,
|
| 92 |
+
binary_mask,
|
| 93 |
+
new_width,
|
| 94 |
+
new_height,
|
| 95 |
+
num_steps,
|
| 96 |
+
seed,
|
| 97 |
+
guidance,
|
| 98 |
+
)
|
|
|
|
| 99 |
|
| 100 |
return result, seed
|
| 101 |
|
|
|
|
| 151 |
return bordered_image, mask
|
| 152 |
|
| 153 |
|
|
|
|
| 154 |
def outpaintGen(
|
| 155 |
img,
|
| 156 |
outpaint_prompt: str,
|
|
|
|
| 160 |
zoom_right: float,
|
| 161 |
zoom_up: float,
|
| 162 |
zoom_down: float,
|
| 163 |
+
guidance: float,
|
| 164 |
+
num_steps: int,
|
| 165 |
+
seed: int,
|
| 166 |
+
randomize_seed: bool
|
| 167 |
):
|
| 168 |
image = Image.open(img)
|
| 169 |
|
|
|
|
| 179 |
|
| 180 |
width, height = new_image.size
|
| 181 |
|
| 182 |
+
if randomize_seed:
|
| 183 |
+
seed = random.randint(0, MAX_SEED)
|
|
|
|
| 184 |
|
| 185 |
+
result = gen(
|
| 186 |
+
outpaint_prompt,
|
| 187 |
+
new_image,
|
| 188 |
+
mask_image,
|
| 189 |
+
width,
|
| 190 |
+
height,
|
| 191 |
+
num_steps,
|
| 192 |
+
seed,
|
| 193 |
+
guidance,
|
| 194 |
+
)
|
|
|
|
| 195 |
|
| 196 |
return result, seed
|
| 197 |
|