NanoImg 工厂
NanoImg Factory is a personal, open-source AI assistant that turns short briefs into deliverable visual assets. It combines a static PWA frontend with a Python proxy that connects to Google AI Studio (Nano Banana) for text-to-image generation. No database required. 项目概述:NanoImg Factory 是一款开源的个人 AI 助手,将简短需求转化为可交付的视觉素材;它使用静态 PWA 前端和连接 Google AI Studio(Nano Banana)的 Python 代理,无需数据库。
快速开始
本地(手动)
- Copy environment config:
- 复制环境配置:
cp config/.env.example config/.env
- Start backend:
2. 启动后端:
cd src/backend python -m venv .venv source .venv/bin/activate pip install -r requirements.txt uvicorn app:app --host 0.0.0.0 --port 8003
- Serve frontend:
3. 启动前端静态服务:
cd src/frontend python -m http.server 8001 - Open
http://localhost:8001. 4. 打开http://localhost:8001。
Docker Compose 部署
cp config/.env.example config/.env
# set GOOGLE_AI_STUDIO_API_KEY in config/.env
# 在 config/.env 中填写 GOOGLE_AI_STUDIO_API_KEY
docker compose up -d --build安装与部署指南
- Recommended: Docker Compose + Nginx frontend container.
- 推荐:使用 Docker Compose + Nginx 前端容器。
- Backend only exposes
/api/*endpoints. - 后端仅暴露
/api/*接口。
See docker/centos-deploy.sh for a CentOS-ready bootstrap script.
可参考 docker/centos-deploy.sh 获取适配 CentOS 的启动脚本。
使用示例
- Choose a template in the Template Market.
- 在模板市场选择一个模板。
- Fill in industry, audience, and selling points. 2. 填写行业、受众和卖点。
- Click Generate Prompt then Batch Generate. 3. 点击 Generate Prompt,然后点击 Batch Generate。
- Download the delivery pack as a ZIP. 4. 将交付包下载为 ZIP。
- Use
demo.htmlfor API key validation and live tests. 5. 使用demo.html验证 API 密钥并进行实时测试。 - Open
http://localhost:8001/docs/index.htmlfor a lightweight web docs page. 6. 打开http://localhost:8001/docs/index.html查看轻量文档页面。
API 文档
Base URL: http://localhost:8003/api
基础地址:http://localhost:8003/api
-
GET /health- 获取健康状态
- Response:
{ "status": "ok", "provider": "nano-banana", "mock": false } - 响应:
{ "status": "ok", "provider": "nano-banana", "mock": false }
-
POST /key/status- 校验密钥状态
- Body:
{ "api_key": "...", "base_url": "..." } - 请求体:
{ "api_key": "...", "base_url": "..." } - Headers:
X-API-Key,X-Base-Url - 请求头:
X-API-Key,X-Base-Url
-
POST /generate- 生成图片
- Body:
{ "prompt": "...", "negative_prompt": "...", "count": 1, "return_type": "base64" } - 请求体如上
- Headers:
X-API-Key,X-Base-Url,X-Model,X-Return-Type - 请求头:
X-API-Key,X-Base-Url,X-Model,X-Return-Type
贡献指南
- Fork the repo and create a feature branch.
- Fork 仓库并创建功能分支。
- Keep changes focused and add tests when needed.
- 变更应聚焦,必要时补充测试。
- Open a PR with a clear summary and screenshots for UI changes.
- 提交 PR 时提供清晰摘要;如有 UI 变更请附截图。
MIT. See LICENSE.
许可证:MIT,详见 LICENSE。
部署说明
最低系统要求
- CPU: 2 cores
- CPU:2 核
- RAM: 4 GB
- 内存:4 GB
- Disk: 2 GB free
- 磁盘:2 GB 可用
- Docker: 24+
- Docker:24+
分步部署
- Install Docker + Compose (or use
docker/centos-deploy.sh).- 安装 Docker 与 Compose(或使用
docker/centos-deploy.sh)。
- 安装 Docker 与 Compose(或使用
- Copy config:
cp config/.env.example config/.env. 2. 复制配置:cp config/.env.example config/.env。 - Add your Google AI Studio key:
GOOGLE_AI_STUDIO_API_KEY. 3. 填写 Google AI Studio 密钥:GOOGLE_AI_STUDIO_API_KEY。 - Run:
docker compose up -d --build. 4. 运行:docker compose up -d --build。 - Open:
http://<server-ip>:8001. 5. 打开:http://<server-ip>:8001。
环境变量
GOOGLE_AI_STUDIO_API_KEY: API key for Nano Banana.GOOGLE_AI_STUDIO_API_KEY:Nano Banana 的 API 密钥。GOOGLE_AI_STUDIO_BASE_URL: defaults tohttps://generativelanguage.googleapis.com/v1beta(the proxy builds/models/{model}:predictfor Imagen).GOOGLE_AI_STUDIO_BASE_URL:默认https://generativelanguage.googleapis.com/v1beta(代理会拼接/models/{model}:predict)。GOOGLE_AI_STUDIO_MODEL: defaults toimagen-4.0-fast-generate-001.GOOGLE_AI_STUDIO_MODEL:默认imagen-4.0-fast-generate-001。USE_MOCK: settruefor placeholder images without API access.USE_MOCK:设为true时在无 API 访问时返回占位图。
常见问题
- Why do I see placeholder images?
- 为何看到占位图?
- The backend runs in mock mode or no API key is set.
- 后端处于 mock 模式或未设置 API 密钥。
- Can I host templates?
- 可以托管模板吗?
- Yes. Share JSON packs and import them in the Template Market.
- 可以,分享 JSON 包并在模板市场导入。
- Where are the default templates?
- 默认模板在哪里?
src/frontend/config/templates.json(static assets used by the PWA).src/frontend/config/templates.json(PWA 使用的静态资源)。
- How do I validate my API key?
- 如何验证我的 API 密钥?
- Use
demo.html(API Key Lab) and click Validate Key. - 使用
demo.html(API Key Lab)并点击 Validate Key。