noumanjavaid commited on
Commit
714eb56
·
verified ·
1 Parent(s): 6cd828a

Update vton.py

Browse files
Files changed (1) hide show
  1. vton.py +7 -12
vton.py CHANGED
@@ -3,32 +3,27 @@ import requests
3
  import os
4
  import base64
5
 
6
- def virtual_try_on(garm_img_url, human_img_url, garment_des):
7
  """
8
  Perform virtual try-on using the IDM-VTON model on Replicate.
9
 
10
  Args:
11
- garm_img_url (str): Path or URL of the garment image
12
- human_img_url (str): Path or URL of the human image
13
  garment_des (str): Description of the garment
14
 
15
  Returns:
16
  str: Path to the saved output image
17
  """
18
- # Convert local files to data URLs
19
- def file_to_data_url(file_path):
20
- if not os.path.exists(file_path):
21
- raise ValueError(f"File not found: {file_path}")
22
-
23
- with open(file_path, 'rb') as f:
24
- img_data = f.read()
25
  encoded = base64.b64encode(img_data).decode('utf-8')
26
  return f"data:image/png;base64,{encoded}"
27
 
28
  # Prepare input for the model
29
  input_data = {
30
- "garm_img": file_to_data_url(garm_img_url),
31
- "human_img": file_to_data_url(human_img_url),
32
  "garment_des": garment_des
33
  }
34
 
 
3
  import os
4
  import base64
5
 
6
+ def virtual_try_on(garm_img_data, human_img_data, garment_des):
7
  """
8
  Perform virtual try-on using the IDM-VTON model on Replicate.
9
 
10
  Args:
11
+ garm_img_data (bytes): Binary data of the garment image
12
+ human_img_data (bytes): Binary data of the human image
13
  garment_des (str): Description of the garment
14
 
15
  Returns:
16
  str: Path to the saved output image
17
  """
18
+ # Convert binary data to data URLs
19
+ def bytes_to_data_url(img_data):
 
 
 
 
 
20
  encoded = base64.b64encode(img_data).decode('utf-8')
21
  return f"data:image/png;base64,{encoded}"
22
 
23
  # Prepare input for the model
24
  input_data = {
25
+ "garm_img": bytes_to_data_url(garm_img_data),
26
+ "human_img": bytes_to_data_url(human_img_data),
27
  "garment_des": garment_des
28
  }
29