Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -75,12 +75,14 @@ else:
|
|
| 75 |
|
| 76 |
|
| 77 |
def _run_pipe(image, prompt, seed, steps):
|
|
|
|
| 78 |
gc.collect()
|
| 79 |
if torch.cuda.is_available():
|
| 80 |
torch.cuda.empty_cache()
|
| 81 |
width, height = _round_dims(image)
|
|
|
|
| 82 |
generator = torch.Generator(device=DEVICE).manual_seed(seed)
|
| 83 |
-
|
| 84 |
image=[image],
|
| 85 |
prompt=prompt,
|
| 86 |
negative_prompt=NEGATIVE_PROMPT,
|
|
@@ -90,6 +92,8 @@ def _run_pipe(image, prompt, seed, steps):
|
|
| 90 |
true_cfg_scale=1.0,
|
| 91 |
generator=generator,
|
| 92 |
).images[0]
|
|
|
|
|
|
|
| 93 |
|
| 94 |
|
| 95 |
# --- Server -------------------------------------------------------------------
|
|
@@ -97,18 +101,23 @@ server = gr.Server()
|
|
| 97 |
HOME = Path(__file__).parent
|
| 98 |
|
| 99 |
|
| 100 |
-
@server.api(name="edit_image"
|
| 101 |
def edit_image(image: FileData, prompt: str) -> dict:
|
| 102 |
"""Edit an image guided by a text prompt using FireRed-Image-Edit 1.1."""
|
|
|
|
| 103 |
if not prompt or not prompt.strip():
|
| 104 |
return {"error": "Please enter an edit prompt."}
|
| 105 |
src = Image.open(image["path"]).convert("RGB")
|
|
|
|
| 106 |
seed = random.randint(0, MAX_SEED)
|
|
|
|
| 107 |
result = _edit(src, prompt.strip(), seed, steps=4)
|
|
|
|
| 108 |
|
| 109 |
fd, out_path = tempfile.mkstemp(suffix=".png")
|
| 110 |
os.close(fd)
|
| 111 |
result.save(out_path)
|
|
|
|
| 112 |
return {"image": FileData(path=out_path), "seed": seed}
|
| 113 |
|
| 114 |
|
|
@@ -118,4 +127,4 @@ async def homepage():
|
|
| 118 |
|
| 119 |
|
| 120 |
if __name__ == "__main__":
|
| 121 |
-
server.launch(
|
|
|
|
| 75 |
|
| 76 |
|
| 77 |
def _run_pipe(image, prompt, seed, steps):
|
| 78 |
+
print(f"[_run_pipe] start cuda_avail={torch.cuda.is_available()}", flush=True)
|
| 79 |
gc.collect()
|
| 80 |
if torch.cuda.is_available():
|
| 81 |
torch.cuda.empty_cache()
|
| 82 |
width, height = _round_dims(image)
|
| 83 |
+
print(f"[_run_pipe] dims w={width} h={height} steps={steps}", flush=True)
|
| 84 |
generator = torch.Generator(device=DEVICE).manual_seed(seed)
|
| 85 |
+
out = PIPE(
|
| 86 |
image=[image],
|
| 87 |
prompt=prompt,
|
| 88 |
negative_prompt=NEGATIVE_PROMPT,
|
|
|
|
| 92 |
true_cfg_scale=1.0,
|
| 93 |
generator=generator,
|
| 94 |
).images[0]
|
| 95 |
+
print(f"[_run_pipe] done size={out.size}", flush=True)
|
| 96 |
+
return out
|
| 97 |
|
| 98 |
|
| 99 |
# --- Server -------------------------------------------------------------------
|
|
|
|
| 101 |
HOME = Path(__file__).parent
|
| 102 |
|
| 103 |
|
| 104 |
+
@server.api(name="edit_image")
|
| 105 |
def edit_image(image: FileData, prompt: str) -> dict:
|
| 106 |
"""Edit an image guided by a text prompt using FireRed-Image-Edit 1.1."""
|
| 107 |
+
print(f"[edit_image] received prompt={prompt!r} path={image.get('path')}", flush=True)
|
| 108 |
if not prompt or not prompt.strip():
|
| 109 |
return {"error": "Please enter an edit prompt."}
|
| 110 |
src = Image.open(image["path"]).convert("RGB")
|
| 111 |
+
print(f"[edit_image] image opened size={src.size}", flush=True)
|
| 112 |
seed = random.randint(0, MAX_SEED)
|
| 113 |
+
print(f"[edit_image] calling _edit seed={seed}", flush=True)
|
| 114 |
result = _edit(src, prompt.strip(), seed, steps=4)
|
| 115 |
+
print(f"[edit_image] _edit returned size={result.size}", flush=True)
|
| 116 |
|
| 117 |
fd, out_path = tempfile.mkstemp(suffix=".png")
|
| 118 |
os.close(fd)
|
| 119 |
result.save(out_path)
|
| 120 |
+
print(f"[edit_image] saved to {out_path}", flush=True)
|
| 121 |
return {"image": FileData(path=out_path), "seed": seed}
|
| 122 |
|
| 123 |
|
|
|
|
| 127 |
|
| 128 |
|
| 129 |
if __name__ == "__main__":
|
| 130 |
+
server.launch(show_error=True)
|