CoolFace
Apppublic

lenML/ChatTTS-Forge

sourceHugging Faceagpl-3.0updated 2y agoView on Hugging Face
301likes
refiner_api.py59 linesDownload Raw Back to impl
1from fastapi import HTTPException2from pydantic import BaseModel3 4from modules import refiner5from modules.api import utils as api_utils6from modules.api.Api import APIManager7from modules.normalization import text_normalize8 9 10class RefineTextRequest(BaseModel):11    text: str12    prompt: str = "[oral_2][laugh_0][break_6]"13    seed: int = -114    top_P: float = 0.715    top_K: int = 2016    temperature: float = 0.717    repetition_penalty: float = 1.018    max_new_token: int = 38419    normalize: bool = True20 21 22async def refiner_prompt_post(request: RefineTextRequest):23    """24    This endpoint receives a prompt and returns the refined result25    """26 27    try:28        text = request.text29        if request.normalize:30            text = text_normalize(request.text)31        # TODO 其实这里可以做 spliter 和 batch 处理32        refined_text = refiner.refine_text(33            text=text,34            prompt=request.prompt,35            seed=request.seed,36            top_P=request.top_P,37            top_K=request.top_K,38            temperature=request.temperature,39            repetition_penalty=request.repetition_penalty,40            max_new_token=request.max_new_token,41        )42        return {"message": "ok", "data": refined_text}43 44    except Exception as e:45        import logging46 47        logging.exception(e)48 49        if isinstance(e, HTTPException):50            raise e51        else:52            raise HTTPException(status_code=500, detail=str(e))53 54 55def setup(api_manager: APIManager):56    api_manager.post("/v1/prompt/refine", response_model=api_utils.BaseResponse)(57        refiner_prompt_post58    )59