page_shot / test-hf-spaces.md
CatPtain's picture
Upload 13 files
e1fd143 verified

Hugging Face Spaces API 测试指南

测试 API 端点

1. 健康检查

curl https://yourusername-page-screenshot.hf.space/

预期响应:

{
  "message": "Page Screenshot API - Hugging Face Spaces",
  "version": "1.0.0",
  "status": "running",
  "platform": "HuggingFace Spaces"
}

2. 截图测试

curl -X POST https://yourusername-page-screenshot.hf.space/screenshot \
  -H "Content-Type: application/json" \
  -d '{"url": "https://google.com", "width": 1280, "height": 720}' \
  --output test-screenshot.jpg

3. 演示界面

访问:https://yourusername-page-screenshot.hf.space/demo

HF Spaces 特殊限制

  • 最大截图尺寸:2000x2000 像素
  • 超时时间:20秒
  • 请求频率:50次/15分钟
  • 内存限制:较严格,建议使用较小的截图尺寸

常见问题排查

1. 构建失败

  • 检查 Dockerfile.hf 语法
  • 确保所有依赖都在 package.json 中
  • 查看 HF Spaces 构建日志

2. 运行时错误

  • Chrome 启动失败:已配置使用系统 Chrome
  • 内存不足:降低截图尺寸
  • 超时:缩短等待时间

3. 演示界面无法访问

  • 确保访问 /demo 路径
  • 检查服务是否正常运行

性能优化建议

  1. 截图尺寸:推荐 1280x720 或更小
  2. 质量设置:推荐 70-80%
  3. 目标网站:避免访问过于复杂的页面
  4. 批量请求:避免同时发送多个请求