lyn10100/gector-api
0
GECToR Grammar Correction API
这是一个使用GECToR模型的语法校正API,部署在Hugging Face Spaces上。
API使用方法
校正文本
端点: /correct
方法: POST
请求格式:
{
"text": "Your text with grammatic errors."
}响应格式:
{
"original": "Your text with grammatic errors.",
"corrected": "Your text with grammatical errors.",
"corrections": [
{
"id": 1,
"type": "grammar",
"original": "grammatic",
"corrected": "grammatical",
"startIndex": 15,
"endIndex": 24,
"message": "Grammatical error"
}
]
}健康检查
端点: /
方法: GET
响应:
{
"status": "GECToR API is running"
}在前端中使用
const checkForCorrections = async (text) => {
try {
const response = await fetch('https://你的用户名-gector-grammar-correction-api.hf.space/correct', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ text }),
});
if (!response.ok) {
throw new Error(`API error: ${response.status}`);
}
const data = await response.json();
return data.corrections || [];
} catch (error) {
console.error('Error fetching corrections:', error);
return [];
}
};关于GECToR
GECToR是一个基于序列标注的语法错误校正模型,由Grammarly开发并开源。它使用BERT作为基础模型,通过标记预测来进行语法错误校正。
更多信息请参考GECToR GitHub 仓库。
