Spaces:
Sleeping
Sleeping
chips
commited on
Commit
·
6eba959
1
Parent(s):
7fc69e4
changes in reading images
Browse files- .gitignore +1 -0
- __pycache__/app.cpython-311.pyc +0 -0
- __pycache__/base_generator.cpython-311.pyc +0 -0
- __pycache__/functions.cpython-311.pyc +0 -0
- app.py +26 -5
- functions.py +2 -1
- requirements.txt +2 -1
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
.env
|
__pycache__/app.cpython-311.pyc
ADDED
Binary file (16.6 kB). View file
|
|
__pycache__/base_generator.cpython-311.pyc
ADDED
Binary file (7.81 kB). View file
|
|
__pycache__/functions.cpython-311.pyc
ADDED
Binary file (2.45 kB). View file
|
|
app.py
CHANGED
@@ -13,6 +13,10 @@ from time import sleep
|
|
13 |
import json
|
14 |
from functions import combine_images_side_by_side
|
15 |
|
|
|
|
|
|
|
|
|
16 |
app = FastAPI()
|
17 |
openai_client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
18 |
|
@@ -80,6 +84,14 @@ async def make_base_image(character_lora: str, character_keyword: str, outfit_de
|
|
80 |
return(result)
|
81 |
|
82 |
# Function related to virtual outfit try on
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
async def run_virtual_tryon_pipeline(
|
85 |
request_id,
|
@@ -95,14 +107,23 @@ async def run_virtual_tryon_pipeline(
|
|
95 |
r.set(request_id, "checking incoming data...")
|
96 |
front_type = ""
|
97 |
back_type = ""
|
98 |
-
|
99 |
# Read all files once at the start
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
|
105 |
if top_garment_data is None and bottom_garment_data is None:
|
|
|
106 |
return {"error": "Missing garment images"}
|
107 |
|
108 |
if top_garment_data and bottom_garment_data:
|
|
|
13 |
import json
|
14 |
from functions import combine_images_side_by_side
|
15 |
|
16 |
+
from dotenv import load_dotenv
|
17 |
+
load_dotenv()
|
18 |
+
|
19 |
+
|
20 |
app = FastAPI()
|
21 |
openai_client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
22 |
|
|
|
84 |
return(result)
|
85 |
|
86 |
# Function related to virtual outfit try on
|
87 |
+
async def safe_read_file(file: UploadFile):
|
88 |
+
print("safe read file")
|
89 |
+
print(file)
|
90 |
+
if file is None:
|
91 |
+
return None
|
92 |
+
content = await file.read()
|
93 |
+
return content if content else None
|
94 |
+
|
95 |
|
96 |
async def run_virtual_tryon_pipeline(
|
97 |
request_id,
|
|
|
107 |
r.set(request_id, "checking incoming data...")
|
108 |
front_type = ""
|
109 |
back_type = ""
|
110 |
+
print("checking incoming data")
|
111 |
# Read all files once at the start
|
112 |
+
try:
|
113 |
+
print("reading top front")
|
114 |
+
top_garment_data = await safe_read_file(top_garment_image)
|
115 |
+
print("reading bottom front")
|
116 |
+
bottom_garment_data = await safe_read_file(bottom_garment_image)
|
117 |
+
print("reading top back")
|
118 |
+
top_back_garment_data = await safe_read_file(top_back_garment_image)
|
119 |
+
print("reading bottom back")
|
120 |
+
bottom_back_garment_data = await safe_read_file(bottom_back_garment_image)
|
121 |
+
except Exception as e:
|
122 |
+
print(f"Error reading garment images: {e}")
|
123 |
+
#return {"error": "Error reading garment images"}
|
124 |
|
125 |
if top_garment_data is None and bottom_garment_data is None:
|
126 |
+
print("Missing garment images from front")
|
127 |
return {"error": "Missing garment images"}
|
128 |
|
129 |
if top_garment_data and bottom_garment_data:
|
functions.py
CHANGED
@@ -16,6 +16,7 @@ async def combine_images_side_by_side(image1: bytes, image2: bytes) -> str:
|
|
16 |
Returns:
|
17 |
Base64 encoded string of the combined image
|
18 |
"""
|
|
|
19 |
# Create temp directory if it doesn't exist
|
20 |
os.makedirs('tmp', exist_ok=True)
|
21 |
|
@@ -46,7 +47,7 @@ async def combine_images_side_by_side(image1: bytes, image2: bytes) -> str:
|
|
46 |
|
47 |
# Clean up
|
48 |
os.remove(filename)
|
49 |
-
|
50 |
return encoded_string
|
51 |
|
52 |
# Example usage:
|
|
|
16 |
Returns:
|
17 |
Base64 encoded string of the combined image
|
18 |
"""
|
19 |
+
print("combine images side by side")
|
20 |
# Create temp directory if it doesn't exist
|
21 |
os.makedirs('tmp', exist_ok=True)
|
22 |
|
|
|
47 |
|
48 |
# Clean up
|
49 |
os.remove(filename)
|
50 |
+
print("combined images side by side")
|
51 |
return encoded_string
|
52 |
|
53 |
# Example usage:
|
requirements.txt
CHANGED
@@ -6,4 +6,5 @@ fal-client
|
|
6 |
requests
|
7 |
openai
|
8 |
redis
|
9 |
-
Pillow>=10.0.0
|
|
|
|
6 |
requests
|
7 |
openai
|
8 |
redis
|
9 |
+
Pillow>=10.0.0
|
10 |
+
python-dotenv
|