| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- from models import *
- import datetime
- from services.SegmentService import SegmentService
- from services.deal_cutout import DealCutout, DealCloths
- from services.other.module_online_data import GetOnlineData
- @app.get("/")
- async def index():
- """入口文件"""
- return {
- "message": "请求成功",
- "data": f"Hello, World!",
- }
- @app.post("/api/check_select_images", description="检查目录或文件,生成可执行的文件结构")
- async def checkSelect(params: CheckSelectImages):
- service = SegmentService()
- file_path = params.path
- path_type = params.path_type
- image_list = params.image_list
- if path_type == 0:
- need_cutout_images = service.initImages(image_list=image_list)
- else:
- need_cutout_images = service.check_need_cutout_images(file_path)
- if len([x for x in need_cutout_images if x["need_cutout"]]) == 0:
- raise UnicornException("您所选文件夹下没有jpg图片,或对应图片已扣图")
- return success(need_cutout_images)
- @app.post("/api/segment_images", description="执行抠图操作")
- async def segmentImages(params: SegmentImages):
- token = params.token
- if token is None:
- raise UnicornException("token不能为空")
- image_type = params.image_type
- segment_type = params.segment_type
- output_type = params.output_type
- need_cutout_images = params.need_cutout_images
- result = None
- try:
- if len([x for x in need_cutout_images if x["need_cutout"]]) == 0:
- raise UnicornException("您所选文件夹下没有jpg图片,或对应图片已扣图")
- except Exception as e:
- raise UnicornException(repr(e))
- if image_type == 1 and segment_type == 1:
- raise UnicornException("服装暂不支持精细化抠图")
- elif image_type == 1 and segment_type == 0:
- deal_cutout_cloth = DealCloths(token)
- # 服装抠图
- # need_cutout_images = service.check_need_cutout_images(file_path)
- deal_cutout_cloth.need_cutout_images = need_cutout_images
- deal_cutout_cloth.output_type = output_type
- result = deal_cutout_cloth.startDispose()
- elif image_type == 0 and segment_type == 1:
- deal_cutout_mode = DealCutout(token)
- # 通用-精细化抠图
- deal_cutout_mode.need_cutout_images = need_cutout_images
- deal_cutout_mode.output_type = output_type
- result = deal_cutout_mode.startDispose()
- elif image_type == 0 and segment_type == 0:
- # 通用-普通抠图
- deal_cutout_mode = DealCutout(token)
- deal_cutout_mode.output_type = output_type
- result = deal_cutout_mode.normalMode()
- return success({"result": result})
- @app.post("/api/request_hlm", description="请求查询可用余额")
- async def requestHlm(params: RequestHlm):
- token = params.token
- if token is None:
- raise UnicornException("token不能为空")
- onlineData = GetOnlineData(token=token)
- result = onlineData.get_cutout_image_times()
- if result == False:
- raise UnicornException("请求失败")
- return success({"result": result})
|