math-solver-api / README.md
zhman's picture
Upload 3 files
7a5eef0 verified

A newer version of the Gradio SDK is available: 6.5.1

Upgrade
metadata
title: Math Solver API
emoji: 🧮
colorFrom: purple
colorTo: blue
sdk: gradio
sdk_version: 4.44.0
app_file: app.py
pinned: false
license: apache-2.0

数学问题求解 API 后端

这是一个基于 Gradio 的 API 后端服务,用于为数学问题求解提供模型推理能力。

模型信息

  • 基础模型: meta-llama/Llama-3.2-1B-Instruct
  • 微调适配器: zhman/llama-SFT-GRPO
  • 训练方法: SFT + GRPO
  • 准确率: 97%

API 使用

端点

POST /api/predict

请求格式

{
  "data": [
    "你的数学问题",
    1024,
    0.7
  ]
}

响应格式

{
  "data": [
    "推理过程...",
    "提取的答案"
  ]
}

JavaScript 示例

const response = await fetch('https://YOUR_SPACE_URL/api/predict', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        data: [
            "Find the positive integer n such that 10^n cubic centimeters is the same as 1 cubic kilometer.",
            1024,
            0.7
        ]
    })
});

const result = await response.json();
console.log('推理过程:', result.data[0]);
console.log('答案:', result.data[1]);

部署说明

  1. 创建新的 Gradio Space
  2. 上传 app.pyrequirements.txt
  3. 等待模型加载(首次约1-2分钟)
  4. Space URL 即为 API 基础地址

注意事项

  • Space 长时间不使用会休眠
  • 休眠后首次调用会唤醒(约10-20秒)
  • 推荐使用 GPU 硬件加速