ishworrsubedii commited on
Commit
5e92108
·
1 Parent(s): b8f6290

add: minor fixes nto

Browse files
Files changed (2) hide show
  1. app.py +1 -1
  2. src/api/mannequin_to_model_api.py +15 -4
app.py CHANGED
@@ -29,4 +29,4 @@ app.add_middleware(
29
  allow_credentials=True,
30
  allow_methods=["*"],
31
  allow_headers=["*"],
32
- )
 
29
  allow_credentials=True,
30
  allow_methods=["*"],
31
  allow_headers=["*"],
32
+ )
src/api/mannequin_to_model_api.py CHANGED
@@ -6,6 +6,7 @@ author @ github.com/ishworrsubedii
6
  import base64
7
  import json
8
  import os
 
9
 
10
  import requests
11
  from fastapi.routing import APIRouter
@@ -34,7 +35,6 @@ def run_mto(input):
34
 
35
  def read_return(url):
36
  try:
37
- logger.info(f"Fetching image from URL: {url}")
38
  res = requests.get(url)
39
  logger.info("Image fetched successfully")
40
  return res.content
@@ -50,7 +50,9 @@ async def mto_image(image: UploadFile = File(...), store_name: str = Form(...),
50
  body_structure: str = Form(...),
51
  skin_complexion: str = Form(...),
52
  facial_structure: str = Form(...), ):
 
53
  try:
 
54
  logger.info(f"Starting MTO image process for store: {store_name}")
55
 
56
  if body_structure == "medium":
@@ -61,7 +63,7 @@ async def mto_image(image: UploadFile = File(...), store_name: str = Form(...),
61
  logger.info("Source image read successfully")
62
 
63
  mannequin_image_url = f"https://lvuhhlrkcuexzqtsbqyu.supabase.co/storage/v1/object/public/ClothingTryOn/{store_name}/{clothing_category}/{product_id}/{product_id}_{skin_complexion}_{facial_structure}_{body_structure}.webp"
64
- logger.info(f"Fetching mannequin image from: {mannequin_image_url}")
65
 
66
  reference_image_bytes = read_return(mannequin_image_url)
67
  if reference_image_bytes is None:
@@ -81,8 +83,17 @@ async def mto_image(image: UploadFile = File(...), store_name: str = Form(...),
81
  logger.error("Face swap process failed")
82
  return JSONResponse({"error": "Face swap process failed"}, status_code=500)
83
 
84
- logger.info("MTO image process completed successfully")
85
- return JSONResponse(content={"output": output}, status_code=200)
 
 
 
 
 
 
 
 
 
86
 
87
  except Exception as e:
88
  logger.error(f"Error in MTO image process: {str(e)}")
 
6
  import base64
7
  import json
8
  import os
9
+ import time
10
 
11
  import requests
12
  from fastapi.routing import APIRouter
 
35
 
36
  def read_return(url):
37
  try:
 
38
  res = requests.get(url)
39
  logger.info("Image fetched successfully")
40
  return res.content
 
50
  body_structure: str = Form(...),
51
  skin_complexion: str = Form(...),
52
  facial_structure: str = Form(...), ):
53
+ start_time = time.time()
54
  try:
55
+
56
  logger.info(f"Starting MTO image process for store: {store_name}")
57
 
58
  if body_structure == "medium":
 
63
  logger.info("Source image read successfully")
64
 
65
  mannequin_image_url = f"https://lvuhhlrkcuexzqtsbqyu.supabase.co/storage/v1/object/public/ClothingTryOn/{store_name}/{clothing_category}/{product_id}/{product_id}_{skin_complexion}_{facial_structure}_{body_structure}.webp"
66
+ logger.info(f"Fetching mannequin image")
67
 
68
  reference_image_bytes = read_return(mannequin_image_url)
69
  if reference_image_bytes is None:
 
83
  logger.error("Face swap process failed")
84
  return JSONResponse({"error": "Face swap process failed"}, status_code=500)
85
 
86
+ try:
87
+ logger.info("MTO image process completed successfully")
88
+ return JSONResponse(content={
89
+ "output": str(output['image']),
90
+ "status": "success",
91
+ "inferece_time": time.time() - start_time
92
+ }, status_code=200)
93
+
94
+ except Exception as e:
95
+ logger.error(f"Error converting output to base64: {str(e)}")
96
+ return JSONResponse({"error": "Error processing output image"}, status_code=500)
97
 
98
  except Exception as e:
99
  logger.error(f"Error in MTO image process: {str(e)}")