Anas-Majeed1/AI-Incident-Verification-System

GitHub: Anas-Majeed1/AI-Incident-Verification-System

一个基于AI的应急事件验证系统,通过多维度智能评分和语音交互验证,帮助应急响应团队高效筛选和验证事件报告的真实性。

Stars: 0 | Forks: 0

# AI Incident Verifier 一个 AI 驱动的事件验证系统,旨在通过智能事件报告和验证工作流程,简化应急响应流程。 ## 📋 概述 AI Incident Verifier 是一个全栈应用程序,结合了现代 Web 技术与 AI 驱动的事件分析功能。它通过以下方式帮助应急响应团队高效验证和分析事件报告: - **实时事件报告**,包含详尽的详细信息 - **AI 驱动的验证**,使用多维度评分(位置、时间、媒体、报告者一致性等) - **管理员仪表板**,用于事件管理和验证规则配置 - **语音验证交互**,使用 Gemini Live API - **用户身份认证**,具有基于角色的访问控制 ## 🏗️ 架构 ### 技术栈 **后端 (Backend):** - **Framework**: FastAPI + Uvicorn - **Database**: PostgreSQL with SQLAlchemy ORM - **Authentication**: JWT tokens with bcrypt - **AI Integration**: Google Gemini, OpenAI - **Async Processing**: asyncpg 用于异步数据库操作 - **API Documentation**: Swagger (OpenAPI) **前端 (Frontend):** - **Framework**: Next.js 16 with TypeScript - **Styling**: Tailwind CSS - **Animations**: Framer Motion - **UI Components**: Lucide React Icons, React Hot Toast - **State Management**: React Context API ### 项目结构 ``` Incident_verification/ ├── backend/ # FastAPI application │ ├── app/ │ │ ├── api/ # API routes (v1) │ │ │ └── v1/ # Authentication, reports, verification endpoints │ │ ├── models/ # SQLAlchemy ORM models │ │ ├── schemas/ # Pydantic validation schemas │ │ ├── services/ # Business logic │ │ │ ├── verification/ # Scoring modules (consistency, duplicate, location, media, etc.) │ │ │ └── voice/ # Gemini Live API integration │ │ ├── core/ # Configuration, security, error handling │ │ ├── db/ # Database initialization │ │ ├── constants/ # Application constants │ │ └── utils/ # Utility functions │ ├── migrations/ # Alembic database migrations │ ├── scripts/ # Admin creation and data seeding │ └── requirements.txt # Python dependencies │ ├── frontend/ # Next.js application │ ├── app/ # App router pages │ │ └── admin/ # Admin panels (dashboard, incidents, users, verification) │ ├── components/ # Reusable React components │ ├── lib/ # Utilities and API client │ └── package.json # Node dependencies │ └── README.md # This file ``` ## 🚀 快速开始 ### 前置条件 - **Backend**: Python 3.9+, PostgreSQL 12+ - **Frontend**: Node.js 18+, npm 或 yarn - **Environment Variables**: 参见 [配置说明](#configuration) 章节 ### 安装说明 #### 1. 克隆 Repository ``` git clone https://github.com/yourusername/incident-verification.git cd incident-verification ``` #### 2. Backend 设置 ``` cd backend # 创建虚拟环境 python -m venv venv # 激活虚拟环境 # 在 Windows 上: venv\Scripts\activate # 在 macOS/Linux 上: source venv/bin/activate # 安装依赖 pip install -r requirements.txt # 创建 .env 文件(如有 .env.example 可从中复制) # 配置数据库和 API keys ``` #### 3. Frontend 设置 ``` cd ../frontend # 安装依赖 npm install # 或 yarn install # 创建包含 backend API URL 的 .env.local 文件 echo "NEXT_PUBLIC_API_URL=http://localhost:8001/api/v1" > .env.local ``` ### 配置说明 #### 后端环境变量 (.env) ``` # Application DEBUG=true ENVIRONMENT=development BASE_URL=http://localhost:8001 # Database DB_NAME=Incident-DB DB_USER=postgres DB_PASSWORD=your_password DB_HOST=localhost DB_PORT=5432 # CORS CORS_ORIGINS=["http://localhost:3000"] # Authentication SECRET_KEY=your_secret_key_here ALGORITHM=HS256 ACCESS_TOKEN_EXPIRE_MINUTES=30 # AI Services OPENAI_API_KEY=your_openai_key GOOGLE_GENAI_API_KEY=your_google_genai_key # Rate Limiting RATE_LIMIT_ENABLED=true RATE_LIMIT_CALLS=100 RATE_LIMIT_PERIOD=3600 ``` #### 前端环境变量 (.env.local) ``` NEXT_PUBLIC_API_URL=http://localhost:8001/api/v1 ``` ## 🗄️ 数据库设置 ### 1. 创建 PostgreSQL 数据库 ``` createdb "Incident-DB" # 或使用 psql psql -U postgres -c "CREATE DATABASE \"Incident-DB\";" ``` ### 2. 运行迁移 ``` cd backend # 应用所有迁移 alembic upgrade head # 初始创建(可选,如果使用 init_db) python -m scripts.create_admin # Creates default admin user python -m scripts.seed_verification_rules # Seeds default verification rules ``` ### 3. 验证设置 ``` # 测试数据库连接 python -c "from app.db.database import engine; print('Database connected!')" ``` ## 🏃 运行应用程序 ### 开发模式 **终端 1 - Backend:** ``` cd backend source venv/bin/activate # On Windows: venv\Scripts\activate uvicorn main:app --reload --host 0.0.0.0 --port 8001 ``` **终端 2 - Frontend:** ``` cd frontend npm run dev # 或 yarn dev ``` 应用程序可通过以下地址访问: - **Frontend**: http://localhost:3000 - **Backend API**: http://localhost:8001 - **API Documentation**: http://localhost:8001/docs - **ReDoc**: http://localhost:8001/redoc ## 📡 API 端点 ### 身份认证 (Authentication) - `POST /api/v1/auth/register` — 注册新用户 - `POST /api/v1/auth/login` — 登录并获取访问令牌 - `GET /api/v1/auth/me` — 获取当前用户资料 ### 事件报告 (Incident Reports) - `POST /api/v1/reports` — 提交新的事件报告 - `GET /api/v1/reports` — 列出所有报告 - `GET /api/v1/reports/{id}` — 获取报告详情 - `PUT /api/v1/reports/{id}` — 更新报告 - `DELETE /api/v1/reports/{id}` — 删除报告 ### 验证 (Verification) - `POST /api/v1/verification/verify` — 对事件运行验证 - `GET /api/v1/verification/rules` — 获取验证规则 - `POST /api/v1/verification/call` — 启动语音验证通话 ## 🤖 验证系统 验证模块使用多种评分算法来评估事件的可信度: 1. **Consistency Scorer** — 检查报告细节的内部一致性 2. **Duplicate Scorer** — 识别重复/相似的报告 3. **Location Scorer** — 验证位置数据和地理一致性 4. **Media Scorer** — 分析附件媒体的真实性 5. **Reporter Scorer** — 评估报告者的可靠性指标 6. **Temporal Scorer** — 检查事件之间的时间一致性 实现细节请参见 [backend/app/services/verification/](backend/app/services/verification/)。 ## 🎤 语音验证 该系统与 Google Gemini Live API 集成,实现实时基于语音的验证: - **Endpoint**: `POST /api/v1/verification/call` - **WebSocket Support**: 实时流式音频验证 - **Multi-turn Conversation**: 自然验证对话 详情请参见 [backend/app/services/voice/gemini_live.py](backend/app/services/voice/gemini_live.py)。 ## 🧪 测试 ``` # Backend 测试(如果配置了 pytest) cd backend pytest # Frontend 测试(如果配置了 jest) cd frontend npm test ``` ## 📦 生产环境构建 ### Backend ``` cd backend # 安装生产环境依赖 pip install -r requirements.txt # 使用生产环境 ASGI server (gunicorn) 运行 pip install gunicorn gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app ``` ### Frontend ``` cd frontend # 构建 Next.js 应用 npm run build # 启动生产环境服务器 npm start ``` ## 🔒 安全性 - 基于 JWT 的身份认证,使用 bcrypt 哈希 - CORS 中间件用于跨域请求 - 通过 Pydantic schemas 进行输入验证 - 通过 SQLAlchemy ORM 防止 SQL 注入 - API 端点的速率限制 - 环境变量中的安全密钥处理 ## 📝 数据库迁移 ### 创建新迁移 ``` cd backend # 创建空迁移 alembic revision --autogenerate -m "Description of changes" # 检查 migrations/versions/ 中生成的迁移文件 ``` ### 应用迁移 ``` # 应用所有待处理的迁移 alembic upgrade head # 回滚一个版本 alembic downgrade -1 # 查看迁移历史 alembic history ``` 详细的迁移说明,请参见 [backend/MIGRATION_GUIDE.md](backend/MIGRATION_GUIDE.md)。 ## 🐛 故障排除 ### 数据库连接问题 ``` # 验证 PostgreSQL 连接 psql -U postgres -h localhost -d "Incident-DB" -c "SELECT 1" # 检查环境变量 cd backend && python -c "from app.core.config import settings; print(settings.DATABASE_URL)" ``` ### Backend 无法启动 ``` # 确保虚拟环境已激活 # 检查 Python 版本 (3.9+) python --version # 重新安装依赖 pip install --force-reinstall -r requirements.txt ``` ### Frontend 构建错误 ``` # 清除 Next.js 缓存 rm -rf frontend/.next # 重新安装 node modules cd frontend rm -rf node_modules package-lock.json npm install ``` ## 📚 文档 - **Backend API Docs**: http://localhost:8001/docs (Swagger) - **Backend API Docs**: http://localhost:8001/redoc (ReDoc) - [数据库迁移指南](backend/MIGRATION_GUIDE.md) - [FastAPI 文档](https://fastapi.tiangolo.com/) - [Next.js 文档](https://nextjs.org/docs) - [SQLAlchemy ORM 指南](https://docs.sqlalchemy.org/) ## 🤝 贡献指南 1. **Fork 本仓库** 2. **创建功能分支**: `git checkout -b feature/your-feature` 3. **提交更改**: `git commit -am 'Add new feature'` 4. **推送到分支**: `git push origin feature/your-feature` 5. **提交 Pull Request** ### 代码风格 - **Backend**: 遵循 PEP 8,使用 black 格式化工具 - **Frontend**: 遵循 Next.js 约定,使用 ESLint ## 📄 许可证 本项目采用 MIT 许可证授权 - 详情请参见 LICENSE 文件。 ## 👥 作者 - Your Name / Development Team ## 🙋 支持 如有问题、疑问或建议: - 在 GitHub 上开启 Issue - 联系方式: your-email@example.com **版本**: 1.0.0 **最后更新**: 2026年3月
标签:AV绕过, DNS 反向解析, FastAPI, JWT认证, OpenAI, ORM, PostgreSQL, Pydantic, React, SQLAlchemy, Swagger, Syscalls, Tailwind CSS, TypeScript, Uvicorn, 事件报告, 事件验证, 人工智能, 全栈应用, 公共安全, 内存规避, 基于角色的访问控制, 多维度评分, 安全插件, 工作流自动化, 库, 应急响应, 异步处理, 智能分析, 测试用例, 用户模式Hook绕过, 管理仪表盘, 语音交互, 逆向工具