Spaces:
Sleeping
Sleeping
Add a Dockfile and Add Fast API function in app.py
Browse files- Dockerfile +30 -0
- app.py +82 -51
Dockerfile
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM pytorch/pytorch:2.0.1-cuda11.7-cudnn8-runtime
|
| 2 |
+
|
| 3 |
+
# Set working directory
|
| 4 |
+
WORKDIR /app
|
| 5 |
+
|
| 6 |
+
# Install system dependencies
|
| 7 |
+
RUN apt-get update && apt-get install -y \
|
| 8 |
+
git \
|
| 9 |
+
libgl1-mesa-glx \
|
| 10 |
+
libglib2.0-0 \
|
| 11 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
+
|
| 13 |
+
# Copy requirements file
|
| 14 |
+
COPY requirements.txt .
|
| 15 |
+
|
| 16 |
+
# Install Python dependencies
|
| 17 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 18 |
+
|
| 19 |
+
# Copy the application code
|
| 20 |
+
COPY . .
|
| 21 |
+
|
| 22 |
+
# Set environment variables
|
| 23 |
+
ENV PYTHONUNBUFFERED=1
|
| 24 |
+
ENV CUDA_VISIBLE_DEVICES=0
|
| 25 |
+
|
| 26 |
+
# Expose port (if your app needs it)
|
| 27 |
+
EXPOSE 7860
|
| 28 |
+
|
| 29 |
+
# Command to run the application
|
| 30 |
+
CMD ["python", "app.py"]
|
app.py
CHANGED
|
@@ -1,5 +1,10 @@
|
|
| 1 |
import spaces
|
| 2 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
from src.tryon_pipeline import StableDiffusionXLInpaintPipeline as TryonPipeline
|
| 5 |
from src.unet_hacked_garmnet import UNet2DConditionModel as UNet2DConditionModel_ref
|
|
@@ -269,57 +274,83 @@ for ex_human in human_list_path:
|
|
| 269 |
##default human
|
| 270 |
|
| 271 |
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
-
image_blocks.launch()
|
|
|
|
| 1 |
import spaces
|
| 2 |
+
from fastapi import FastAPI, File, UploadFile
|
| 3 |
+
import pickle
|
| 4 |
+
import uvicorn
|
| 5 |
+
import pandas as pd
|
| 6 |
+
import io
|
| 7 |
+
# import gradio as gr
|
| 8 |
from PIL import Image
|
| 9 |
from src.tryon_pipeline import StableDiffusionXLInpaintPipeline as TryonPipeline
|
| 10 |
from src.unet_hacked_garmnet import UNet2DConditionModel as UNet2DConditionModel_ref
|
|
|
|
| 274 |
##default human
|
| 275 |
|
| 276 |
|
| 277 |
+
# API base configuration
|
| 278 |
+
app = FastAPI()
|
| 279 |
+
|
| 280 |
+
@app.get("/")
|
| 281 |
+
def api_home():
|
| 282 |
+
return {"message": "Hello World"}
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
#AI λͺ¨λΈ μ€ν API, μ²λ¦¬μλ£λ μ΄λ―Έμ§λ₯Ό 리ν΄νλ€.
|
| 286 |
+
@app.post("/vton/")
|
| 287 |
+
async def vton_run(
|
| 288 |
+
upload_human: UploadFile = File(...),
|
| 289 |
+
upload_cloth: UploadFile = File(...),
|
| 290 |
+
input_prompt: str = None,
|
| 291 |
+
is_checked: bool = True,
|
| 292 |
+
is_checked_crop: bool = True,
|
| 293 |
+
denoise_steps: int = 30,
|
| 294 |
+
seed: int = 42
|
| 295 |
+
):
|
| 296 |
+
target_human = Image.open(io.BytesIO(await upload_human.read()))
|
| 297 |
+
target_cloth = Image.open(io.BytesIO(await upload_cloth.read()))
|
| 298 |
+
|
| 299 |
+
results = start_tryon(target_human, target_cloth, input_prompt, is_checked, is_checked_crop, denoise_steps, seed)
|
| 300 |
+
return results[0]
|
| 301 |
+
|
| 302 |
+
|
| 303 |
+
# image_blocks = gr.Blocks().queue()
|
| 304 |
+
# with image_blocks as demo:
|
| 305 |
+
# gr.Markdown("πππ GSR μμ±λ¨ πππ")
|
| 306 |
+
# gr.Markdown("μμ±ν AIλ₯Ό νμ©ν κ°μ μμ μ°©μ₯ Protype (Based on IDM-VTON)!!!")
|
| 307 |
+
# with gr.Row():
|
| 308 |
+
# with gr.Column():
|
| 309 |
+
# imgs = gr.ImageEditor(sources='upload', type="pil", label='Human. Mask with pen or use auto-masking', interactive=True)
|
| 310 |
+
# with gr.Row():
|
| 311 |
+
# is_checked = gr.Checkbox(label="'μμ' μλ λ§μ€νΉ", info="μ²΄ν¬ 'ν΄μ 'ν΄μΌ 'λ§μ€νΉ μλ₯ μ ν'μ΄ λ°μλ©λλ€.",value=True)
|
| 312 |
+
# # with gr.Row():
|
| 313 |
+
# # gr.Radio(["μμ μ€",], label="(μμ μ€)λ§μ€νΉ μλ₯ μ ν", info="μλμΌλ‘ λ§μ€νΉν μλ₯ μμΉλ₯Ό μ ννμΈμ")
|
| 314 |
+
# # is_category = gr.Radio(["upper_body", "lower_body", "dresses","layer"], label="λ§μ€νΉ μλ₯ μ ν", info="μλμΌλ‘ λ§μ€νΉν μλ₯ μμΉλ₯Ό μ ννμΈμ")
|
| 315 |
+
# with gr.Row():
|
| 316 |
+
# is_checked_crop = gr.Checkbox(label="Yes", info="Use auto-crop & resizing",value=False)
|
| 317 |
+
|
| 318 |
+
# example = gr.Examples(
|
| 319 |
+
# inputs=imgs,
|
| 320 |
+
# examples_per_page=10,
|
| 321 |
+
# examples=human_ex_list
|
| 322 |
+
# )
|
| 323 |
+
|
| 324 |
+
# with gr.Column():
|
| 325 |
+
# garm_img = gr.Image(label="Garment", sources='upload', type="pil")
|
| 326 |
+
# with gr.Row(elem_id="prompt-container"):
|
| 327 |
+
# with gr.Row():
|
| 328 |
+
# prompt = gr.Textbox(placeholder="Description of garment ex) Short Sleeve Round Neck T-shirts", show_label=False, elem_id="prompt")
|
| 329 |
+
# example = gr.Examples(
|
| 330 |
+
# inputs=garm_img,
|
| 331 |
+
# examples_per_page=8,
|
| 332 |
+
# examples=garm_list_path)
|
| 333 |
+
# with gr.Column():
|
| 334 |
+
# # image_out = gr.Image(label="Output", elem_id="output-img", height=400)
|
| 335 |
+
# masked_img = gr.Image(label="Masked image output", elem_id="masked-img",show_share_button=False)
|
| 336 |
+
# with gr.Column():
|
| 337 |
+
# # image_out = gr.Image(label="Output", elem_id="output-img", height=400)
|
| 338 |
+
# image_out = gr.Image(label="Output", elem_id="output-img",show_share_button=False)
|
| 339 |
+
|
| 340 |
+
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
# with gr.Column():
|
| 344 |
+
# try_button = gr.Button(value="Try-on")
|
| 345 |
+
# with gr.Accordion(label="Advanced Settings", open=False):
|
| 346 |
+
# with gr.Row():
|
| 347 |
+
# denoise_steps = gr.Number(label="Denoising Steps", minimum=20, maximum=40, value=30, step=1)
|
| 348 |
+
# seed = gr.Number(label="Seed", minimum=-1, maximum=2147483647, step=1, value=42)
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
# try_button.click(fn=start_tryon, inputs=[imgs, garm_img, prompt, is_checked,is_checked_crop, denoise_steps, seed], outputs=[image_out,masked_img], api_name='tryon')
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
+
# image_blocks.launch()
|