diff --git a/README.md b/README.md index 154df8298fab5ecf322016157858e08cd1bccbe1..1f7a9fbb0490cf651e88188e3d110ca578020de5 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,13 @@ --- -license: apache-2.0 +title: OutfitAnyone +emoji: 🏢 +colorFrom: red +colorTo: pink +sdk: gradio +sdk_version: 4.8.0 +app_file: app.py +pinned: false +license: cc-by-nc-4.0 --- + +Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference diff --git a/app.py b/app.py new file mode 100644 index 0000000000000000000000000000000000000000..3448322c3e3afda2c8c58d90eb1c89a1ea77768f --- /dev/null +++ b/app.py @@ -0,0 +1,191 @@ +import os +import cv2 +import numpy as np +import json +import random +from PIL import Image, ImageDraw, ImageFont +import asyncio + +import requests +import base64 +import gradio as gr +# from IPython import embed + +machine_number = 0 +model = os.path.join(os.path.dirname(__file__), "models/eva/Eva_0.png") + +MODEL_MAP = { + "AI Model Rouyan_0": 'models/rouyan_new/Rouyan_0.png', + "AI Model Rouyan_1": 'models/rouyan_new/Rouyan_1.png', + "AI Model Rouyan_2": 'models/rouyan_new/Rouyan_2.png', + "AI Model Eva_0": 'models/eva/Eva_0.png', + "AI Model Eva_1": 'models/eva/Eva_1.png', + "AI Model Simon_0": 'models/simon_online/Simon_0.png', + "AI Model Simon_1": 'models/simon_online/Simon_1.png', + "AI Model Xuanxuan_0": 'models/xiaoxuan_online/Xuanxuan_0.png', + "AI Model Xuanxuan_1": 'models/xiaoxuan_online/Xuanxuan_1.png', + "AI Model Xuanxuan_2": 'models/xiaoxuan_online/Xuanxuan_2.png', + "AI Model Yaqi_0": 'models/yaqi/Yaqi_0.png', + "AI Model Yaqi_1": 'models/yaqi/Yaqi_1.png', + "AI Model Yaqi_2": 'models/yaqi/Yaqi_2.png', + "AI Model Yaqi_3": 'models/yaqi/Yaqi_3.png', + "AI Model Yifeng_0": 'models/yifeng_online/Yifeng_0.png', + "AI Model Yifeng_1": 'models/yifeng_online/Yifeng_1.png', + "AI Model Yifeng_2": 'models/yifeng_online/Yifeng_2.png', + "AI Model Yifeng_3": 'models/yifeng_online/Yifeng_3.png', +} + +def add_waterprint(img): + + h, w, _ = img.shape + img = cv2.putText(img, 'Powered by OutfitAnyone', (int(0.3*w), h-20), cv2.FONT_HERSHEY_PLAIN, 2, (128, 128, 128), 2, cv2.LINE_AA) + + return img + + +def get_tryon_result(model_name, garment1, garment2, seed=1234): + + # model_name = "AI Model " + model_name.split("\\")[-1].split(".")[0] # windows + model_name = "AI Model " + model_name.split("/")[-1].split(".")[0] # linux + print(model_name) + + encoded_garment1 = cv2.imencode('.jpg', garment1)[1].tobytes() + encoded_garment1 = base64.b64encode(encoded_garment1).decode('utf-8') + + if garment2 is not None: + encoded_garment2 = cv2.imencode('.jpg', garment2)[1].tobytes() + encoded_garment2 = base64.b64encode(encoded_garment2).decode('utf-8') + else: + encoded_garment2 = '' + + url = os.environ['OA_IP_ADDRESS'] + headers = {'Content-Type': 'application/json'} + seed = random.randint(0, 1222222222) + data = { + "garment1": encoded_garment1, + "garment2": encoded_garment2, + "model_name": model_name, + "seed": seed + } + response = requests.post(url, headers=headers, data=json.dumps(data)) + print("response code", response.status_code) + if response.status_code == 200: + result = response.json() + result = base64.b64decode(result['images'][0]) + result_np = np.frombuffer(result, np.uint8) + result_img = cv2.imdecode(result_np, cv2.IMREAD_UNCHANGED) + else: + print('server error!') + + + final_img = add_waterprint(result_img) + + return final_img + + + +with gr.Blocks(css = ".output-image, .input-image, .image-preview {height: 400px !important} ") as demo: + # gr.Markdown("# Outfit Anyone v0.9") + gr.HTML( + """ +
+ + +
+

Outfit Anyone: Ultra-high quality virtual try-on for Any Clothing and Any Person

