JustClothify / app.py
Brasd99's picture
Updated UI
8456408
raw
history blame
2.07 kB
import gradio as gr
import os
import wget
import subprocess
subprocess.call(['pip', 'install', 'git+https://github.com/facebookresearch/detectron2@main#subdirectory=projects/DensePose'])
from helpers.processor import TextureProcessor
def image_processing(person_img, model_img):
return texture_processor.extract(person_img, model_img)
def load_model(current_path):
data_path = os.path.join(current_path, 'data')
if not os.path.isdir(data_path):
os.mkdir(data_path)
loader_dict = {
'config.yaml': 'https://raw.githubusercontent.com/facebookresearch/detectron2/main/projects/DensePose/configs/densepose_rcnn_R_50_FPN_WC1M_s1x.yaml',
'weights.pkl': 'https://dl.fbaipublicfiles.com/densepose/densepose_rcnn_R_50_FPN_WC1M_s1x/217144516/model_final_48a9d9.pkl',
'Base-DensePose-RCNN-FPN.yaml': 'https://raw.githubusercontent.com/facebookresearch/detectron2/main/projects/DensePose/configs/Base-DensePose-RCNN-FPN.yaml'
}
for filename, url in loader_dict.items():
wget.download(url, os.path.join(data_path, filename))
current_path = os.getcwd()
load_model(current_path)
densepose_config = os.path.join(current_path, 'data', 'config.yaml')
densepose_weights = os.path.join(current_path, 'data', 'weights.pkl')
texture_processor = TextureProcessor(densepose_config, densepose_weights)
title = '<h1 style="text-align:center">JustClothify</h1>'
with gr.Blocks(theme='soft', title='AnswerMate') as blocks:
gr.HTML(title)
gr.Markdown('Upload an image of a person and an image of a model with clothes, the system will generate an image of a person wearing these clothes.')
with gr.Row():
person_image = gr.inputs.Image(label='Person Image', type='numpy')
model_image = gr.inputs.Image(label='Model Image (with clothes)', type='numpy')
process_button = gr.Button('Process')
outputs = gr.outputs.Image(label='Result Image', type='numpy')
process_button.click(fn=image_processing, inputs=[person_image, model_image], outputs=outputs)
blocks.launch()