nami0342 commited on
Commit
a07c712
Β·
1 Parent(s): 9961feb

Add a Dockfile and Add Fast API function in app.py

Browse files
Files changed (2) hide show
  1. Dockerfile +30 -0
  2. 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 gradio as gr
 
 
 
 
 
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
- image_blocks = gr.Blocks().queue()
273
- with image_blocks as demo:
274
- gr.Markdown("πŸ‘•πŸ‘”πŸ‘š GSR μž„μ„±λ‚¨ πŸ‘•πŸ‘”πŸ‘š")
275
- gr.Markdown("μƒμ„±ν˜• AIλ₯Ό ν™œμš©ν•œ 가상 μ˜μƒ μ°©μž₯ Protype (Based on IDM-VTON)!!!")
276
- with gr.Row():
277
- with gr.Column():
278
- imgs = gr.ImageEditor(sources='upload', type="pil", label='Human. Mask with pen or use auto-masking', interactive=True)
279
- with gr.Row():
280
- is_checked = gr.Checkbox(label="'μƒμ˜' μžλ™ λ§ˆμŠ€ν‚Ή", info="체크 'ν•΄μ œ'ν•΄μ•Ό 'λ§ˆμŠ€ν‚Ή 의λ₯˜ 선택'이 λ°˜μ˜λ©λ‹ˆλ‹€.",value=True)
281
- # with gr.Row():
282
- # gr.Radio(["μˆ˜μ •μ€‘",], label="(μˆ˜μ •μ€‘)λ§ˆμŠ€ν‚Ή 의λ₯˜ 선택", info="μžλ™μœΌλ‘œ λ§ˆμŠ€ν‚Ήν•  의λ₯˜ μœ„μΉ˜λ₯Ό μ„ νƒν•˜μ„Έμš”")
283
- # is_category = gr.Radio(["upper_body", "lower_body", "dresses","layer"], label="λ§ˆμŠ€ν‚Ή 의λ₯˜ 선택", info="μžλ™μœΌλ‘œ λ§ˆμŠ€ν‚Ήν•  의λ₯˜ μœ„μΉ˜λ₯Ό μ„ νƒν•˜μ„Έμš”")
284
- with gr.Row():
285
- is_checked_crop = gr.Checkbox(label="Yes", info="Use auto-crop & resizing",value=False)
286
-
287
- example = gr.Examples(
288
- inputs=imgs,
289
- examples_per_page=10,
290
- examples=human_ex_list
291
- )
292
-
293
- with gr.Column():
294
- garm_img = gr.Image(label="Garment", sources='upload', type="pil")
295
- with gr.Row(elem_id="prompt-container"):
296
- with gr.Row():
297
- prompt = gr.Textbox(placeholder="Description of garment ex) Short Sleeve Round Neck T-shirts", show_label=False, elem_id="prompt")
298
- example = gr.Examples(
299
- inputs=garm_img,
300
- examples_per_page=8,
301
- examples=garm_list_path)
302
- with gr.Column():
303
- # image_out = gr.Image(label="Output", elem_id="output-img", height=400)
304
- masked_img = gr.Image(label="Masked image output", elem_id="masked-img",show_share_button=False)
305
- with gr.Column():
306
- # image_out = gr.Image(label="Output", elem_id="output-img", height=400)
307
- image_out = gr.Image(label="Output", elem_id="output-img",show_share_button=False)
308
-
309
-
310
-
311
-
312
- with gr.Column():
313
- try_button = gr.Button(value="Try-on")
314
- with gr.Accordion(label="Advanced Settings", open=False):
315
- with gr.Row():
316
- denoise_steps = gr.Number(label="Denoising Steps", minimum=20, maximum=40, value=30, step=1)
317
- seed = gr.Number(label="Seed", minimum=-1, maximum=2147483647, step=1, value=42)
318
-
319
-
320
- 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')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()