把截图、设计稿和屏幕录制转换为可预览、可复制的前端代码。在线体验: screenshot-to-code-blue.vercel.app。
本项目基于 abi/screenshot-to-code 二次开发,并继续遵循 MIT License。
youtube.mp4
Supported stacks:
- HTML + Tailwind
- HTML + CSS
- React + Tailwind
- Vue + Tailwind
- Bootstrap
- Ionic + Tailwind
Default AI models:
- Gemini 3 Flash Preview and Gemini 3.1 Pro Preview - the best models
- GPT-5.5 and GPT-5.4 Mini
- Claude Opus 4.6, Claude Opus 4.8
- z-image-turbo (using Replicate) for image generation
See the Examples section below for more demos.
Screenshot to Code also supports taking a screen recording of a website in action and turning that into a functional prototype.
可以直接打开在线版本,也可以在本地运行并继续定制。
Running locally requires API keys and a backend/frontend setup. The app has a React/Vite frontend and a FastAPI backend.
You need at least one model provider key (OpenAI, Anthropic, or Gemini). Gemini and Replicate are strongly recommended for the best quality of screenshot-to-code accuracy — Gemini powers asset extraction (reusing the real logos/images from your screenshot) and Replicate powers image generation, background removal, and image editing. Adding all four keys gives the best results and lets you compare multiple models per generation.
| Key | Required? | What it unlocks |
|---|---|---|
OPENAI_API_KEY |
One of these three | GPT code-gen variants (GPT-5.5, GPT-5.4 Mini) |
ANTHROPIC_API_KEY |
One of these three | Claude code-gen variants (Opus 5, Opus 4.8, Fable 5, Sonnet 4.6) |
GEMINI_API_KEY |
One of these three — strongly recommended | Gemini code-gen variants (3 Flash, 3.1 Pro); extracts real assets from the screenshot; required for video mode |
REPLICATE_API_KEY |
Strongly recommended | Image editing, background removal, and Replicate-backed image generation — without it, edit_images and remove_backgrounds are unavailable |
With more keys, the app automatically picks a stronger mix of models per variant; with a single key it uses that provider's models only.
If you'd like to run the app with Ollama open-source models (not recommended due to poor-quality results), follow this comment.
Run the backend (I use Poetry for package management; run pip install --upgrade poetry if you don't have it):
cd backend
echo "OPENAI_API_KEY=sk-your-key" > .env
echo "ANTHROPIC_API_KEY=your-key" >> .env
echo "GEMINI_API_KEY=your-key" >> .env
echo "REPLICATE_API_KEY=r8_your-key" >> .env
poetry install
# Install the Chromium browser used by the screenshot preview tool.
# On Linux, use `poetry run playwright install --with-deps chromium` to also
# install the required system libraries (needs sudo/apt).
poetry run playwright install chromium
poetry env activate
# run the printed command, e.g. source /path/to/venv/bin/activate
poetry run uvicorn main:app --reload --port 7001在线版本可在设置中填写 OpenAI、Anthropic 或 Gemini Key。Key 只保存在当前页面内存中,刷新或关闭页面后即清除。Replicate 仅支持通过本地 backend/.env 配置。设置页也会显示后端是否支持自动截图预览。
Screenshot preview (optional) lets the agent render its own generated page in a headless browser and visually check its work. It's enabled automatically once Chromium is installed (the
playwright install chromiumstep above, or automatically in the Docker image). If Chromium is missing, the app just skips the tool — the Settings dialog shows whether it's available.
Run the frontend:
cd frontend
pnpm install
pnpm devOpen http://localhost:5173 to use the app.
If you prefer to run the backend on a different port, update VITE_WS_BACKEND_URL in frontend/.env.local.
If you have Docker installed, run this from the root directory:
echo "OPENAI_API_KEY=sk-your-key" > .env
docker-compose up -d --buildThe app will be up and running at http://localhost:5173. Note that you can't develop the application with this setup, as file changes won't trigger a rebuild.
This fork can deploy the Vite frontend and FastAPI backend together in one Vercel project. Select the Services framework preset and apply these non-secret environment variables to both Production and Preview:
BACKEND_PATH_PREFIX=/backend
VITE_BACKEND_PATH_PREFIX=/backend
IS_PROD=true
LOCAL_ASSET_TOOLS_ENABLED=false
LOCAL_ASSET_DIR=/tmp/screenshot-to-code/local-assets
LOGS_PATH=/tmp/screenshot-to-code
PROMPT_REPORTS_ENABLED=falseThe backend keeps its existing internal routes and is mounted under
/backend, including:
- WebSocket generation:
/backend/generate-code - Backend capabilities:
/backend/api/capabilities - Temporary generated assets:
/backend/local-assets/*
Provider credentials use browser BYOK for this deployment. Enter an OpenAI, Anthropic, or Gemini key in the application's Settings dialog. Do not add provider keys to the Vercel project or commit them to Git.
IS_PROD=true disables custom OpenAI Base URLs in the public deployment.
LOCAL_ASSET_TOOLS_ENABLED=false disables save_assets and extract_assets
because Vercel /tmp storage is ephemeral and cannot provide durable public
asset URLs across Function instances. Screenshot input and core code generation
remain available; durable asset extraction can be added later with object
storage.
The backend service pins Python 3.12 in backend/.python-version, declares
runtime dependencies through PEP 621 in backend/pyproject.toml, and commits
backend/uv.lock. Vercel's Python builder therefore uses the same dependency
set verified locally while Poetry remains available for development.
Vercel Hobby Functions can keep a generation connection open for at most 300
seconds. The first deployment does not bundle Chromium, so the optional
screenshot-preview tool is unavailable; core screenshot-to-code generation
continues to work. The /backend prefixes are opt-in, so the local development
commands above continue to use the existing unprefixed backend routes.
- I'm running into an error when setting up the backend. How can I fix it? See Troubleshooting.
- How do I get an OpenAI API key? See https://github.com/wyf027/screenshot-to-code/blob/main/Troubleshooting.md
- How can I configure an OpenAI proxy? If you're not able to access the OpenAI API directly, for example because of country restrictions, you can try a VPN or configure the OpenAI base URL to use a proxy. Set
OPENAI_BASE_URLinbackend/.envor directly in the UI in the settings dialog. Make sure the URL hasv1in the path, for example:https://xxx.xxxxx.xxx/v1. - How can I update the backend host that my frontend connects to? Configure
VITE_HTTP_BACKEND_URLandVITE_WS_BACKEND_URLinfrontend/.env.local. For example, setVITE_HTTP_BACKEND_URL=http://124.10.20.1:7001. - Seeing UTF-8 errors when running the backend? On Windows, open the
.envfile with Notepad++, then go to Encoding and select UTF-8. - How can I provide feedback? Open an issue in https://github.com/wyf027/screenshot-to-code/issues.
NYTimes
| Original | Replica |
|---|---|
![]() |
![]() |
instagram.mp4
Hacker News


