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

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

说明与用途

Talivo 是一个自托管的 AI 网站生成器,使用 FastAPI 作为后端,Gemini 生成完整 HTML,按信用计费并在失败时退款。

问题

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