Spaces:
Sleeping
Sleeping
chips
commited on
Commit
·
e571768
1
Parent(s):
2bc1f58
Made process work in background for better interaction
Browse files
app.py
CHANGED
|
@@ -9,6 +9,7 @@ from openai import OpenAI
|
|
| 9 |
import base64
|
| 10 |
import redis
|
| 11 |
import uuid
|
|
|
|
| 12 |
|
| 13 |
app = FastAPI()
|
| 14 |
openai_client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
|
@@ -42,24 +43,18 @@ async def virtual_try_on(talent_trigger_word: str = Form(...),
|
|
| 42 |
|
| 43 |
request_id = str(uuid.uuid4())
|
| 44 |
r.set(request_id, "pending")
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
sleep(5)
|
| 58 |
-
#step 5. Upscale the images
|
| 59 |
-
r.set(request_id, "Upscaling Images")
|
| 60 |
-
sleep(5)
|
| 61 |
-
# step 6, return the result
|
| 62 |
-
r.set(request_id, "Completed")
|
| 63 |
return(request_id)
|
| 64 |
|
| 65 |
@app.get("/status/{request_id}")
|
|
@@ -84,6 +79,52 @@ async def make_base_image(character_lora: str, character_keyword: str, outfit_de
|
|
| 84 |
|
| 85 |
# Function related to virtual outfit try on
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
#figure out how to deal with front vs back images of garments
|
| 88 |
|
| 89 |
|
|
|
|
| 9 |
import base64
|
| 10 |
import redis
|
| 11 |
import uuid
|
| 12 |
+
from time import sleep
|
| 13 |
|
| 14 |
app = FastAPI()
|
| 15 |
openai_client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
|
|
|
| 43 |
|
| 44 |
request_id = str(uuid.uuid4())
|
| 45 |
r.set(request_id, "pending")
|
| 46 |
+
# Launch background task
|
| 47 |
+
background_tasks.add_task(
|
| 48 |
+
run_virtual_tryon_pipeline,
|
| 49 |
+
request_id,
|
| 50 |
+
top_garment_image,
|
| 51 |
+
bottom_garment_image,
|
| 52 |
+
top_back_garment_image,
|
| 53 |
+
bottom_back_garment_image,
|
| 54 |
+
talent_trigger_word,
|
| 55 |
+
talent_lora_url,
|
| 56 |
+
num_images
|
| 57 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
return(request_id)
|
| 59 |
|
| 60 |
@app.get("/status/{request_id}")
|
|
|
|
| 79 |
|
| 80 |
# Function related to virtual outfit try on
|
| 81 |
|
| 82 |
+
async def run_virtual_tryon_pipeline(
|
| 83 |
+
request_id,
|
| 84 |
+
top,
|
| 85 |
+
bottom,
|
| 86 |
+
top_back,
|
| 87 |
+
bottom_back,
|
| 88 |
+
trigger,
|
| 89 |
+
lora_url,
|
| 90 |
+
num_images
|
| 91 |
+
):
|
| 92 |
+
try:
|
| 93 |
+
r.set(request_id, "Creating base image")
|
| 94 |
+
sleep(5)
|
| 95 |
+
# STEP 1: make base image
|
| 96 |
+
# ... your logic here
|
| 97 |
+
|
| 98 |
+
r.set(request_id, "Combining garment images")
|
| 99 |
+
sleep(5)
|
| 100 |
+
|
| 101 |
+
# STEP 2: combine garments
|
| 102 |
+
# ...
|
| 103 |
+
|
| 104 |
+
r.set(request_id, "Styling talent")
|
| 105 |
+
sleep(5)
|
| 106 |
+
# STEP 3: style the talent
|
| 107 |
+
# ...
|
| 108 |
+
|
| 109 |
+
r.set(request_id, "Creating variations")
|
| 110 |
+
sleep(5)
|
| 111 |
+
# STEP 4: generate variations
|
| 112 |
+
# ...
|
| 113 |
+
|
| 114 |
+
r.set(request_id, "Upscaling images")
|
| 115 |
+
sleep(5)
|
| 116 |
+
# STEP 5: upscale
|
| 117 |
+
# ...
|
| 118 |
+
|
| 119 |
+
# STEP 6: Final result
|
| 120 |
+
final_result = {"images": ["url1", "url2"], "notes": "done"}
|
| 121 |
+
r.set(f"{request_id}_result", json.dumps(final_result))
|
| 122 |
+
r.set(request_id, "completed")
|
| 123 |
+
except Exception as e:
|
| 124 |
+
r.set(request_id, "error")
|
| 125 |
+
r.set(f"{request_id}_error", str(e))
|
| 126 |
+
|
| 127 |
+
|
| 128 |
#figure out how to deal with front vs back images of garments
|
| 129 |
|
| 130 |
|