rmbg增加免费端点/file/free

This commit is contained in:
jingrow 2025-12-20 12:06:36 +00:00
parent 0cffb65490
commit 46c2265ab0
2 changed files with 23 additions and 0 deletions

View File

@ -57,3 +57,25 @@ async def remove_background_file(file: UploadFile = File(...), request: Request
process_and_stream(),
media_type="application/x-ndjson"
)
@router.post(settings.file_free_route)
async def remove_background_file_free(file: UploadFile = File(...)):
"""
免费版本从上传的文件移除背景流式返回
Args:
file: 上传的图片文件
Returns:
流式响应包含处理后的图片内容
"""
content = await file.read()
async def process_and_stream():
result = await service.remove_background_from_file(content)
yield json.dumps(result) + "\n"
return StreamingResponse(
process_and_stream(),
media_type="application/x-ndjson"
)

View File

@ -11,6 +11,7 @@ class Settings(BaseSettings):
# API路由配置
router_prefix: str = "/rmbg"
file_route: str = "/file"
file_free_route: str = "/file/free"
batch_route: str = "/batch"
api_name: str = "remove_background"