Spaces:
Running
Running
yizhangliu
commited on
Commit
•
19586cf
1
Parent(s):
797024c
Update app.py
Browse files
app.py
CHANGED
@@ -152,17 +152,12 @@ def model_process(image, mask):
|
|
152 |
cv2_flag='INPAINT_NS',
|
153 |
cv2_radius=5,
|
154 |
)
|
155 |
-
|
156 |
-
|
157 |
-
hd_strategy_crop_trigger_size=1280 hd_strategy_resize_limit=2048
|
158 |
-
'''
|
159 |
-
|
160 |
-
print(f'config = {config}')
|
161 |
|
162 |
-
|
163 |
-
|
164 |
|
165 |
-
config.sd_seed = 42
|
166 |
# logger.info(f"Origin image shape: {original_shape}")
|
167 |
print(f"Origin image shape: {original_shape}")
|
168 |
image = resize_max_size(image, size_limit=size_limit, interpolation=interpolation)
|
@@ -177,10 +172,12 @@ def model_process(image, mask):
|
|
177 |
|
178 |
start = time.time()
|
179 |
res_np_img = model(image, mask, config)
|
180 |
-
logger.info(f"process time: {(time.time() - start) * 1000}ms")
|
181 |
|
182 |
torch.cuda.empty_cache()
|
183 |
|
|
|
|
|
184 |
if alpha_channel is not None:
|
185 |
if alpha_channel.shape[:2] != res_np_img.shape[:2]:
|
186 |
alpha_channel = cv2.resize(
|
@@ -192,8 +189,8 @@ def model_process(image, mask):
|
|
192 |
|
193 |
ext = get_image_ext(origin_image_bytes)
|
194 |
return ext
|
|
|
195 |
|
196 |
-
'''
|
197 |
model = ModelManager(
|
198 |
name='lama',
|
199 |
device=device,
|
@@ -203,7 +200,6 @@ model = ModelManager(
|
|
203 |
# sd_run_local=True,
|
204 |
# callback=diffuser_callback,
|
205 |
)
|
206 |
-
'''
|
207 |
|
208 |
'''
|
209 |
pipe = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-inpainting", dtype=torch.float16, revision="fp16", use_auth_token=auth_token).to(device)
|
@@ -235,8 +231,8 @@ def predict(dict):
|
|
235 |
'''
|
236 |
image = Image.fromarray(dict["image"])
|
237 |
mask = Image.fromarray(dict["mask"])
|
238 |
-
|
239 |
-
output = mask #output.images[0]
|
240 |
# output = pipe(prompt = prompt, image=init_image, mask_image=mask,guidance_scale=7.5)
|
241 |
|
242 |
return output #, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
|
|
152 |
cv2_flag='INPAINT_NS',
|
153 |
cv2_radius=5,
|
154 |
)
|
155 |
+
|
156 |
+
# print(f'config = {config}')
|
|
|
|
|
|
|
|
|
157 |
|
158 |
+
if config.sd_seed == -1:
|
159 |
+
config.sd_seed = random.randint(1, 999999999)
|
160 |
|
|
|
161 |
# logger.info(f"Origin image shape: {original_shape}")
|
162 |
print(f"Origin image shape: {original_shape}")
|
163 |
image = resize_max_size(image, size_limit=size_limit, interpolation=interpolation)
|
|
|
172 |
|
173 |
start = time.time()
|
174 |
res_np_img = model(image, mask, config)
|
175 |
+
logger.info(f"process time: {(time.time() - start) * 1000}ms, {res_np_img.shape}")
|
176 |
|
177 |
torch.cuda.empty_cache()
|
178 |
|
179 |
+
return Image.fromarray(res_np_img)
|
180 |
+
'''
|
181 |
if alpha_channel is not None:
|
182 |
if alpha_channel.shape[:2] != res_np_img.shape[:2]:
|
183 |
alpha_channel = cv2.resize(
|
|
|
189 |
|
190 |
ext = get_image_ext(origin_image_bytes)
|
191 |
return ext
|
192 |
+
'''
|
193 |
|
|
|
194 |
model = ModelManager(
|
195 |
name='lama',
|
196 |
device=device,
|
|
|
200 |
# sd_run_local=True,
|
201 |
# callback=diffuser_callback,
|
202 |
)
|
|
|
203 |
|
204 |
'''
|
205 |
pipe = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-inpainting", dtype=torch.float16, revision="fp16", use_auth_token=auth_token).to(device)
|
|
|
231 |
'''
|
232 |
image = Image.fromarray(dict["image"])
|
233 |
mask = Image.fromarray(dict["mask"])
|
234 |
+
output = model_process(dict["image"], dict["mask"])
|
235 |
+
# output = mask #output.images[0]
|
236 |
# output = pipe(prompt = prompt, image=init_image, mask_image=mask,guidance_scale=7.5)
|
237 |
|
238 |
return output #, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|