Spaces:
Sleeping
Sleeping
chips
commited on
Commit
·
e610a17
1
Parent(s):
6eba959
working on file input
Browse files- __pycache__/app.cpython-311.pyc +0 -0
- app.py +42 -35
__pycache__/app.cpython-311.pyc
CHANGED
Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ
|
|
app.py
CHANGED
@@ -12,6 +12,7 @@ import uuid
|
|
12 |
from time import sleep
|
13 |
import json
|
14 |
from functions import combine_images_side_by_side
|
|
|
15 |
|
16 |
from dotenv import load_dotenv
|
17 |
load_dotenv()
|
@@ -33,35 +34,43 @@ def greet_json():
|
|
33 |
|
34 |
@app.post("/virtualTryOn", summary="Virtual try on single call",
|
35 |
description="Virtual try on single call for complete outfit try on")
|
36 |
-
async def virtual_try_on(
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
44 |
"""
|
45 |
Pass in the top garment image, bottom garment image, top back garment image, bottom back garment image, talent trigger word, talent lora url and number of images to generate.
|
46 |
Only one front garment image is required, the rest are optional.
|
47 |
Default number of images is 4.
|
48 |
"""
|
49 |
-
|
50 |
request_id = str(uuid.uuid4())
|
51 |
r.set(request_id, "pending")
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
background_tasks.add_task(
|
54 |
run_virtual_tryon_pipeline,
|
55 |
request_id,
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
talent_trigger_word,
|
61 |
talent_lora_url,
|
62 |
num_images
|
63 |
)
|
64 |
-
return
|
65 |
|
66 |
@app.get("/status/{request_id}")
|
67 |
async def check_status(request_id: str):
|
@@ -95,10 +104,10 @@ async def safe_read_file(file: UploadFile):
|
|
95 |
|
96 |
async def run_virtual_tryon_pipeline(
|
97 |
request_id,
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
talent_trigger_word,
|
103 |
talent_lora_url,
|
104 |
num_images
|
@@ -107,23 +116,9 @@ async def run_virtual_tryon_pipeline(
|
|
107 |
r.set(request_id, "checking incoming data...")
|
108 |
front_type = ""
|
109 |
back_type = ""
|
110 |
-
|
111 |
-
#
|
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:
|
@@ -368,3 +363,15 @@ async def describe_garment(image: UploadFile = File(...)):
|
|
368 |
|
369 |
|
370 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
from time import sleep
|
13 |
import json
|
14 |
from functions import combine_images_side_by_side
|
15 |
+
from typing import Optional
|
16 |
|
17 |
from dotenv import load_dotenv
|
18 |
load_dotenv()
|
|
|
34 |
|
35 |
@app.post("/virtualTryOn", summary="Virtual try on single call",
|
36 |
description="Virtual try on single call for complete outfit try on")
|
37 |
+
async def virtual_try_on(
|
38 |
+
background_tasks: BackgroundTasks,
|
39 |
+
talent_trigger_word: str = Form(...),
|
40 |
+
talent_lora_url: str = Form(...),
|
41 |
+
num_images: int = 4,
|
42 |
+
top_garment_image: UploadFile = File(...),
|
43 |
+
bottom_garment_image: UploadFile = File( None),
|
44 |
+
top_back_garment_image: UploadFile = File(None),
|
45 |
+
bottom_back_garment_image: UploadFile = File(None)):
|
46 |
"""
|
47 |
Pass in the top garment image, bottom garment image, top back garment image, bottom back garment image, talent trigger word, talent lora url and number of images to generate.
|
48 |
Only one front garment image is required, the rest are optional.
|
49 |
Default number of images is 4.
|
50 |
"""
|
51 |
+
print(top_garment_image)
|
52 |
request_id = str(uuid.uuid4())
|
53 |
r.set(request_id, "pending")
|
54 |
+
|
55 |
+
# Read all files first
|
56 |
+
top_garment_data = await safe_read_file(top_garment_image)
|
57 |
+
bottom_garment_data = await safe_read_file(bottom_garment_image)
|
58 |
+
top_back_garment_data = await safe_read_file(top_back_garment_image)
|
59 |
+
bottom_back_garment_data = await safe_read_file(bottom_back_garment_image)
|
60 |
+
|
61 |
+
# Launch background task with the actual data
|
62 |
background_tasks.add_task(
|
63 |
run_virtual_tryon_pipeline,
|
64 |
request_id,
|
65 |
+
top_garment_data,
|
66 |
+
bottom_garment_data,
|
67 |
+
top_back_garment_data,
|
68 |
+
bottom_back_garment_data,
|
69 |
talent_trigger_word,
|
70 |
talent_lora_url,
|
71 |
num_images
|
72 |
)
|
73 |
+
return {"request_id": request_id}
|
74 |
|
75 |
@app.get("/status/{request_id}")
|
76 |
async def check_status(request_id: str):
|
|
|
104 |
|
105 |
async def run_virtual_tryon_pipeline(
|
106 |
request_id,
|
107 |
+
top_garment_data: bytes,
|
108 |
+
bottom_garment_data: bytes,
|
109 |
+
top_back_garment_data: bytes,
|
110 |
+
bottom_back_garment_data: bytes,
|
111 |
talent_trigger_word,
|
112 |
talent_lora_url,
|
113 |
num_images
|
|
|
116 |
r.set(request_id, "checking incoming data...")
|
117 |
front_type = ""
|
118 |
back_type = ""
|
119 |
+
|
120 |
+
# Now we can use the data directly
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
if top_garment_data is None and bottom_garment_data is None:
|
|
|
122 |
return {"error": "Missing garment images"}
|
123 |
|
124 |
if top_garment_data and bottom_garment_data:
|
|
|
363 |
|
364 |
|
365 |
|
366 |
+
@app.post("/upload")
|
367 |
+
async def upload_files(
|
368 |
+
name: str = Form(...),
|
369 |
+
image1: UploadFile = File(...),
|
370 |
+
image2: UploadFile = File(None) # Optional!
|
371 |
+
):
|
372 |
+
result = {
|
373 |
+
"name": name,
|
374 |
+
"image1_filename": image1.filename,
|
375 |
+
"image2_filename": image2.filename if image2 else "Not provided"
|
376 |
+
}
|
377 |
+
return result
|