rmbg增加免费端点/file/free
This commit is contained in:
parent
0cffb65490
commit
46c2265ab0
@ -57,3 +57,25 @@ async def remove_background_file(file: UploadFile = File(...), request: Request
|
|||||||
process_and_stream(),
|
process_and_stream(),
|
||||||
media_type="application/x-ndjson"
|
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"
|
||||||
|
)
|
||||||
|
|||||||
@ -11,6 +11,7 @@ class Settings(BaseSettings):
|
|||||||
# API路由配置
|
# API路由配置
|
||||||
router_prefix: str = "/rmbg"
|
router_prefix: str = "/rmbg"
|
||||||
file_route: str = "/file"
|
file_route: str = "/file"
|
||||||
|
file_free_route: str = "/file/free"
|
||||||
batch_route: str = "/batch"
|
batch_route: str = "/batch"
|
||||||
api_name: str = "remove_background"
|
api_name: str = "remove_background"
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user