Spaces:
Sleeping
Sleeping
chips
commited on
Commit
·
3b76ad6
1
Parent(s):
9206058
added documentation and trying redis
Browse files- app.py +59 -9
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -7,23 +7,72 @@ import os
|
|
| 7 |
import base_generator
|
| 8 |
from openai import OpenAI
|
| 9 |
import base64
|
|
|
|
|
|
|
| 10 |
|
| 11 |
app = FastAPI()
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
@app.get("/")
|
| 16 |
def greet_json():
|
| 17 |
return {"Hello": "World!"}
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
#endpoints related to base image generation
|
| 22 |
|
| 23 |
-
@app.get("/makeBaseImage"
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
print("make base image")
|
| 26 |
-
result = base_generator.create_image(character_lora, character_keyword, outfit_desc, pose_id)
|
| 27 |
return(result)
|
| 28 |
|
| 29 |
# Function related to virtual outfit try on
|
|
@@ -40,7 +89,7 @@ def combine_garment_images(Upper_garment: UploadFile = File(...), Lower_garment:
|
|
| 40 |
# Endpoints related to virtual outfit try on
|
| 41 |
# HOW DO WE DICESERN FRONT VS BACK IMAGES OF GARMENTS?
|
| 42 |
|
| 43 |
-
@app.post("/styleTalent")
|
| 44 |
async def style_talent( talent_image: UploadFile = File(...), garment_image: UploadFile = File(...)):
|
| 45 |
#Save the uploaded talent image tempoarily
|
| 46 |
talent_image_bytes = await talent_image.read()
|
|
@@ -168,12 +217,13 @@ async def videoResult(request_id: str):
|
|
| 168 |
|
| 169 |
#Auxiliary functions
|
| 170 |
|
| 171 |
-
@app.post("/describeGarment"
|
|
|
|
| 172 |
async def describe_garment(image: UploadFile = File(...)):
|
| 173 |
image_bytes = await image.read()
|
| 174 |
base64_image = base64.b64encode(image_bytes).decode("utf-8")
|
| 175 |
|
| 176 |
-
response =
|
| 177 |
model="gpt-4o",
|
| 178 |
messages=[
|
| 179 |
{
|
|
|
|
| 7 |
import base_generator
|
| 8 |
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"))
|
| 15 |
+
|
| 16 |
+
#This is a temp redis instance, replace with one on aws when going into production!
|
| 17 |
+
r = redis.Redis(
|
| 18 |
+
host='cute-wildcat-41430.upstash.io',
|
| 19 |
+
port=6379,
|
| 20 |
+
password='AaHWAAIjcDFhZDVlOGUyMDQ0ZGQ0MTZmODA4ZjdkNzc4ZDVhZjUzZHAxMA',
|
| 21 |
+
ssl=True
|
| 22 |
+
)
|
| 23 |
@app.get("/")
|
| 24 |
def greet_json():
|
| 25 |
return {"Hello": "World!"}
|
| 26 |
|
| 27 |
+
@app.post("/virtualTryOn", summary="Virtual try on single call",
|
| 28 |
+
description="Virtual try on single call for complete outfit try on")
|
| 29 |
+
async def virtual_try_on(top_garment_image: UploadFile = File(...),
|
| 30 |
+
bottom_garment_image: UploadFile = File(...),
|
| 31 |
+
top_back_garment_image: UploadFile = File(...),
|
| 32 |
+
bottom_back_garment_image: UploadFile = File(...),
|
| 33 |
+
talent_trigger_word: str,
|
| 34 |
+
talent_lora_url: str,
|
| 35 |
+
num_images: int = 4):
|
| 36 |
+
"""
|
| 37 |
+
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.
|
| 38 |
+
Only one front garment image is required, the rest are optional.
|
| 39 |
+
Default number of images is 4.
|
| 40 |
+
"""
|
| 41 |
+
|
| 42 |
+
request_id = str(uuid.uuid4())
|
| 43 |
+
r.set(request_id, "pending")
|
| 44 |
+
# step 1, make the base image
|
| 45 |
+
r.set(request_id, "Creating Base Images")
|
| 46 |
+
# step 2, combine the garment images
|
| 47 |
+
r.set(request_id, "Combining Garment Images")
|
| 48 |
+
# step 3, style the talent
|
| 49 |
+
r.set(request_id, "Styling Talent")
|
| 50 |
+
# step 4, create variations
|
| 51 |
+
r.set(request_id, "Creating Variations")
|
| 52 |
+
#step 5. Upscale the images
|
| 53 |
+
r.set(request_id, "Upscaling Images")
|
| 54 |
+
# step 6, return the result
|
| 55 |
+
r.set(request_id, "Completed")
|
| 56 |
+
return(request_id)
|
| 57 |
|
| 58 |
+
@app.get("/status/{request_id}")
|
| 59 |
+
async def check_status(request_id: str):
|
| 60 |
+
status = r.get(request_id)
|
| 61 |
+
if not status:
|
| 62 |
+
return {"error": "Invalid request_id"}
|
| 63 |
+
return {"request_id": request_id, "status": status}
|
| 64 |
|
| 65 |
#endpoints related to base image generation
|
| 66 |
|
| 67 |
+
@app.get("/makeBaseImage", summary="Make a base image of the character,before adding the outfit",
|
| 68 |
+
description="Make one or more base image(s) of the character,before adding the outfit. supports multiple poses by passing in a list of pose ids")
|
| 69 |
+
async def make_base_image(character_lora: str, character_keyword: str, outfit_desc: str, pose_id: int , num_outputs: int = 1):
|
| 70 |
+
"""
|
| 71 |
+
Pass in the character lora, character keyword, outfit description and pose id to make a base image of the character,before adding the outfit.
|
| 72 |
+
supports multiple poses by passing a number of outputs.
|
| 73 |
+
"""
|
| 74 |
print("make base image")
|
| 75 |
+
result = base_generator.create_image(character_lora, character_keyword, outfit_desc, pose_id, num_outputs )
|
| 76 |
return(result)
|
| 77 |
|
| 78 |
# Function related to virtual outfit try on
|
|
|
|
| 89 |
# Endpoints related to virtual outfit try on
|
| 90 |
# HOW DO WE DICESERN FRONT VS BACK IMAGES OF GARMENTS?
|
| 91 |
|
| 92 |
+
@app.post("/styleTalent", summary="Style talent", description="Style talent")
|
| 93 |
async def style_talent( talent_image: UploadFile = File(...), garment_image: UploadFile = File(...)):
|
| 94 |
#Save the uploaded talent image tempoarily
|
| 95 |
talent_image_bytes = await talent_image.read()
|
|
|
|
| 217 |
|
| 218 |
#Auxiliary functions
|
| 219 |
|
| 220 |
+
@app.post("/describeGarment", summary="Describe a garment or garments in the image",
|
| 221 |
+
description="Passes the garment image to openai to describe it to improve generation of base images")
|
| 222 |
async def describe_garment(image: UploadFile = File(...)):
|
| 223 |
image_bytes = await image.read()
|
| 224 |
base64_image = base64.b64encode(image_bytes).decode("utf-8")
|
| 225 |
|
| 226 |
+
response = openai_client.chat.completions.create(
|
| 227 |
model="gpt-4o",
|
| 228 |
messages=[
|
| 229 |
{
|
requirements.txt
CHANGED
|
@@ -5,3 +5,4 @@ python-multipart
|
|
| 5 |
fal-client
|
| 6 |
requests
|
| 7 |
openai
|
|
|
|
|
|
| 5 |
fal-client
|
| 6 |
requests
|
| 7 |
openai
|
| 8 |
+
redis
|