本地开发
设置 Potato 用于本地开发和测试。
本地开发
在本地机器上运行 Potato 进行开发和测试。
前提条件
- Python 3.7 或更高版本
- pip 包管理器
- Git(可选,用于克隆示例)
安装
使用 pip(推荐)
bash
pip install potato-annotation从源代码安装
bash
git clone https://github.com/davidjurgens/potato.git
cd potato
pip install -e .安装可选依赖
bash
# For audio annotation support
pip install potato-annotation[audio]
# For all optional features
pip install potato-annotation[all]快速开始
1. 创建配置文件
创建 config.yaml:
yaml
task_name: "My First Annotation Task"
server:
port: 8000
data_files:
- path: data.json
text_field: text
annotation_schemes:
- annotation_type: radio
name: sentiment
description: "What is the sentiment?"
labels:
- Positive
- Negative
- Neutral
output:
path: annotations/2. 准备示例数据
创建 data.json:
json
[
{"id": "1", "text": "I love this product!"},
{"id": "2", "text": "This is terrible."},
{"id": "3", "text": "It's okay, nothing special."}
]3. 启动服务器
bash
potato start config.yaml4. 访问界面
在浏览器中打开 http://localhost:8000
开发模式
热重载
启用配置变更时的自动重启:
bash
potato start config.yaml --reload调试模式
启用详细日志记录:
bash
potato start config.yaml --debug详细输出
查看所有服务器活动:
bash
potato start config.yaml --verbose目录结构
推荐的项目布局:
text
my-annotation-project/
├── config.yaml # Main configuration
├── data/
│ ├── train.json # Training data
│ └── main.json # Annotation data
├── annotations/ # Output directory
├── templates/ # Custom HTML templates
└── static/ # Custom CSS/JS
测试你的配置
验证配置
检查语法错误:
bash
potato validate config.yaml预览模式
启动但不保存标注:
bash
potato start config.yaml --preview使用测试数据
生成测试数据:
bash
potato generate-data --count 10 --output test_data.json常见问题
端口已被占用
bash
# Use a different port
potato start config.yaml --port 8080
# Or in config.yaml
server:
port: 8080数据文件未找到
确保路径相对于配置文件位置:
yaml
# If data is in subdirectory
data_files:
- path: data/main.json
# Or use absolute path
data_files:
- path: /full/path/to/data.json权限被拒绝
检查文件权限:
bash
chmod 755 annotations/
chmod 644 data/*.json本地多用户
用于测试多用户场景:
yaml
allow_all_users: true
url_user_id_param: user_id使用不同用户访问:
http://localhost:8000/?user_id=annotator1http://localhost:8000/?user_id=annotator2
重置标注
清除所有标注并重新开始:
bash
# Remove annotation files
rm -rf annotations/*
# Restart server
potato start config.yaml环境变量
通过环境配置:
bash
export POTATO_PORT=8000
export POTATO_DEBUG=true
export POTATO_DATA_PATH=/path/to/data
potato start config.yaml使用虚拟环境
venv
bash
python -m venv potato-env
source potato-env/bin/activate # Linux/Mac
potato-env\Scripts\activate # Windows
pip install potato-annotationConda
bash
conda create -n potato python=3.10
conda activate potato
pip install potato-annotationIDE 集成
VS Code
安装 YAML 扩展以支持配置文件:
json
// settings.json
{
"yaml.schemas": {
"https://potato-annotation.com/schema.json": "config.yaml"
}
}PyCharm
设置运行配置:
- 添加 → Python
- 脚本:
potato - 参数:
start config.yaml - 工作目录:你的项目路径