screenshot-to-code README

The project's README from github.com/abi/screenshot-to-code. As one markdown file: README.md.

screenshot-to-code

Convert screenshots, mockups, Figma designs, and screen recordings into clean, functional code using AI. The easiest way to try this is using the official, hosted product at screenshottocode.com →

https://github.com/user-attachments/assets/ec08a5e6-9606-41c5-b03a-1bf47dfeba75

Supported stacks:

Default AI models:

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.

google in app quick 3

🛠 Getting Started

Choose the path that fits what you want to do:

Running locally requires API keys and a backend/frontend setup. The app has a React/Vite frontend and a FastAPI backend.

API keys

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

You can also set up OpenAI, Anthropic, and Gemini keys using the settings dialog in the frontend (click the gear icon after loading the app). Replicate must be configured in backend/.env as REPLICATE_API_KEY. The Settings dialog also shows whether screenshot preview is available on your backend.

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 chromium step 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 dev

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

Docker

If you have Docker installed, run this from the root directory:

echo "OPENAI_API_KEY=sk-your-key" > .env
docker-compose up -d --build

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

🙋‍♂️ FAQs

📚 Examples

NYTimes

Original Replica
Screenshot 2023-11-20 at 12 54 03 PM Screenshot 2026-06-15 at 3 06 37 PM

Instagram

https://github.com/user-attachments/assets/a335a105-f9cc-40e6-ac6b-64e5390bfc21

Hacker News

https://github.com/user-attachments/assets/205cb5c7-9c3c-438d-acd4-26dfe6e077e5

screenshot-to-code (abi/screenshot-to-code)

Searching Database…

这是什么?Screenshot-to-code 可以把截图、模型图、Figma 设计稿和屏幕录像转换成整洁、可用的代码,背后使用的是 GPT、Claude、Gemini 等 AI 模型。
这是托管的网页应用,还是需要我自己运行的程序?两种都有:screenshottocode.com 提供托管版本,适合快速使用;你也可以在本地运行,用 React/Vite 前端和 FastAPI 后端自行部署,并按需定制。
我该怎么在本地运行它?用 Poetry 运行后端(先执行 pip install --upgrade poetry),再单独运行 Vite 前端;或者使用项目自带的 Docker 配置,一次性启动整个应用。
我需要 OpenAI、Anthropic 或 Gemini 的 API 密钥吗?需要,至少要有 OPENAI_API_KEY、ANTHROPIC_API_KEY、GEMINI_API_KEY 其中之一;为了获得最佳质量和资源提取效果,强烈建议同时配置 Gemini 和 Replicate 的密钥。
我能用免费的本地模型代替付费 API 吗?支持 Ollama 开源模型,但不推荐,因为和默认的商业模型相比,它生成的结果质量较差。
这个程序在 Windows 上也能运行吗,还是只能在 Mac/Linux 上用?可以,它是跨平台的;README 中还专门提到了 Windows 下编辑 .env 文件时 UTF-8 编码错误的修复方法。
支持哪些输出技术栈?HTML+Tailwind、HTML+CSS、React+Tailwind、Vue+Tailwind、Bootstrap 和 Ionic+Tailwind。
它能把屏幕录像也转换成代码吗?能,它也支持录制网站的实际运行过程,并将其转换为可用的原型。
它只是盲目生成代码,还是能检查自己的成果?安装了 Chromium 之后(通过 Playwright 安装,或在 Docker 镜像中自动安装),智能体可以在无头浏览器中渲染生成的页面,并通过视觉方式验证结果。
Replicate 在这个项目中有什么用?Replicate 为图像编辑、背景去除以及 AI 图像生成功能(如 z-image-turbo 模型)提供支持,没有 REPLICATE_API_KEY 就无法使用这些功能。
Creator
abi
Size
10.9 MB
Stars
80.5K
Updated
CommitOct 09
Age
2y
Commits · 90 Days