diff --git a/ops/home/gen_ai_rooms.py b/ops/home/gen_ai_rooms.py new file mode 100644 index 0000000..b33c270 --- /dev/null +++ b/ops/home/gen_ai_rooms.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +"""Генерация изометрических рендеров комнат через Pollinations (бесплатно, без ключа). + +Вход: ops/home/renders/input//spec.json +Выход: ops/home/renders/ai/.jpg + веб-версии в renders/web/ +""" +import io +import json +import os +import time +import urllib.parse +import urllib.request + +OUT_AI = '/root/buryan-infra/ops/home/renders/ai' +OUT_WEB = '/root/buryan-infra/ops/home/renders/web' +IN_DIR = '/root/buryan-infra/ops/home/renders/input' + +BASE = 'https://image.pollinations.ai/prompt/' + +STYLE = ("isometric 2.5D cutaway room illustration, cozy modern interior, detailed furniture, " + "warm interior lighting, soft shadows, dark charcoal background, clean minimalist style, " + "high detail, no text, no people") + +PROMPTS = { + 'bedroom': ("cozy bedroom, double bed with wooden headboard and grey bedding, two wooden nightstands " + "with warm bedside lamps, tall wardrobe, writing desk with chair, wall-mounted TV, " + "ceiling track light with spotlights"), + 'office': ("home office room, large wooden desk with two monitors, ergonomic chair, wall-mounted TV, " + "white game console, tall wardrobe, air conditioner on wall, ceiling track light"), + 'danina': ("teenage bedroom with loft mezzanine, single bed, study desk, small sofa, wall-mounted TV, " + "wooden loft platform with metal ladder, wardrobe, ceiling track light on wooden beam"), + 'kitchen-living': ("open plan kitchen living room, wooden kitchen cabinets with stone countertop, " + "fridge, extractor hood, dining table with chairs, grey sofa, large wall-mounted TV, " + "open shelving unit, pendant lights"), + 'bathroom': ("small bathroom, white bathtub, glass shower, toilet, sink with mirror cabinet, " + "washing machine, LED strip lighting, white tiles"), + 'corridor': ("narrow entry corridor, tall wardrobe, wooden bench, full height mirror, shoe cabinet, " + "ceiling track light, warm wall lamps"), + 'laundry': ("small utility laundry room, washing machine, dryer, wooden shelving with storage boxes, " + "compact space"), + 'hall-way': ("small entrance hallway, wooden console table, mirror, hooks with coats, ceiling light"), +} + +SIZES = {'bedroom': (1024, 1024), 'office': (1024, 1024), 'danina': (1024, 1024), + 'kitchen-living': (1024, 768), 'bathroom': (1024, 1024), 'corridor': (768, 1024), + 'laundry': (1024, 1024), 'hall-way': (1024, 1024)} + + +def gen(key, attempt=1): + w, h = SIZES.get(key, (1024, 1024)) + prompt = (PROMPTS.get(key, key) + ", " + STYLE) + q = urllib.parse.quote(prompt) + url = ('%s%s?width=%d&height=%d&nologo=true&seed=%d&model=flux' + % (BASE, q, w, h, int(time.time()) % 100000)) + try: + with urllib.request.urlopen(url, timeout=180) as r: + data = r.read() + if len(data) < 5000: + return None, 'мало данных (%d б)' % len(data) + os.makedirs(OUT_AI, exist_ok=True) + path = os.path.join(OUT_AI, key + '.jpg') + open(path, 'wb').write(data) + return path, None + except Exception as e: + return None, str(e)[:120] + + +def main(): + from PIL import Image + os.makedirs(OUT_AI, exist_ok=True) + os.makedirs(OUT_WEB, exist_ok=True) + keys = sorted(PROMPTS.keys()) + results = [] + for key in keys: + name = key + sp = os.path.join(IN_DIR, key, 'spec.json') + if os.path.exists(sp): + try: + name = json.load(open(sp, encoding='utf-8')).get('name', key) + except Exception: + pass + t0 = time.time() + path, err = gen(key) + dt = round(time.time() - t0) + if path: + im = Image.open(path).convert('RGB') + # обрезаем водяной знак справа снизу + im = im.crop((0, 0, im.width - 90, im.height - 26)) if im.width > 400 else im + im.save(path, 'JPEG', quality=88, optimize=True) + wid = 1200 + hei = int(im.height * wid / im.width) + im.resize((wid, hei), Image.LANCZOS).save( + os.path.join(OUT_WEB, key + '.jpg'), 'JPEG', quality=84, optimize=True) + print(' %-16s %-22s %ss %d КБ' % (key, name, dt, os.path.getsize(path) // 1024)) + results.append(key) + else: + print(' %-16s ОШИБКА: %s' % (key, err)) + time.sleep(2) + print('\nсгенерировано: %d из %d' % (len(results), len(keys))) + + +if __name__ == '__main__': + main() diff --git a/ops/home/renders/ai/bathroom.jpg b/ops/home/renders/ai/bathroom.jpg new file mode 100644 index 0000000..d56db3a Binary files /dev/null and b/ops/home/renders/ai/bathroom.jpg differ diff --git a/ops/home/renders/ai/bedroom.jpg b/ops/home/renders/ai/bedroom.jpg new file mode 100644 index 0000000..8d7189c Binary files /dev/null and b/ops/home/renders/ai/bedroom.jpg differ diff --git a/ops/home/renders/ai/corridor.jpg b/ops/home/renders/ai/corridor.jpg new file mode 100644 index 0000000..66787eb Binary files /dev/null and b/ops/home/renders/ai/corridor.jpg differ diff --git a/ops/home/renders/ai/danina.jpg b/ops/home/renders/ai/danina.jpg new file mode 100644 index 0000000..ef868f3 Binary files /dev/null and b/ops/home/renders/ai/danina.jpg differ diff --git a/ops/home/renders/ai/hall-way.jpg b/ops/home/renders/ai/hall-way.jpg new file mode 100644 index 0000000..e088c67 Binary files /dev/null and b/ops/home/renders/ai/hall-way.jpg differ diff --git a/ops/home/renders/ai/kitchen-living.jpg b/ops/home/renders/ai/kitchen-living.jpg new file mode 100644 index 0000000..d45a1e4 Binary files /dev/null and b/ops/home/renders/ai/kitchen-living.jpg differ diff --git a/ops/home/renders/ai/laundry.jpg b/ops/home/renders/ai/laundry.jpg new file mode 100644 index 0000000..0261f97 Binary files /dev/null and b/ops/home/renders/ai/laundry.jpg differ diff --git a/ops/home/renders/ai/office.jpg b/ops/home/renders/ai/office.jpg new file mode 100644 index 0000000..d360a61 Binary files /dev/null and b/ops/home/renders/ai/office.jpg differ diff --git a/ops/home/renders/web/bathroom.jpg b/ops/home/renders/web/bathroom.jpg index 0f47701..083b965 100644 Binary files a/ops/home/renders/web/bathroom.jpg and b/ops/home/renders/web/bathroom.jpg differ diff --git a/ops/home/renders/web/bedroom.jpg b/ops/home/renders/web/bedroom.jpg index e725d25..adc7222 100644 Binary files a/ops/home/renders/web/bedroom.jpg and b/ops/home/renders/web/bedroom.jpg differ diff --git a/ops/home/renders/web/corridor.jpg b/ops/home/renders/web/corridor.jpg index d5641a2..eeeff79 100644 Binary files a/ops/home/renders/web/corridor.jpg and b/ops/home/renders/web/corridor.jpg differ diff --git a/ops/home/renders/web/danina.jpg b/ops/home/renders/web/danina.jpg index 62fbd9f..afd50ad 100644 Binary files a/ops/home/renders/web/danina.jpg and b/ops/home/renders/web/danina.jpg differ diff --git a/ops/home/renders/web/hall-way.jpg b/ops/home/renders/web/hall-way.jpg new file mode 100644 index 0000000..508e1cc Binary files /dev/null and b/ops/home/renders/web/hall-way.jpg differ diff --git a/ops/home/renders/web/kitchen-living.jpg b/ops/home/renders/web/kitchen-living.jpg index ac4698d..9d533ee 100644 Binary files a/ops/home/renders/web/kitchen-living.jpg and b/ops/home/renders/web/kitchen-living.jpg differ diff --git a/ops/home/renders/web/laundry.jpg b/ops/home/renders/web/laundry.jpg index 2e7dc98..88187e8 100644 Binary files a/ops/home/renders/web/laundry.jpg and b/ops/home/renders/web/laundry.jpg differ diff --git a/ops/home/renders/web/office.jpg b/ops/home/renders/web/office.jpg index 63a7e9c..0d7963c 100644 Binary files a/ops/home/renders/web/office.jpg and b/ops/home/renders/web/office.jpg differ