+

v0.9

+
If you like our project, please give us a star on Github to stay updated with the latest developments.
+
+ Project Page + +
+
+
+ """) + with gr.Row(): + with gr.Column(): + init_image = gr.Image(sources='clipboard', type="filepath", label="model", value=model) + example = gr.Examples(inputs=init_image, + examples_per_page=4, + examples=[os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Rouyan_0')), + os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Rouyan_2')), + os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Eva_0')), + os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Simon_1')), + os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Eva_1')), + os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Simon_0')), + os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Xuanxuan_0')), + os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Xuanxuan_2')), + os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yaqi_1')), + os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yifeng_0')), + os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yifeng_3')), + os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Rouyan_1')), + os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yifeng_2')), + os.path.join(os.path.dirname(__file__), MODEL_MAP.get('AI Model Yaqi_0')), + ]) + with gr.Column(): + gr.HTML( + """ +
+
+

Models are fixed and cannot be uploaded or modified; we only support users uploading their own garments.

+

For a one-piece dress or coat, you only need to upload the image to the 'top garment' section and leave the 'lower garment' section empty.

+
+
+ """) + with gr.Row(): + garment_top = gr.Image(sources='upload', type="numpy", label="top garment") + example_top = gr.Examples(inputs=garment_top, + examples_per_page=5, + examples=[os.path.join(os.path.dirname(__file__), "garments/top222.JPG"), + os.path.join(os.path.dirname(__file__), "garments/top5.png"), + os.path.join(os.path.dirname(__file__), "garments/top333.png"), + os.path.join(os.path.dirname(__file__), "garments/dress1.png"), + os.path.join(os.path.dirname(__file__), "garments/dress2.png"), + ]) + garment_down = gr.Image(sources='upload', type="numpy", label="lower garment") + example_down = gr.Examples(inputs=garment_down, + examples_per_page=5, + examples=[os.path.join(os.path.dirname(__file__), "garments/bottom1.png"), + os.path.join(os.path.dirname(__file__), "garments/bottom2.PNG"), + os.path.join(os.path.dirname(__file__), "garments/bottom3.JPG"), + os.path.join(os.path.dirname(__file__), "garments/bottom4.PNG"), + os.path.join(os.path.dirname(__file__), "garments/bottom5.png"), + ]) + + run_button = gr.Button(value="Run") + with gr.Column(): + gallery = gr.Image() + + run_button.click(fn=get_tryon_result, + inputs=[ + init_image, + garment_top, + garment_down, + ], + outputs=[gallery], + concurrency_limit=2) + + + # Examples + gr.Markdown("## Examples") + with gr.Row(): + reference_image1 = gr.Image(label="model", scale=1, value="examples/basemodel.png") + reference_image2 = gr.Image(label="garment", scale=1, value="examples/garment1.jpg") + reference_image3 = gr.Image(label="result", scale=1, value="examples/result1.png") + gr.Examples( + examples=[ + ["examples/basemodel.png", "examples/garment1.png", "examples/result1.png"], + ["examples/basemodel.png", "examples/garment2.png", "examples/result2.png"], + ["examples/basemodel.png", "examples/garment3.png", "examples/result3.png"], + ], + inputs=[reference_image1, reference_image2, reference_image3], + label=None, + ) + +if __name__ == "__main__": + ip = requests.get('http://ifconfig.me/ip', timeout=1).text.strip() + print("ip address alibaba", ip) + demo.queue(max_size=10) + demo.launch() + diff --git a/examples/basemodel.png b/examples/basemodel.png new file mode 100644 index 0000000000000000000000000000000000000000..edc56f22be9999ecdc9995d6e3d37550bbc6ad76 Binary files /dev/null and b/examples/basemodel.png differ diff --git a/examples/garment1.jpg b/examples/garment1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..0f23f4f4b500802c791a88ba66ed430fa1482fb8 Binary files /dev/null and b/examples/garment1.jpg differ diff --git a/examples/garment1.png b/examples/garment1.png new file mode 100644 index 0000000000000000000000000000000000000000..9d1e6ba4d5a5c90063236c3f669c3a5a6a6d8168 Binary files /dev/null and b/examples/garment1.png differ diff --git a/examples/garment2.jpg b/examples/garment2.jpg new file mode 100644 index 0000000000000000000000000000000000000000..31b41a161f9ddf052f5ec288a9df563eb4818f0a Binary files /dev/null and b/examples/garment2.jpg differ diff --git a/examples/garment2.png b/examples/garment2.png new file mode 100644 index 0000000000000000000000000000000000000000..919d51031ae96a6b30c2ebb3e6301509fc99256b Binary files /dev/null and b/examples/garment2.png differ diff --git a/examples/garment3.png b/examples/garment3.png new file mode 100644 index 0000000000000000000000000000000000000000..f09a7ca18386e9cfcf9b3a3437624064e1e431ab Binary files /dev/null and b/examples/garment3.png differ diff --git a/examples/result1.png b/examples/result1.png new file mode 100644 index 0000000000000000000000000000000000000000..f073f254204da79176a9b751eb65f5e824cabb4d Binary files /dev/null and b/examples/result1.png differ diff --git a/examples/result2.png b/examples/result2.png new file mode 100644 index 0000000000000000000000000000000000000000..29438f50c84e9a5872ef64239bd37ed82142ef87 Binary files /dev/null and b/examples/result2.png differ diff --git a/examples/result3.png b/examples/result3.png new file mode 100644 index 0000000000000000000000000000000000000000..5f543ec45a2e250b2b3493a6b5eaf18cbc7a9cb4 Binary files /dev/null and b/examples/result3.png differ diff --git a/garments/bottom1.png b/garments/bottom1.png new file mode 100644 index 0000000000000000000000000000000000000000..53ed315502710e5f2252ce0cb2b8dbb09db046d4 Binary files /dev/null and b/garments/bottom1.png differ diff --git a/garments/bottom2.PNG b/garments/bottom2.PNG new file mode 100644 index 0000000000000000000000000000000000000000..fc56bc984a54a7ee528c49c7310563a941952367 Binary files /dev/null and b/garments/bottom2.PNG differ diff --git a/garments/bottom3.JPG b/garments/bottom3.JPG new file mode 100644 index 0000000000000000000000000000000000000000..eb5d96846735d549da3c1379e61095437a162613 Binary files /dev/null and b/garments/bottom3.JPG differ diff --git a/garments/bottom4.PNG b/garments/bottom4.PNG new file mode 100644 index 0000000000000000000000000000000000000000..c75e93cccf03377113aefa690d20c17f1b137438 Binary files /dev/null and b/garments/bottom4.PNG differ diff --git a/garments/bottom5.png b/garments/bottom5.png new file mode 100644 index 0000000000000000000000000000000000000000..0e30263d5a238d4f413cff4584a397c7f92db464 Binary files /dev/null and b/garments/bottom5.png differ diff --git a/garments/dress1.png b/garments/dress1.png new file mode 100644 index 0000000000000000000000000000000000000000..a1e6170075f2816fd047e150411450f6a4ec200d Binary files /dev/null and b/garments/dress1.png differ diff --git a/garments/dress2.png b/garments/dress2.png new file mode 100644 index 0000000000000000000000000000000000000000..64fdc508460f835fe6f16e2f06850641a333feca Binary files /dev/null and b/garments/dress2.png differ diff --git a/garments/top111.png b/garments/top111.png new file mode 100644 index 0000000000000000000000000000000000000000..82a4d272252857a3a8d9ce803e785db0844ac8df Binary files /dev/null and b/garments/top111.png differ diff --git a/garments/top222.JPG b/garments/top222.JPG new file mode 100644 index 0000000000000000000000000000000000000000..62f5daafcf14a73d0b75a0a694a0f72c6d83ddd5 Binary files /dev/null and b/garments/top222.JPG differ diff --git a/garments/top3.JPG b/garments/top3.JPG new file mode 100644 index 0000000000000000000000000000000000000000..e0bb63c4cd8e8394368fe652da997f083512fed1 Binary files /dev/null and b/garments/top3.JPG differ diff --git a/garments/top333.png b/garments/top333.png new file mode 100644 index 0000000000000000000000000000000000000000..b6a7e4dff5b96ad7fa300956d415b89dbe25ded3 Binary files /dev/null and b/garments/top333.png differ diff --git a/garments/top4.png b/garments/top4.png new file mode 100644 index 0000000000000000000000000000000000000000..e59993d2c0ba6a237852bf79905f9ba7706868cd Binary files /dev/null and b/garments/top4.png differ diff --git a/garments/top5.png b/garments/top5.png new file mode 100644 index 0000000000000000000000000000000000000000..bb70177453ac621d8431d67137c884dfec39425b Binary files /dev/null and b/garments/top5.png differ diff --git a/models/eva/Eva_0.png b/models/eva/Eva_0.png new file mode 100644 index 0000000000000000000000000000000000000000..8cc93d7384b2fba25d3677d34cd6b4acc0712f89 Binary files /dev/null and b/models/eva/Eva_0.png differ diff --git a/models/eva/Eva_1.png b/models/eva/Eva_1.png new file mode 100644 index 0000000000000000000000000000000000000000..0c235d0ff07a314d705bf91f2a7859b562b464ab Binary files /dev/null and b/models/eva/Eva_1.png differ diff --git a/models/rouyan_new/0/densepose.png b/models/rouyan_new/0/densepose.png new file mode 100644 index 0000000000000000000000000000000000000000..00843077a5005f09a8679fa58a8eac29599a60ab Binary files /dev/null and b/models/rouyan_new/0/densepose.png differ diff --git a/models/rouyan_new/0/humanmask.png b/models/rouyan_new/0/humanmask.png new file mode 100644 index 0000000000000000000000000000000000000000..312c2baa78b90e7edaf1acd88265642768d228c5 Binary files /dev/null and b/models/rouyan_new/0/humanmask.png differ diff --git a/models/rouyan_new/0/initmask.png b/models/rouyan_new/0/initmask.png new file mode 100644 index 0000000000000000000000000000000000000000..fddbf24c957027b603cf5b88b82779a72d192f22 Binary files /dev/null and b/models/rouyan_new/0/initmask.png differ diff --git a/models/rouyan_new/0/model.png b/models/rouyan_new/0/model.png new file mode 100644 index 0000000000000000000000000000000000000000..6371fe113d1db941b0c16b8237aec323291a8955 Binary files /dev/null and b/models/rouyan_new/0/model.png differ diff --git a/models/rouyan_new/1/densepose.png b/models/rouyan_new/1/densepose.png new file mode 100644 index 0000000000000000000000000000000000000000..9dd81ff50719856bf2f6a0faa08de10bc234b3c8 Binary files /dev/null and b/models/rouyan_new/1/densepose.png differ diff --git a/models/rouyan_new/1/humanmask.png b/models/rouyan_new/1/humanmask.png new file mode 100644 index 0000000000000000000000000000000000000000..c079b370e250c45d2d1b395436c69b12b9c94de0 Binary files /dev/null and b/models/rouyan_new/1/humanmask.png differ diff --git a/models/rouyan_new/1/initmask.png b/models/rouyan_new/1/initmask.png new file mode 100644 index 0000000000000000000000000000000000000000..134859ca42fad5082a821899d527fac58a25b28d Binary files /dev/null and b/models/rouyan_new/1/initmask.png differ diff --git a/models/rouyan_new/1/model.png b/models/rouyan_new/1/model.png new file mode 100644 index 0000000000000000000000000000000000000000..cea983e91bd8c189c2d976cb1e2221562549d8c4 Binary files /dev/null and b/models/rouyan_new/1/model.png differ diff --git a/models/rouyan_new/2/densepose.png b/models/rouyan_new/2/densepose.png new file mode 100644 index 0000000000000000000000000000000000000000..fc45ad05662df36776acd4beaa6c1da077779506 Binary files /dev/null and b/models/rouyan_new/2/densepose.png differ diff --git a/models/rouyan_new/2/humanmask.png b/models/rouyan_new/2/humanmask.png new file mode 100644 index 0000000000000000000000000000000000000000..eac4394be9c7d9aad9c567b0a695dd1f2c1cdcb1 Binary files /dev/null and b/models/rouyan_new/2/humanmask.png differ diff --git a/models/rouyan_new/2/initmask.png b/models/rouyan_new/2/initmask.png new file mode 100644 index 0000000000000000000000000000000000000000..ec01a61b670c8f4e04c5be9e153e43eb284fb23a Binary files /dev/null and b/models/rouyan_new/2/initmask.png differ diff --git a/models/rouyan_new/2/model.png b/models/rouyan_new/2/model.png new file mode 100644 index 0000000000000000000000000000000000000000..ddf30201bfcabc71da81c1261fff89a316ede6a5 Binary files /dev/null and b/models/rouyan_new/2/model.png differ diff --git a/models/rouyan_new/Rouyan_0.png b/models/rouyan_new/Rouyan_0.png new file mode 100644 index 0000000000000000000000000000000000000000..6371fe113d1db941b0c16b8237aec323291a8955 Binary files /dev/null and b/models/rouyan_new/Rouyan_0.png differ diff --git a/models/rouyan_new/Rouyan_1.png b/models/rouyan_new/Rouyan_1.png new file mode 100644 index 0000000000000000000000000000000000000000..cea983e91bd8c189c2d976cb1e2221562549d8c4 Binary files /dev/null and b/models/rouyan_new/Rouyan_1.png differ diff --git a/models/rouyan_new/Rouyan_2.png b/models/rouyan_new/Rouyan_2.png new file mode 100644 index 0000000000000000000000000000000000000000..ddf30201bfcabc71da81c1261fff89a316ede6a5 Binary files /dev/null and b/models/rouyan_new/Rouyan_2.png differ diff --git a/models/simon_online/Simon_0.png b/models/simon_online/Simon_0.png new file mode 100644 index 0000000000000000000000000000000000000000..da459bc35de31063da6082d2ec2cd8a9ea6ce83f Binary files /dev/null and b/models/simon_online/Simon_0.png differ diff --git a/models/simon_online/Simon_1.png b/models/simon_online/Simon_1.png new file mode 100644 index 0000000000000000000000000000000000000000..06ee8f72f2f81a90c4b5c7d1dea5f575e445882a Binary files /dev/null and b/models/simon_online/Simon_1.png differ diff --git a/models/xiaoxuan/model.png b/models/xiaoxuan/model.png new file mode 100644 index 0000000000000000000000000000000000000000..c400004bb7af59681a687825f094a5f3fa7ab9ad Binary files /dev/null and b/models/xiaoxuan/model.png differ diff --git a/models/xiaoxuan_online/Xuanxuan_0.png b/models/xiaoxuan_online/Xuanxuan_0.png new file mode 100644 index 0000000000000000000000000000000000000000..c400004bb7af59681a687825f094a5f3fa7ab9ad Binary files /dev/null and b/models/xiaoxuan_online/Xuanxuan_0.png differ diff --git a/models/xiaoxuan_online/Xuanxuan_1.png b/models/xiaoxuan_online/Xuanxuan_1.png new file mode 100644 index 0000000000000000000000000000000000000000..fc791cb9f839610f9cedb28ff9c755e797b7ddc2 Binary files /dev/null and b/models/xiaoxuan_online/Xuanxuan_1.png differ diff --git a/models/xiaoxuan_online/Xuanxuan_2.png b/models/xiaoxuan_online/Xuanxuan_2.png new file mode 100644 index 0000000000000000000000000000000000000000..49e61e56ba4d8523858c3da20eeccec519de93c2 Binary files /dev/null and b/models/xiaoxuan_online/Xuanxuan_2.png differ diff --git a/models/yaqi/Yaqi_0.png b/models/yaqi/Yaqi_0.png new file mode 100644 index 0000000000000000000000000000000000000000..66b7e23458646ac46c7d340a4d21407ab8653991 Binary files /dev/null and b/models/yaqi/Yaqi_0.png differ diff --git a/models/yaqi/Yaqi_1.png b/models/yaqi/Yaqi_1.png new file mode 100644 index 0000000000000000000000000000000000000000..bd9a37dd31be5f3f196b7efc522318945343c0ca Binary files /dev/null and b/models/yaqi/Yaqi_1.png differ diff --git a/models/yifeng/model.png b/models/yifeng/model.png new file mode 100644 index 0000000000000000000000000000000000000000..337a542677a54ec5a7f96a715c87012098c5c56a Binary files /dev/null and b/models/yifeng/model.png differ diff --git a/models/yifeng_online/Yifeng_0.png b/models/yifeng_online/Yifeng_0.png new file mode 100644 index 0000000000000000000000000000000000000000..82791dee68a8963a61679297c57d1c61f1a4403a Binary files /dev/null and b/models/yifeng_online/Yifeng_0.png differ diff --git a/models/yifeng_online/Yifeng_1.png b/models/yifeng_online/Yifeng_1.png new file mode 100644 index 0000000000000000000000000000000000000000..337a542677a54ec5a7f96a715c87012098c5c56a Binary files /dev/null and b/models/yifeng_online/Yifeng_1.png differ diff --git a/models/yifeng_online/Yifeng_2.png b/models/yifeng_online/Yifeng_2.png new file mode 100644 index 0000000000000000000000000000000000000000..97ebd04977174efb7a5915ec3a0c48c54699a745 Binary files /dev/null and b/models/yifeng_online/Yifeng_2.png differ diff --git a/models/yifeng_online/Yifeng_3.png b/models/yifeng_online/Yifeng_3.png new file mode 100644 index 0000000000000000000000000000000000000000..aa31c4af75bcb279c82ef6f2b3a0b306574a97b2 Binary files /dev/null and b/models/yifeng_online/Yifeng_3.png differ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..46781edb79473f3c08174b3c834464bcbee3ce67 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +opencv-python +IPython +gradio==3.41.2 +gradio-client==0.5.0 \ No newline at end of file