Spaces:
Running
on
Zero
Running
on
Zero
bugfix
Browse files
app.py
CHANGED
@@ -125,7 +125,7 @@ def upload_image_to_r2(image, account_id, access_key, secret_key, bucket_name):
|
|
125 |
print("upload finish", image_file)
|
126 |
return image_file
|
127 |
|
128 |
-
|
129 |
def run_flux(
|
130 |
image: Image.Image,
|
131 |
mask: Image.Image,
|
@@ -168,6 +168,7 @@ def run_flux(
|
|
168 |
|
169 |
return genearte_image
|
170 |
|
|
|
171 |
def process(
|
172 |
image_url: str,
|
173 |
mask_url: str,
|
@@ -210,10 +211,11 @@ def process(
|
|
210 |
return None, json.dumps(result)
|
211 |
|
212 |
# generate
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
|
|
217 |
|
218 |
try:
|
219 |
generated_image = run_flux(
|
@@ -233,7 +235,8 @@ def process(
|
|
233 |
except:
|
234 |
result["message"] = "generate image failed"
|
235 |
return None, json.dumps(result)
|
236 |
-
|
|
|
237 |
if upload_to_r2:
|
238 |
with calculateDuration("upload image"):
|
239 |
url = upload_image_to_r2(generated_image, account_id, access_key, secret_key, bucket)
|
|
|
125 |
print("upload finish", image_file)
|
126 |
return image_file
|
127 |
|
128 |
+
|
129 |
def run_flux(
|
130 |
image: Image.Image,
|
131 |
mask: Image.Image,
|
|
|
168 |
|
169 |
return genearte_image
|
170 |
|
171 |
+
@spaces.GPU(duration=120)
|
172 |
def process(
|
173 |
image_url: str,
|
174 |
mask_url: str,
|
|
|
211 |
return None, json.dumps(result)
|
212 |
|
213 |
# generate
|
214 |
+
with calculateDuration("resize & process mask"):
|
215 |
+
width, height = calculate_image_dimensions_for_flux(original_resolution_wh=image.size)
|
216 |
+
image = image.resize((width, height), Image.LANCZOS)
|
217 |
+
mask = mask.resize((width, height), Image.LANCZOS)
|
218 |
+
mask = process_mask(mask, mask_inflation=mask_inflation_slider, mask_blur=mask_blur_slider)
|
219 |
|
220 |
try:
|
221 |
generated_image = run_flux(
|
|
|
235 |
except:
|
236 |
result["message"] = "generate image failed"
|
237 |
return None, json.dumps(result)
|
238 |
+
|
239 |
+
print("run flux finish")
|
240 |
if upload_to_r2:
|
241 |
with calculateDuration("upload image"):
|
242 |
url = upload_image_to_r2(generated_image, account_id, access_key, secret_key, bucket)
|