# magic_notebook **Repository Path**: j326598/magic_notebook ## Basic Information - **Project Name**: magic_notebook - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-07-07 - **Last Updated**: 2026-07-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 魔法笔记本 Magic Notebook 手写问题,魔法回答。一本来自霍格沃茨的 AI 魔法笔记本。 ## 演示 演示网址:https://quantdash.ccwu.cc/magic.html 目前ocr和ai的API额度快没了开源自行部署体验: 👉 [点击这里观看演示视频](https://www.image2url.com/r2/default/videos/1783437106982-77e0ac0c-5734-40c1-ae9c-65b3dc1a01bd.mp4) 在屏幕上手写问题,停笔后字迹如魔法般消散,AI 大模型以神秘的口吻给出答案。 - 手写输入 / 手指书写 - OCR 识别手写文字 - DeepSeek AI 流式回答(打字机效果) - 历史记录持久化存储 - 逆时针画圈清除答案,进入下一题 ## 技术栈 | 层级 | 技术 | |------|------| | 前端 | HTML5 Canvas + 原生 JavaScript | | OCR | 百度 OCR 手写识别 API | | AI | DeepSeek-R1-0528-Qwen3-8B(流式输出) | | 后端 | Python 3 `http.server` | ## 快速开始 ### 环境要求 - Python 3.6+ - 百度 OCR API 密钥 - DeepSeek API 密钥(或其他兼容 OpenAI 接口的服务) ### 1. 克隆仓库 ```bash git clone https://gitee.com/yourname/magic-notebook.git cd magic-notebook ``` ### 2. 配置 API 密钥 编辑 `server.py`,替换其中的 API 密钥: ```python DEEPSEEK_API_KEY = '你的DeepSeek密钥' BAIDU_API_KEY = '你的百度OCR API Key' BAIDU_SECRET_KEY = '你的百度OCR Secret Key' ``` > 如需使用其他 LLM 服务,修改 `server.py` 中 `handle_deepseek` 方法里的请求地址即可。 ### 3. 启动服务 ```bash python3 server.py ``` 服务默认运行在 `http://0.0.0.0:8080`。 ### 4. 打开页面 用浏览器(推荐 iPad / 平板)访问: ``` http://localhost:8080 ``` 历史记录页面: ``` http://localhost:8080/history ``` ## 项目结构 ``` magic-notebook/ ├── magic.html # 前端页面(Canvas 手写 + 交互逻辑) ├── server.py # Python 后端(API 代理 + 历史记录) ├── font.woff2 # LXGW WenKai 字体文件 ├── history.json # 历史记录存储(自动生成) └── README.md ``` ## 后台部署 ### nohup 方式 ```bash nohup python3 server.py > server.log 2>&1 & ``` 停止服务: ```bash kill $(lsof -t -i:8080) ``` ### Nginx 反向代理(推荐生产环境) ```nginx location / { proxy_pass http://127.0.0.1:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_http_version 1.1; proxy_set_header Connection ""; proxy_buffering off; proxy_cache off; proxy_read_timeout 300s; proxy_send_timeout 300s; } ``` > `proxy_buffering off` 和 `proxy_http_version 1.1` 对流式输出至关重要。 ## 交互流程 1. 在屏幕上手写问题 2. 停笔约 1.8 秒后,字迹慢慢消散 3. OCR 识别手写文字 4. AI 以魔法口吻流式输出答案 5. 逆时针画圈可清除答案,写下一个问题 按键盘 `C` 键可手动清屏。 ## 自定义 ### 修改 AI 回答风格 编辑 `magic.html` 中 `callDeepSeek` 函数里的 `system` prompt: ```javascript { role: 'system', content: '你是一本来自霍格沃茨的魔法笔记本...' } ``` ### 修改停笔等待时间 编辑 `magic.html` 中的 `IDLE_DELAY` 变量(单位:毫秒): ```javascript const IDLE_DELAY = 1800; // 默认 1.8 秒 ``` ### 修改历史记录上限 编辑 `server.py` 中的条件: ```python if len(_history) > 50: # 默认保留 50 条 ``` ## 安全提醒 - 部署前务必替换 `server.py` 中的 API 密钥 - 建议将密钥改为环境变量读取,避免硬编码 - 不要将含密钥的代码提交到公开仓库 ## 许可证 MIT License ## 作者 [@都是斯文人](https://xhslink.com/m/5yUbHrtz1jX)