jocoandonob commited on
Commit
856f007
·
1 Parent(s): 9b4578d
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -9,6 +9,7 @@ import numpy as np
9
  from PIL import Image
10
  from gradio_client import Client, handle_file
11
  import io
 
12
 
13
  app = FastAPI()
14
 
@@ -166,16 +167,21 @@ async def try_on_api(human_image: UploadFile = File(...), garment_image: UploadF
166
  # Process the images
167
  result = process_image(human_path, garment_path)
168
 
169
- # Convert result to bytes
170
  img_byte_arr = io.BytesIO()
171
  result.save(img_byte_arr, format='PNG')
172
  img_byte_arr = img_byte_arr.getvalue()
 
173
 
174
  # Clean up temporary files
175
  os.remove(human_path)
176
  os.remove(garment_path)
177
 
178
- return {"status": "success", "image": img_byte_arr}
 
 
 
 
179
  except Exception as e:
180
  return {"status": "error", "message": str(e)}
181
 
 
9
  from PIL import Image
10
  from gradio_client import Client, handle_file
11
  import io
12
+ import base64
13
 
14
  app = FastAPI()
15
 
 
167
  # Process the images
168
  result = process_image(human_path, garment_path)
169
 
170
+ # Convert result to base64
171
  img_byte_arr = io.BytesIO()
172
  result.save(img_byte_arr, format='PNG')
173
  img_byte_arr = img_byte_arr.getvalue()
174
+ base64_image = base64.b64encode(img_byte_arr).decode('utf-8')
175
 
176
  # Clean up temporary files
177
  os.remove(human_path)
178
  os.remove(garment_path)
179
 
180
+ return {
181
+ "status": "success",
182
+ "image": base64_image,
183
+ "format": "base64"
184
+ }
185
  except Exception as e:
186
  return {"status": "error", "message": str(e)}
187