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

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

Description and use

Talivo is a self‑hosted AI website builder that charges per generation, using FastAPI for the API and Gemini for HTML generation, with atomic credit management and refund on failure.

Problem

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.

Outcome

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.

Workflow

  • 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.

Evidence

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.

Source

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

Source

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

Source

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)

Source

  • Record date: 2026-10-05T10:41:01.031Z