Spaces:
Sleeping
Sleeping
Add a Dockfile and Add Fast API function in app.py
Browse filesFiles changed (2)
- DockerfileAdded+30
- app.py+82-51
123456789101112131415161718192021222324252627282930FROM pytorch/pytorch:2.0.1-cuda11.7-cudnn8-runtime
# Set working directoryWORKDIR /app
# Install system dependenciesRUN apt-get update && apt-get install -y \ git \ libgl1-mesa-glx \ libglib2.0-0 \ && rm -rf /var/lib/apt/lists/*
# Copy requirements fileCOPY requirements.txt .
# Install Python dependenciesRUN pip install --no-cache-dir -r requirements.txt
# Copy the application codeCOPY . .
# Set environment variablesENV PYTHONUNBUFFERED=1ENV CUDA_VISIBLE_DEVICES=0
# Expose port (if your app needs it)EXPOSE 7860
# Command to run the applicationCMD ["python", "app.py"] 12345263 unmodified lines269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325import spacesimport gradio as grfrom PIL import Imagefrom src.tryon_pipeline import StableDiffusionXLInpaintPipeline as TryonPipelinefrom src.unet_hacked_garmnet import UNet2DConditionModel as UNet2DConditionModel_ref263 unmodified lines##default humanimage_blocks = gr.Blocks().queue()with image_blocks as demo:gr.Markdown("πππ GSR μμ±λ¨ πππ")gr.Markdown("μμ±ν AIλ₯Ό νμ©ν κ°μ μμ μ°©μ₯ Protype (Based on IDM-VTON)!!!")with gr.Row():with gr.Column():imgs = gr.ImageEditor(sources='upload', type="pil", label='Human. Mask with pen or use auto-masking', interactive=True)with gr.Row():is_checked = gr.Checkbox(label="'μμ' μλ λ§μ€νΉ", info="μ²΄ν¬ 'ν΄μ 'ν΄μΌ 'λ§μ€νΉ μλ₯ μ ν'μ΄ λ°μλ©λλ€.",value=True)# with gr.Row():# gr.Radio(["μμ μ€",], label="(μμ μ€)λ§μ€νΉ μλ₯ μ ν", info="μλμΌλ‘ λ§μ€νΉν μλ₯ μμΉλ₯Ό μ ννμΈμ")# is_category = gr.Radio(["upper_body", "lower_body", "dresses","layer"], label="λ§μ€νΉ μλ₯ μ ν", info="μλμΌλ‘ λ§μ€νΉν μλ₯ μμΉλ₯Ό μ ννμΈμ")with gr.Row():is_checked_crop = gr.Checkbox(label="Yes", info="Use auto-crop & resizing",value=False)example = gr.Examples(inputs=imgs,examples_per_page=10,examples=human_ex_list)with gr.Column():garm_img = gr.Image(label="Garment", sources='upload', type="pil")with gr.Row(elem_id="prompt-container"):with gr.Row():prompt = gr.Textbox(placeholder="Description of garment ex) Short Sleeve Round Neck T-shirts", show_label=False, elem_id="prompt")example = gr.Examples(inputs=garm_img,examples_per_page=8,examples=garm_list_path)with gr.Column():# image_out = gr.Image(label="Output", elem_id="output-img", height=400)masked_img = gr.Image(label="Masked image output", elem_id="masked-img",show_share_button=False)with gr.Column():# image_out = gr.Image(label="Output", elem_id="output-img", height=400)image_out = gr.Image(label="Output", elem_id="output-img",show_share_button=False)with gr.Column():try_button = gr.Button(value="Try-on")with gr.Accordion(label="Advanced Settings", open=False):with gr.Row():denoise_steps = gr.Number(label="Denoising Steps", minimum=20, maximum=40, value=30, step=1)seed = gr.Number(label="Seed", minimum=-1, maximum=2147483647, step=1, value=42)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')image_blocks.launch()12345678910263 unmodified lines274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356import spacesfrom fastapi import FastAPI, File, UploadFileimport pickleimport uvicornimport pandas as pdimport io# import gradio as grfrom PIL import Imagefrom src.tryon_pipeline import StableDiffusionXLInpaintPipeline as TryonPipelinefrom src.unet_hacked_garmnet import UNet2DConditionModel as UNet2DConditionModel_ref263 unmodified lines##default human# API base configurationapp = FastAPI()@app.get("/")def api_home():return {"message": "Hello World"}#AI λͺ¨λΈ μ€ν API, μ²λ¦¬μλ£λ μ΄λ―Έμ§λ₯Ό 리ν΄νλ€.@app.post("/vton/")async def vton_run(upload_human: UploadFile = File(...),upload_cloth: UploadFile = File(...),input_prompt: str = None,is_checked: bool = True,is_checked_crop: bool = True,denoise_steps: int = 30,seed: int = 42):target_human = Image.open(io.BytesIO(await upload_human.read()))target_cloth = Image.open(io.BytesIO(await upload_cloth.read()))results = start_tryon(target_human, target_cloth, input_prompt, is_checked, is_checked_crop, denoise_steps, seed)return results[0]# image_blocks = gr.Blocks().queue()# with image_blocks as demo:# gr.Markdown("πππ GSR μμ±λ¨ πππ")# gr.Markdown("μμ±ν AIλ₯Ό νμ©ν κ°μ μμ μ°©μ₯ Protype (Based on IDM-VTON)!!!")# with gr.Row():# with gr.Column():# imgs = gr.ImageEditor(sources='upload', type="pil", label='Human. Mask with pen or use auto-masking', interactive=True)# with gr.Row():# is_checked = gr.Checkbox(label="'μμ' μλ λ§μ€νΉ", info="μ²΄ν¬ 'ν΄μ 'ν΄μΌ 'λ§μ€νΉ μλ₯ μ ν'μ΄ λ°μλ©λλ€.",value=True)# # with gr.Row():# # gr.Radio(["μμ μ€",], label="(μμ μ€)λ§μ€νΉ μλ₯ μ ν", info="μλμΌλ‘ λ§μ€νΉν μλ₯ μμΉλ₯Ό μ ννμΈμ")# # is_category = gr.Radio(["upper_body", "lower_body", "dresses","layer"], label="λ§μ€νΉ μλ₯ μ ν", info="μλμΌλ‘ λ§μ€νΉν μλ₯ μμΉλ₯Ό μ ννμΈμ")# with gr.Row():# is_checked_crop = gr.Checkbox(label="Yes", info="Use auto-crop & resizing",value=False)# example = gr.Examples(# inputs=imgs,# examples_per_page=10,# examples=human_ex_list# )# with gr.Column():# garm_img = gr.Image(label="Garment", sources='upload', type="pil")# with gr.Row(elem_id="prompt-container"):# with gr.Row():# prompt = gr.Textbox(placeholder="Description of garment ex) Short Sleeve Round Neck T-shirts", show_label=False, elem_id="prompt")# example = gr.Examples(# inputs=garm_img,# examples_per_page=8,# examples=garm_list_path)# with gr.Column():# # image_out = gr.Image(label="Output", elem_id="output-img", height=400)# masked_img = gr.Image(label="Masked image output", elem_id="masked-img",show_share_button=False)# with gr.Column():# # image_out = gr.Image(label="Output", elem_id="output-img", height=400)# image_out = gr.Image(label="Output", elem_id="output-img",show_share_button=False)# with gr.Column():# try_button = gr.Button(value="Try-on")# with gr.Accordion(label="Advanced Settings", open=False):# with gr.Row():# denoise_steps = gr.Number(label="Denoising Steps", minimum=20, maximum=40, value=30, step=1)# seed = gr.Number(label="Seed", minimum=-1, maximum=2147483647, step=1, value=42)# 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')# image_blocks.launch()
DockerfileAdded+30
app.py+82-51