Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

How I built a credit‑based AI website builder with FastAPI and Gemini

Описание и применение

Talivo – самодостаточный генератор сайтов на основе Gemini, где пользователи платят за каждый запрос, а баланс кредитов управляется атомарно.

Задача

Provide a self‑hosted AI website builder that freelancers or agencies can run under their own brand and charge customers, avoiding the typical platform‑rent model.

Результат

Talivo allows users to generate fully styled, responsive HTML sites from natural language prompts, with a credit‑based billing model that prevents negative balances and refunds on failure.

Рабочий процесс

  • 1. User signs up and receives a credit balance.
  • 2. User submits a prompt to generate a website.
  • 3. The backend checks credits atomically and deducts one credit.
  • 4. The backend calls Gemini with a system prompt that forces a single self‑contained HTML document.
  • 5. The response is cleaned to remove any code fences and validated to contain HTML.
  • 6. If generation succeeds, the HTML is returned; if it fails, the credit is refunded and an error is returned.

Доказательства

The goal: A user signs up, types something like "a warm website for a family bakery in Bologna", and gets back a complete, styled website. Every generation costs credits.

Источник

The naive version looks like this: # ❌ Don't do this user = get_user(user_id) if user.credits > 0: user.credits -= 1 save(user)

Источник

def spend_credit(db, user_id: int) -> bool: cur = db.execute("UPDATE users SET credits = credits - 1 WHERE id = ? AND credits > 0", (user_id,)) db.commit() return cur.rowcount == 1

Источник

def generate_site(prompt: str) -> str: response = client.models.generate_content(model=GEMINI_MODEL, contents=prompt, config={"system_instruction": SYSTEM_PROMPT}), return clean_html(response.text)

Источник

  • Дата записи: 2026-10-05T10:41:01.031Z