# -*- coding: utf-8 -*-
from fastapi import FastAPI, Form, HTTPException, Request,status,APIRouter,Query,Path,UploadFile,File
from tools.loglog import logger,log_err_e
from spoken_language.soeexample import spoken_result,make_spoken
from random import randint
from core.respone_format import *


router = APIRouter()


@router.post("/spoken_language")
async def post_article(request:Request,url=Form(""),file: UploadFile = File(None),text=Form(...)):

    if not url and not file:
        logger.error("错误:请上传mp3文件url参数或者二进制文件file参数")
        return resp_404(message="错误:请上传mp3文件url参数或者二进制文件file参数")
    try:
        task_id = randint(10000,99999)
       
        if file:
            file_content = await file.read()
        else:
            file_content = None
        data:dict = make_spoken(task_id,url,file_content,text)
        if data:
            logger.success(f"完成spoken_language请求:{data}")
           
            return data
    except Exception as e:
        log_err_e(e,msg="口语评测接口")
        return resp_500(message=f"{type(e).__name__},{e}")


