import os import cv2 import random import gradio as gr from gradio_client import Client, handle_file machine_number = 0 model = os.path.join(os.path.dirname(__file__), "models/eva/Eva_0.png") client = Client("HumanAIGC/OutfitAnyone") 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 = "AI Model " + model_name.split("\\")[-1].split(".")[0] # windows _model = "AI Model " + model_name.split("/")[-1].split(".")[0] # linux print("Use Model:", _model) seed = random.randint(0, 1222222222) garment1 = handle_file(garment1) if garment1 else None garment2 = handle_file(garment2) if garment2 else None result = client.predict( handle_file(model_name), garment1, garment2, api_name="/get_tryon_result", fn_index=seed ) final_img = remove_watermark2(result) return final_img def remove_watermark2(path): img = cv2.imread(path) img_ = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) h, w, _ = img.shape y_start = max(h - 45, 0) y_end = h x_start = max(int(0.3 * w), 0) x_end = w img_[y_start:y_end, x_start:x_end, :] = [255, 255, 255] return img_ with gr.Blocks(css=".output-image, .input-image, .image-preview {height: 400px !important} ") as demo: # gr.Markdown("# Outfit Anyone v0.9") gr.HTML( """
""") 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( """