'commit'
This commit is contained in:
70
dsLightRag/Routes/RecognizeEduQuestion.py
Normal file
70
dsLightRag/Routes/RecognizeEduQuestion.py
Normal file
@@ -0,0 +1,70 @@
|
||||
import logging
|
||||
|
||||
from fastapi import APIRouter, Request, HTTPException
|
||||
|
||||
from Util.FormulaRecognizer import FormulaRecognizer
|
||||
from Util.ShiTiRecognizer import ShiTiRecognizer
|
||||
|
||||
# 创建路由路由器
|
||||
router = APIRouter(prefix="/api", tags=["教育场景识别"])
|
||||
|
||||
# 配置日志
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@router.post("/recognize-formula")
|
||||
async def recognize_formula(request: Request):
|
||||
"""
|
||||
公式识别接口
|
||||
参数:
|
||||
image_url: 图片URL
|
||||
返回:
|
||||
JSON响应,包含公式识别结果
|
||||
"""
|
||||
try:
|
||||
# 获取请求参数
|
||||
data = await request.json()
|
||||
image_url = data.get("image_url")
|
||||
|
||||
# 验证参数
|
||||
if not image_url:
|
||||
raise HTTPException(status_code=400, detail="缺少必要参数: image_url")
|
||||
|
||||
# 调用公式识别器
|
||||
recognizer = FormulaRecognizer()
|
||||
result = recognizer.recognize_formula(image_url)
|
||||
|
||||
return result
|
||||
except HTTPException as e:
|
||||
raise e
|
||||
except Exception as e:
|
||||
logger.error(f"公式识别接口异常: {str(e)}")
|
||||
raise HTTPException(status_code=500, detail=f"服务器内部错误: {str(e)}")
|
||||
|
||||
@router.post("/recognize-question")
|
||||
async def recognize_question(request: Request):
|
||||
"""
|
||||
试题识别接口
|
||||
参数:
|
||||
image_url: 图片URL
|
||||
返回:
|
||||
JSON响应,包含试题识别结果
|
||||
"""
|
||||
try:
|
||||
# 获取请求参数
|
||||
data = await request.json()
|
||||
image_url = data.get("image_url")
|
||||
|
||||
# 验证参数
|
||||
if not image_url:
|
||||
raise HTTPException(status_code=400, detail="缺少必要参数: image_url")
|
||||
|
||||
# 调用试题识别器
|
||||
recognizer = ShiTiRecognizer()
|
||||
result = recognizer.recognize_question(image_url)
|
||||
|
||||
return result
|
||||
except HTTPException as e:
|
||||
raise e
|
||||
except Exception as e:
|
||||
logger.error(f"试题识别接口异常: {str(e)}")
|
||||
raise HTTPException(status_code=500, detail=f"服务器内部错误: {str(e)}")
|
Reference in New Issue
Block a user