umynameislove/FactoryLens
GitHub: umynameislove/FactoryLens
工业视觉缺陷分析 AI copilot,通过上传产品图片与测试日志辅助工程师完成异常评估、已知问题检索、根因假设与报告生成。
Stars: 1 | Forks: 0
# FactoryLens AI
用于**工业视觉缺陷分析、根本原因调查和工程报告生成**的 AI copilot。上传一张产品图片(+ 可选的测试日志和已知问题文档)以及一个问题;即可获取异常评估、相关的已知问题、根本原因假设、后续行动以及结构化的工程报告。
## 技术栈
- **后端:** FastAPI · SQLAlchemy 2.0 · PostgreSQL + pgvector
- **运行时:** Docker · docker-compose
- **AI(开发中):** LangChain · OpenAI
- **数据集:** MVTec AD — `hazelnut` 子集
## 快速开始
存活检测端点不需要数据库:
```
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
uvicorn factorylens.main:app --reload # http://127.0.0.1:8000/health
pytest
```
`POST /analyze`(multipart:`image`、`test_logs`、`question`、`category`)
目前返回一个契约有效的 stub。
## 使用 Docker 的本地数据库
复制占位环境文件,并将其中的密码替换为仅在本地使用的真实值,需要同时修改 `POSTGRES_PASSWORD` 和 `DATABASE_URL`。`.env` 已被 gitignore,绝对不能提交。
```
cp .env.example .env
docker compose build
docker compose up -d
docker compose exec app python -m factorylens.db.init_db
```
分别检查这两个健康信号:
```
curl http://127.0.0.1:8000/health
curl http://127.0.0.1:8000/readyz
```
- `/health` 是纯粹的应用存活检测,从不查询数据库。
- `/readyz` 执行 `SELECT 1`,并在数据库不可用时返回 HTTP 503。
停止技术栈运行,但不删除命名的 PostgreSQL 卷:
```
docker compose down
```
当前的 schema 是通过 `factorylens.db.init_db` 幂等创建的。
在 schema 开始演进之前,Alembic 迁移被特意推迟。
## 填充演示数据
在本地技术栈运行后,加载已提交的 hazelnut 示例日志:
```
docker compose up -d
docker compose exec app python -m factorylens.db.init_db
docker compose exec app python -m factorylens.seed
# 替换现有的 test-log 行:
docker compose exec app python -m factorylens.seed --reset
```
在不使用 `--reset` 的情况下,填充操作是幂等的。MVTec 图像清单属于视觉 pipeline,不会被此命令加载到数据库中。
## 架构
下方的实心节点目前已实现。虚线节点要么是契约有效的 `/analyze` stub,要么是计划中的集成;它们不作为运行中的功能呈现。
```
flowchart LR
Client["API consumer"]:::external
Uploads["Image and CSV uploads"]:::implemented
Analyze["/analyze stub"]:::stub
Services["Storage, ingest, seed, config"]:::implemented
DB["PostgreSQL + test_logs
pgvector extension enabled"]:::implemented Files["Local uploads"]:::implemented Vision["Vision baseline
standalone"]:::stub Agent["Bounded agent and five tools"]:::planned Vectors["Known-issue vectors"]:::planned UI["Streamlit dashboard"]:::planned Client --> Uploads Client --> Analyze Uploads --> Services Services --> DB Services --> Files Analyze -. "planned integration" .-> Agent Agent -. "planned wrapper" .-> Vision Agent -. "planned retrieval" .-> Vectors UI -. "planned API client" .-> Analyze classDef implemented fill:#e8f5e9,stroke:#2e7d32,stroke-width:2px,color:#1b1b1b; classDef stub fill:#fff3e0,stroke:#ef6c00,stroke-width:2px,stroke-dasharray:2 3,color:#1b1b1b; classDef planned fill:#e3f2fd,stroke:#1565c0,stroke-width:2px,stroke-dasharray:7 5,color:#1b1b1b; classDef external fill:#f5f5f5,stroke:#616161,stroke-width:2px,color:#1b1b1b; ``` 请参阅[架构](docs/architecture.md)以获取完整的组件映射、已实现的请求流、目标 `/analyze` 序列以及证据表。 ## 布局 ``` working/ src/factorylens/ # API, config, schemas, and SQLAlchemy database layer tests/ # smoke + contract tests docs/MVP_SPEC.md # product + tool contract (source of truth) Dockerfile docker-compose.yml ``` 内部计划/跟踪位于**此仓库之外**的 `../_tracking/` 目录中(从未提交过)。 ## 贡献规则 禁止直接提交到 `main`。流程:**issue → 分支 → 小提交 → PR(目标 / 更改 / 测试 / 风险 + 标签) → 审查 → squash 合并。**
pgvector extension enabled"]:::implemented Files["Local uploads"]:::implemented Vision["Vision baseline
standalone"]:::stub Agent["Bounded agent and five tools"]:::planned Vectors["Known-issue vectors"]:::planned UI["Streamlit dashboard"]:::planned Client --> Uploads Client --> Analyze Uploads --> Services Services --> DB Services --> Files Analyze -. "planned integration" .-> Agent Agent -. "planned wrapper" .-> Vision Agent -. "planned retrieval" .-> Vectors UI -. "planned API client" .-> Analyze classDef implemented fill:#e8f5e9,stroke:#2e7d32,stroke-width:2px,color:#1b1b1b; classDef stub fill:#fff3e0,stroke:#ef6c00,stroke-width:2px,stroke-dasharray:2 3,color:#1b1b1b; classDef planned fill:#e3f2fd,stroke:#1565c0,stroke-width:2px,stroke-dasharray:7 5,color:#1b1b1b; classDef external fill:#f5f5f5,stroke:#616161,stroke-width:2px,color:#1b1b1b; ``` 请参阅[架构](docs/architecture.md)以获取完整的组件映射、已实现的请求流、目标 `/analyze` 序列以及证据表。 ## 布局 ``` working/ src/factorylens/ # API, config, schemas, and SQLAlchemy database layer tests/ # smoke + contract tests docs/MVP_SPEC.md # product + tool contract (source of truth) Dockerfile docker-compose.yml ``` 内部计划/跟踪位于**此仓库之外**的 `../_tracking/` 目录中(从未提交过)。 ## 贡献规则 禁止直接提交到 `main`。流程:**issue → 分支 → 小提交 → PR(目标 / 更改 / 测试 / 风险 + 标签) → 审查 → squash 合并。**
标签:AV绕过, FastAPI, PostgreSQL, 大语言模型应用, 工业AI, 测试用例, 缺陷检测, 请求拦截, 逆向工具