feat(rmbg): 将file接口改为流式返回,统一接口风格
- 将file上传接口从一次性返回改为流式返回 - 使用StreamingResponse和NDJSON格式,与batch接口保持一致 - 提升用户体验,减少响应等待时间 - 统一两种接口的返回格式
This commit is contained in:
parent
173f788ab7
commit
b3818a9ab1
@ -38,15 +38,22 @@ async def remove_background_batch(data: dict, request: Request):
|
||||
@jingrow_api_verify_and_billing(api_name=settings.api_name)
|
||||
async def remove_background_file(file: UploadFile = File(...), request: Request = None):
|
||||
"""
|
||||
从上传的文件移除背景
|
||||
从上传的文件移除背景(流式返回)
|
||||
|
||||
Args:
|
||||
file: 上传的图片文件
|
||||
request: FastAPI 请求对象
|
||||
|
||||
Returns:
|
||||
处理后的图片内容
|
||||
流式响应,包含处理后的图片内容
|
||||
"""
|
||||
content = await file.read()
|
||||
result = await service.remove_background_from_file(content)
|
||||
return result
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user