[HOME] img2img через FLUX Kontext (HF): 10 рендеров по реальным фото (спальня 5, кабинет 4) — галерея обновлена

This commit is contained in:
root committed 2026-11-07 22:12:37 +03:00
1 parent afd01f8055
commit 3ffcc08904
14 files changed
+148

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
import os
import shutil
import time
from gradio_client import Client, handle_file
SRC = "/root/buryan-infra/ops/home/plans/photos"
OUT = "/root/buryan-infra/ops/home/renders/img2img"
os.makedirs(OUT, exist_ok=True)
PROMPT = ("Convert this real room photo into a clean isometric 2.5D cutaway illustration. "
"Keep the SAME room layout, furniture positions, materials and lighting as in the photo. "
"Style: modern flat vector illustration, warm interior light, dark charcoal background, "
"detailed furniture, soft shadows, no text, no people.")
# по 1-2 фото на комнату
TASKS = {
"bedroom": ["spalnya-bed.jpg", "spalnya-window-tv.jpg"],
"office": ["office-1.jpg", "office-3.jpg"],
"bathroom": ["bath-1.jpg", "bath-2.jpg"],
"corridor": ["corridor-1.jpg", "corridor-2.jpg"],
"danina": ["danina-loft.jpg"],
"laundry": ["laundry-1.jpg"],
}
c = Client("black-forest-labs/FLUX.1-Kontext-Dev", verbose=False)
done = 0
fail = 0
for room, files in TASKS.items():
for i, fn in enumerate(files):
src = os.path.join(SRC, fn)
if not os.path.exists(src):
print(" %-16s нет файла %s" % (room, fn))
continue
for attempt in range(2):
try:
res = c.predict(input_image=handle_file(src), prompt=PROMPT,
seed=0, randomize_seed=True,
guidance_scale=2.5, steps=28, api_name="/infer")
path = res[0] if isinstance(res, (list, tuple)) else res
dst = os.path.join(OUT, "%s-%d.jpg" % (room, i + 1))
shutil.copy(path, dst)
print(" %-16s %-24s -> %s (%d КБ)" % (room, fn, os.path.basename(dst),
os.path.getsize(dst) // 1024))
done += 1
break
except Exception as e:
if attempt == 1:
print(" %-16s %-24s ОШИБКА: %s" % (room, fn, str(e)[:80]))
fail += 1
else:
time.sleep(10)
time.sleep(3)
print("\nготово: %d, ошибок: %d" % (done, fail))
+94
View File
@@ -0,0 +1,94 @@
import glob
import os
import shutil
import time
os.environ["HF_TOKEN"] = open('/root/.hf-token').read().strip()
from gradio_client import Client, handle_file # noqa: E402
TOKEN = os.environ["HF_TOKEN"]
SRC = "/root/buryan-infra/ops/home/plans/photos"
OUT = "/root/buryan-infra/ops/home/renders/img2img"
WEB = "/root/buryan-infra/ops/home/renders/web"
os.makedirs(OUT, exist_ok=True)
os.makedirs(WEB, exist_ok=True)
PROMPT = ("Convert this real room photo into a clean isometric 2.5D cutaway illustration. "
"Keep the SAME room layout, furniture positions, materials and lighting as in the photo. "
"Style: modern flat vector illustration, warm interior light, dark charcoal background, "
"detailed furniture, soft shadows, no text, no people.")
ROOMS = {
"bedroom": "spalnya-*.jpg",
"office": "office-*.jpg",
"bathroom": "bath-*.jpg",
"corridor": "corridor-*.jpg",
"danina": "danina-*.jpg",
"laundry": "laundry-*.jpg",
}
def client():
for kwargs in ({"hf_token": TOKEN}, {"token": TOKEN}, {}):
try:
return Client("black-forest-labs/FLUX.1-Kontext-Dev", verbose=False, **kwargs)
except TypeError:
continue
except Exception:
continue
return Client("black-forest-labs/FLUX.1-Kontext-Dev", verbose=False)
c = client()
print("клиент создан", flush=True)
done = fail = 0
for room, pattern in ROOMS.items():
files = sorted(glob.glob(os.path.join(SRC, pattern)))
if not files:
print(" %-12s фото нет" % room, flush=True)
continue
for i, src in enumerate(files, 1):
dst = os.path.join(OUT, "%s-%d.jpg" % (room, i))
if os.path.exists(dst) and os.path.getsize(dst) > 8000:
print(" %-12s %-26s уже есть" % (room, os.path.basename(src)), flush=True)
done += 1
continue
ok = False
for attempt in range(3):
try:
res = c.predict(input_image=handle_file(src), prompt=PROMPT,
seed=0, randomize_seed=True,
guidance_scale=2.5, steps=28, api_name="/infer")
path = res[0] if isinstance(res, (list, tuple)) else res
shutil.copy(path, dst)
print(" %-12s %-26s -> %s (%d КБ)" % (room, os.path.basename(src),
os.path.basename(dst),
os.path.getsize(dst) // 1024), flush=True)
done += 1
ok = True
break
except Exception as e:
msg = str(e)[:90]
print(" %-12s %-26s попытка %d: %s" % (room, os.path.basename(src), attempt + 1, msg), flush=True)
time.sleep(12)
if not ok:
fail += 1
time.sleep(2)
print("\nГОТОВО: %d, ошибок: %d" % (done, fail), flush=True)
# веб-версии: лучшее фото комнаты -> gallery
from PIL import Image # noqa: E402
for room in ROOMS:
cand = sorted(glob.glob(os.path.join(OUT, "%s-*.jpg" % room)))
if not cand:
continue
src = max(cand, key=lambda p: os.path.getsize(p))
im = Image.open(src).convert("RGB")
w = 1200
im.resize((w, int(im.height * w / im.width)), Image.LANCZOS).save(
os.path.join(WEB, room + ".jpg"), "JPEG", quality=85, optimize=True)
print(" галерея: %s <- %s" % (room, os.path.basename(src)), flush=True)
print("веб-версии обновлены", flush=True)
Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 75 KiB

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 KiB

After

Width:  |  Height:  |  Size: 76 KiB