Spaces:
Running
Running
Update vton.py
Browse files
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
|
18 |
def file_to_data_url(file_path):
|
19 |
-
if
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
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 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
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:
|