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

Update vton.py

Browse files
Files changed (1) hide show
  1. vton.py +12 -12
vton.py CHANGED
@@ -1,6 +1,7 @@
1
  import replicate
2
  import requests
3
  import os
 
4
 
5
  def virtual_try_on(garm_img_url, human_img_url, garment_des):
6
  """
@@ -14,15 +15,13 @@ def virtual_try_on(garm_img_url, human_img_url, garment_des):
14
  Returns:
15
  str: Path to the saved output image
16
  """
17
- # Convert local files to data URLs if needed
18
  def file_to_data_url(file_path):
19
- if file_path.startswith('http'):
20
- response = requests.get(file_path)
21
- img_data = response.content
22
- else:
23
- with open(file_path, 'rb') as f:
24
- img_data = f.read()
25
- import base64
26
  encoded = base64.b64encode(img_data).decode('utf-8')
27
  return f"data:image/png;base64,{encoded}"
28
 
@@ -56,10 +55,11 @@ def virtual_try_on(garm_img_url, human_img_url, garment_des):
56
 
57
  # Example usage
58
  if __name__ == "__main__":
59
- # Example inputs
60
- garm_img = "https://replicate.delivery/pbxt/KgwTlZyFx5aUU3gc5gMiKuD5nNPTgliMlLUWx160G4z99YjO/sweater.webp"
61
- human_img = "https://replicate.delivery/pbxt/KgwTlhCMvDagRrcVzZJbuozNJ8esPqiNAIJS3eMgHrYuHmW4/KakaoTalk_Photo_2024-04-04-21-44-45.png"
62
- garment_des = "cute pink top"
 
63
 
64
  # Check if REPLICATE_API_TOKEN is set
65
  if "REPLICATE_API_TOKEN" not in os.environ:
 
1
  import replicate
2
  import requests
3
  import os
4
+ import base64
5
 
6
  def virtual_try_on(garm_img_url, human_img_url, garment_des):
7
  """
 
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
 
 
55
 
56
  # Example usage
57
  if __name__ == "__main__":
58
+ print("Please use this module by importing it in your application.")
59
+ print("Example usage:")
60
+ print("from vton import virtual_try_on")
61
+ print("output_path = virtual_try_on(garment_image_path, person_image_path, garment_description)")
62
+ print("\nNote: Both garment_image_path and person_image_path should be paths to local image files.")
63
 
64
  # Check if REPLICATE_API_TOKEN is set
65
  if "REPLICATE_API_TOKEN" not in os.environ: