api.py 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. from models import *
  2. import datetime
  3. from services.SegmentService import SegmentService
  4. from services.deal_cutout import DealCutout
  5. @app.get("/")
  6. async def index():
  7. """入口文件"""
  8. return {
  9. "message": "请求成功",
  10. "data": f"Hello, World!",
  11. }
  12. @app.post("/api/check_select_images", description="检查目录或文件")
  13. async def checkSelect(params: CheckSelectImages):
  14. service = SegmentService()
  15. file_path = params.path
  16. path_type = params.path_type
  17. image_list = params.image_list
  18. deal_cutout_mode = DealCutout()
  19. if path_type == 0:
  20. need_cutout_images = service.initImages(image_list=image_list)
  21. else:
  22. need_cutout_images = service.check_need_cutout_images(file_path)
  23. if len([x for x in need_cutout_images if x["need_cutout"]]) == 0:
  24. raise UnicornException("您所选文件夹下没有jpg图片,或对应图片已扣图")
  25. deal_cutout_mode.need_cutout_images = need_cutout_images
  26. deal_cutout_mode.start()
  27. # print("list_result", need_cutout_images)
  28. return success(need_cutout_images)