36 lines
1.6 KiB
Python
36 lines
1.6 KiB
Python
import os
|
|
import shutil
|
|
import sys
|
|
import time
|
|
|
|
os.environ["HF_TOKEN"] = open('/root/.hf-token').read().strip()
|
|
from gradio_client import Client, handle_file # noqa: E402
|
|
|
|
PHOTO = "/root/buryan-infra/ops/home/plans/photos/bath-1.jpg"
|
|
DST = "/root/buryan-infra/ops/home/renders/img2img/bathroom-bath-1.jpg"
|
|
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.")
|
|
|
|
t0 = time.time()
|
|
print("1) создаю клиента...", flush=True)
|
|
c = Client("black-forest-labs/FLUX.1-Kontext-Dev", verbose=True,
|
|
hf_token=os.environ["HF_TOKEN"])
|
|
print(" клиент готов за %.0f c" % (time.time() - t0), flush=True)
|
|
|
|
print("2) отправляю фото...", flush=True)
|
|
try:
|
|
res = c.predict(input_image=handle_file(PHOTO), prompt=PROMPT,
|
|
seed=0, randomize_seed=True, guidance_scale=2.5, steps=28,
|
|
api_name="/infer")
|
|
print(" ответ за %.0f c:" % (time.time() - t0), str(res)[:150], flush=True)
|
|
path = res[0] if isinstance(res, (list, tuple)) else res
|
|
if path and os.path.exists(path):
|
|
shutil.copy(path, DST)
|
|
print(" СОХРАНЕНО:", DST, os.path.getsize(DST) // 1024, "КБ", flush=True)
|
|
else:
|
|
print(" файл не найден:", path, flush=True)
|
|
except Exception as e:
|
|
print(" ОШИБКА за %.0f c: %s" % (time.time() - t0, str(e)[:200]), flush=True)
|