WeShopAI-Virtual-Try-On
Browse files- .gitattributes +4 -0
- app.py +386 -0
- assets/clothing/01.png +3 -0
- assets/clothing/02.png +3 -0
- assets/clothing/03.png +3 -0
- assets/clothing/04.png +3 -0
- assets/clothing/05.png +3 -0
- assets/clothing/06.png +3 -0
- assets/clothing/07.png +3 -0
- assets/clothing/08.png +3 -0
- assets/clothing/09.png +3 -0
- assets/examples/result_01_01.png +3 -0
- assets/examples/result_01_02.png +3 -0
- assets/examples/result_01_03.png +3 -0
- assets/examples/result_02_01.png +3 -0
- assets/examples/result_02_02.png +3 -0
- assets/examples/result_02_03.png +3 -0
- assets/examples/result_03_01.png +3 -0
- assets/examples/result_03_02.png +3 -0
- assets/examples/result_03_03.png +3 -0
- assets/examples/result_04_01.png +3 -0
- assets/examples/result_04_02.png +3 -0
- assets/examples/result_04_03.png +3 -0
- assets/examples/result_05_01.png +3 -0
- assets/examples/result_05_02.png +3 -0
- assets/examples/result_05_03.png +3 -0
- assets/human/01.png +3 -0
- assets/human/02.png +3 -0
- assets/human/03.png +3 -0
- assets/human/04.png +3 -0
- assets/human/05.png +3 -0
- assets/human/06.png +3 -0
- assets/human/07.png +3 -0
- assets/human/08.png +3 -0
- assets/human/09.png +3 -0
- assets/title.md +16 -0
.gitattributes
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
|
@@ -33,3 +35,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 1 |
+
.idea/
|
| 2 |
+
*.iml
|
| 3 |
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 4 |
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 5 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 35 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 36 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 37 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
|
@@ -0,0 +1,386 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import hmac
|
| 3 |
+
import hashlib
|
| 4 |
+
import time
|
| 5 |
+
import os
|
| 6 |
+
import requests
|
| 7 |
+
from io import BytesIO
|
| 8 |
+
from PIL import Image
|
| 9 |
+
import uuid
|
| 10 |
+
|
| 11 |
+
example_path = os.path.join(os.path.dirname(__file__), 'assets')
|
| 12 |
+
clothing_list = os.listdir(os.path.join(example_path, "clothing"))
|
| 13 |
+
clothing_list_path = [os.path.join(example_path, "clothing", clothing) for clothing in clothing_list]
|
| 14 |
+
human_list = os.listdir(os.path.join(example_path, "human"))
|
| 15 |
+
human_list_path = [os.path.join(example_path, "human", human) for human in human_list]
|
| 16 |
+
|
| 17 |
+
base_url = os.getenv('base_url')
|
| 18 |
+
upload_image_url = os.getenv('upload_image_url')
|
| 19 |
+
upload_background_image_url = os.getenv('upload_background_image_url')
|
| 20 |
+
create_save_task_url = os.getenv('create_save_task_url')
|
| 21 |
+
execute_task_url = os.getenv('execute_task_url')
|
| 22 |
+
query_task_url = os.getenv('query_task_url')
|
| 23 |
+
secret_key = os.getenv('secret_key')
|
| 24 |
+
agent_version = os.getenv('agent_version')
|
| 25 |
+
agent_name = os.getenv('agent_name')
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def parse_response(response):
|
| 29 |
+
data = {}
|
| 30 |
+
msg = ''
|
| 31 |
+
if response.status_code == 200:
|
| 32 |
+
try:
|
| 33 |
+
datas = response.json()
|
| 34 |
+
if datas:
|
| 35 |
+
data = datas.get("data")
|
| 36 |
+
if not data:
|
| 37 |
+
msg = datas.get("msg")
|
| 38 |
+
if not msg:
|
| 39 |
+
msg = "Field error."
|
| 40 |
+
else:
|
| 41 |
+
msg = "The parsing result is empty."
|
| 42 |
+
except Exception as e:
|
| 43 |
+
msg = f"parse error: {repr(e)}."
|
| 44 |
+
else:
|
| 45 |
+
msg = f'request error.'
|
| 46 |
+
return data, msg
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def generate_signature(key, did, timestamp):
|
| 50 |
+
data = f"{did}:{timestamp}"
|
| 51 |
+
h = hmac.new(key.encode(), data.encode(), hashlib.sha256)
|
| 52 |
+
return h.hexdigest()
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def url_to_image(url):
|
| 56 |
+
headers = {
|
| 57 |
+
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
| 58 |
+
}
|
| 59 |
+
try:
|
| 60 |
+
response = requests.get(url, headers=headers, timeout=30)
|
| 61 |
+
except:
|
| 62 |
+
return None
|
| 63 |
+
if response.status_code == 200:
|
| 64 |
+
img = Image.open(BytesIO(response.content))
|
| 65 |
+
return img
|
| 66 |
+
return None
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def start_task(task_id, timestamp, signature, did):
|
| 70 |
+
headers = {
|
| 71 |
+
'Did': did,
|
| 72 |
+
'X-Timestamp': timestamp,
|
| 73 |
+
'X-Signature': signature
|
| 74 |
+
}
|
| 75 |
+
data = {
|
| 76 |
+
"agentVersion": agent_version,
|
| 77 |
+
"agentName": agent_name,
|
| 78 |
+
"taskId": task_id,
|
| 79 |
+
"runFreeAsFallback": False
|
| 80 |
+
}
|
| 81 |
+
response = requests.post(base_url + execute_task_url, json=data, headers=headers)
|
| 82 |
+
data, msg = parse_response(response)
|
| 83 |
+
return data, msg
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def create_task(image_url, timestamp, signature, did):
|
| 87 |
+
headers = {
|
| 88 |
+
'Did': did,
|
| 89 |
+
'X-Timestamp': timestamp,
|
| 90 |
+
'X-Signature': signature
|
| 91 |
+
}
|
| 92 |
+
data = {
|
| 93 |
+
"agentVersion": agent_version,
|
| 94 |
+
"agentName": agent_name,
|
| 95 |
+
"image": image_url
|
| 96 |
+
}
|
| 97 |
+
response = requests.post(base_url + create_save_task_url, json=data, headers=headers)
|
| 98 |
+
data, msg = parse_response(response)
|
| 99 |
+
return data, msg
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def save_task(image_url, timestamp, signature, show_image, task_id, location_id, did):
|
| 103 |
+
headers = {
|
| 104 |
+
'Did': did,
|
| 105 |
+
'X-Timestamp': timestamp,
|
| 106 |
+
'X-Signature': signature
|
| 107 |
+
}
|
| 108 |
+
data = {
|
| 109 |
+
"agentVersion": agent_version,
|
| 110 |
+
"agentName": agent_name,
|
| 111 |
+
"image": image_url,
|
| 112 |
+
"showImage": show_image,
|
| 113 |
+
"taskId": task_id,
|
| 114 |
+
"locationId": location_id,
|
| 115 |
+
}
|
| 116 |
+
response = requests.post(base_url + create_save_task_url, json=data, headers=headers)
|
| 117 |
+
data, msg = parse_response(response)
|
| 118 |
+
return data, msg
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
def query_task(task_id, execution_id, timestamp, signature, did):
|
| 122 |
+
headers = {
|
| 123 |
+
'Did': did,
|
| 124 |
+
'X-Timestamp': timestamp,
|
| 125 |
+
'X-Signature': signature
|
| 126 |
+
}
|
| 127 |
+
data = {
|
| 128 |
+
"agentVersion": agent_version,
|
| 129 |
+
"agentName": agent_name,
|
| 130 |
+
"taskId": task_id,
|
| 131 |
+
"executionId": execution_id,
|
| 132 |
+
}
|
| 133 |
+
response = requests.post(base_url + query_task_url, json=data, headers=headers)
|
| 134 |
+
data, msg = parse_response(response)
|
| 135 |
+
return data, msg
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
def upload_image(image, signature, timestamp, upload_type, did):
|
| 139 |
+
if image is None:
|
| 140 |
+
return None
|
| 141 |
+
if upload_type == 'image':
|
| 142 |
+
upload_url = upload_image_url
|
| 143 |
+
else:
|
| 144 |
+
upload_url = upload_background_image_url
|
| 145 |
+
image_format = image.format if image.format else "PNG"
|
| 146 |
+
mime_type = f"image/{image_format.lower()}"
|
| 147 |
+
with BytesIO() as m_img:
|
| 148 |
+
image.save(m_img, format=image_format)
|
| 149 |
+
m_img.seek(0)
|
| 150 |
+
files = {'image': (f"main_image.{image_format.lower()}", m_img, mime_type)}
|
| 151 |
+
headers = {
|
| 152 |
+
'Did': did,
|
| 153 |
+
'X-Timestamp': timestamp,
|
| 154 |
+
'X-Signature': signature
|
| 155 |
+
}
|
| 156 |
+
response = requests.post(base_url + upload_url, files=files, headers=headers)
|
| 157 |
+
data, msg = parse_response(response)
|
| 158 |
+
return data, msg
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
def load_description(file_path):
|
| 162 |
+
with open(file_path, 'r', encoding='utf-8') as file:
|
| 163 |
+
content = file.read()
|
| 164 |
+
return content
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def generate_image(main_image, background_image, did):
|
| 168 |
+
if not did:
|
| 169 |
+
did = str(uuid.uuid4())
|
| 170 |
+
if main_image is None or background_image is None:
|
| 171 |
+
m = "Please upload both the main image and the background reference image before generating."
|
| 172 |
+
return gr.Warning(m), did
|
| 173 |
+
|
| 174 |
+
timestamp = str(int(time.time()))
|
| 175 |
+
signature = generate_signature(
|
| 176 |
+
key=secret_key,
|
| 177 |
+
did=did,
|
| 178 |
+
timestamp=timestamp
|
| 179 |
+
)
|
| 180 |
+
upload_image_data, upload_image_msg = upload_image(
|
| 181 |
+
image=main_image,
|
| 182 |
+
signature=signature,
|
| 183 |
+
timestamp=timestamp,
|
| 184 |
+
upload_type='image',
|
| 185 |
+
did=did
|
| 186 |
+
)
|
| 187 |
+
if not upload_image_data:
|
| 188 |
+
return gr.Warning(upload_image_msg), did
|
| 189 |
+
image_url = upload_image_data.get("image")
|
| 190 |
+
if not image_url:
|
| 191 |
+
m = 'Upload image failed.'
|
| 192 |
+
return gr.Warning(m), did
|
| 193 |
+
create_task_data, create_task_msg = create_task(
|
| 194 |
+
image_url=image_url,
|
| 195 |
+
timestamp=timestamp,
|
| 196 |
+
signature=signature,
|
| 197 |
+
did=did
|
| 198 |
+
)
|
| 199 |
+
if not create_task_data:
|
| 200 |
+
return gr.Warning(create_task_msg), did
|
| 201 |
+
task_id = create_task_data.get("taskId")
|
| 202 |
+
show_image = create_task_data.get("showImage")
|
| 203 |
+
if not task_id or not show_image:
|
| 204 |
+
m = 'Create task failed.'
|
| 205 |
+
return gr.Warning(m), did
|
| 206 |
+
upload_image_data, upload_image_msg = upload_image(
|
| 207 |
+
image=background_image,
|
| 208 |
+
signature=signature,
|
| 209 |
+
timestamp=timestamp,
|
| 210 |
+
upload_type='background_image',
|
| 211 |
+
did=did
|
| 212 |
+
)
|
| 213 |
+
if not upload_image_data:
|
| 214 |
+
return gr.Warning(upload_image_msg), did
|
| 215 |
+
|
| 216 |
+
save_task_data, save_task_msg = save_task(
|
| 217 |
+
image_url=image_url,
|
| 218 |
+
timestamp=timestamp,
|
| 219 |
+
signature=signature,
|
| 220 |
+
show_image=show_image,
|
| 221 |
+
task_id=task_id,
|
| 222 |
+
location_id=upload_image_data,
|
| 223 |
+
did=did
|
| 224 |
+
)
|
| 225 |
+
if not save_task_data:
|
| 226 |
+
return gr.Warning(save_task_msg), did
|
| 227 |
+
save_task_id = save_task_data.get("taskId")
|
| 228 |
+
save_show_image = save_task_data.get("showImage")
|
| 229 |
+
if not save_task_id or not save_show_image:
|
| 230 |
+
return gr.Warning('Save task failed'), did
|
| 231 |
+
start_task_data, start_task_msg = start_task(
|
| 232 |
+
task_id=save_task_id,
|
| 233 |
+
timestamp=timestamp,
|
| 234 |
+
signature=signature,
|
| 235 |
+
did=did
|
| 236 |
+
)
|
| 237 |
+
if not start_task_data:
|
| 238 |
+
return gr.Warning(start_task_msg), did
|
| 239 |
+
execution_id = start_task_data.get("executionId")
|
| 240 |
+
if not execution_id:
|
| 241 |
+
m = "The task failed to start."
|
| 242 |
+
return gr.Warning(m), did
|
| 243 |
+
start_time = int(time.time())
|
| 244 |
+
while True:
|
| 245 |
+
m = "Query task failed."
|
| 246 |
+
query_task_data, query_task_msg = query_task(
|
| 247 |
+
task_id=save_task_id,
|
| 248 |
+
execution_id=execution_id,
|
| 249 |
+
timestamp=timestamp,
|
| 250 |
+
signature=signature,
|
| 251 |
+
did=did
|
| 252 |
+
)
|
| 253 |
+
if not query_task_data:
|
| 254 |
+
return gr.Warning(query_task_msg), did
|
| 255 |
+
executions = query_task_data.get("executions")
|
| 256 |
+
if not executions:
|
| 257 |
+
return gr.Warning(m), did
|
| 258 |
+
results = executions[0].get("result")
|
| 259 |
+
if not results:
|
| 260 |
+
return gr.Warning(m), did
|
| 261 |
+
status = results[0].get("status")
|
| 262 |
+
if status == "Failed":
|
| 263 |
+
return gr.Warning(m), did
|
| 264 |
+
elif status == "Success" or status == "Blocked":
|
| 265 |
+
img = results[0].get("image")
|
| 266 |
+
if img and str(img).strip() != "":
|
| 267 |
+
return url_to_image(img), did
|
| 268 |
+
end_time = int(time.time())
|
| 269 |
+
if end_time - start_time > 3600:
|
| 270 |
+
m = 'Query task timeout.'
|
| 271 |
+
return gr.Warning(m), did
|
| 272 |
+
time.sleep(2)
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
def preprocess_image(main_image):
|
| 276 |
+
return main_image
|
| 277 |
+
|
| 278 |
+
|
| 279 |
+
def preprocess_background_image(background_image):
|
| 280 |
+
return background_image
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
css = """
|
| 284 |
+
.image-container img {
|
| 285 |
+
max-height: 500px;
|
| 286 |
+
width: auto;
|
| 287 |
+
}
|
| 288 |
+
.hide-buttons .source-selection {
|
| 289 |
+
display: none;
|
| 290 |
+
}
|
| 291 |
+
#example-images .gallery {
|
| 292 |
+
display: flex;
|
| 293 |
+
flex-wrap: wrap;
|
| 294 |
+
}
|
| 295 |
+
#example-images .gallery-item .container{
|
| 296 |
+
width: 100%;
|
| 297 |
+
max-width: 100%;
|
| 298 |
+
}
|
| 299 |
+
#example-images .gallery-item {
|
| 300 |
+
flex: 0 0 32%;
|
| 301 |
+
max-width: 32%;
|
| 302 |
+
box-sizing: border-box;
|
| 303 |
+
display: flex;
|
| 304 |
+
text-align: center;
|
| 305 |
+
justify-content: center;
|
| 306 |
+
height: 200px;
|
| 307 |
+
}
|
| 308 |
+
"""
|
| 309 |
+
|
| 310 |
+
with gr.Blocks(css=css) as WeShop:
|
| 311 |
+
current_did = gr.State(value='')
|
| 312 |
+
gr.HTML(load_description("assets/title.md"))
|
| 313 |
+
with gr.Row():
|
| 314 |
+
with gr.Column():
|
| 315 |
+
gr.Markdown("#### Step 1: Upload a main image")
|
| 316 |
+
main_image_input = gr.Image(
|
| 317 |
+
type="pil",
|
| 318 |
+
label="Main Image",
|
| 319 |
+
elem_classes=["image-container", "hide-buttons"]
|
| 320 |
+
)
|
| 321 |
+
clothing_example = gr.Examples(
|
| 322 |
+
inputs=main_image_input,
|
| 323 |
+
examples_per_page=12,
|
| 324 |
+
examples=clothing_list_path,
|
| 325 |
+
elem_id="example-images",
|
| 326 |
+
outputs=main_image_input
|
| 327 |
+
)
|
| 328 |
+
|
| 329 |
+
with gr.Column():
|
| 330 |
+
gr.Markdown("#### Step 2: Upload a background reference image")
|
| 331 |
+
background_image_input = gr.Image(
|
| 332 |
+
type="pil",
|
| 333 |
+
label="Background reference image",
|
| 334 |
+
elem_classes=["image-container", "hide-buttons"]
|
| 335 |
+
)
|
| 336 |
+
human_example = gr.Examples(
|
| 337 |
+
inputs=background_image_input,
|
| 338 |
+
examples_per_page=12,
|
| 339 |
+
examples=human_list_path,
|
| 340 |
+
elem_id="example-images",
|
| 341 |
+
outputs=background_image_input
|
| 342 |
+
)
|
| 343 |
+
with gr.Column():
|
| 344 |
+
with gr.Row():
|
| 345 |
+
with gr.Column():
|
| 346 |
+
gr.Markdown("#### Step 3: Press 'Generate' to get the result")
|
| 347 |
+
output = gr.Image(
|
| 348 |
+
label="Result",
|
| 349 |
+
elem_classes=["image-container", "hide-buttons"],
|
| 350 |
+
interactive=False
|
| 351 |
+
)
|
| 352 |
+
with gr.Row():
|
| 353 |
+
submit_button = gr.Button("Generate")
|
| 354 |
+
submit_button.click(
|
| 355 |
+
fn=generate_image,
|
| 356 |
+
inputs=[main_image_input, background_image_input, current_did],
|
| 357 |
+
outputs=[output, current_did],
|
| 358 |
+
concurrency_limit=None
|
| 359 |
+
)
|
| 360 |
+
with gr.Column():
|
| 361 |
+
show_case = gr.Examples(
|
| 362 |
+
examples=[
|
| 363 |
+
["assets/examples/result_01_01.png", "assets/examples/result_01_02.png",
|
| 364 |
+
"assets/examples/result_01_03.png"],
|
| 365 |
+
["assets/examples/result_02_01.png", "assets/examples/result_02_02.png",
|
| 366 |
+
"assets/examples/result_02_03.png"],
|
| 367 |
+
["assets/examples/result_03_01.png", "assets/examples/result_03_02.png",
|
| 368 |
+
"assets/examples/result_03_03.png"],
|
| 369 |
+
["assets/examples/result_04_01.png", "assets/examples/result_04_02.png",
|
| 370 |
+
"assets/examples/result_04_03.png"],
|
| 371 |
+
["assets/examples/result_05_01.png", "assets/examples/result_05_02.png",
|
| 372 |
+
"assets/examples/result_05_03.png"],
|
| 373 |
+
],
|
| 374 |
+
inputs=[main_image_input, background_image_input, output],
|
| 375 |
+
)
|
| 376 |
+
main_image_input.upload(
|
| 377 |
+
fn=preprocess_image,
|
| 378 |
+
inputs=[main_image_input],
|
| 379 |
+
outputs=main_image_input
|
| 380 |
+
)
|
| 381 |
+
background_image_input.upload(
|
| 382 |
+
fn=preprocess_background_image,
|
| 383 |
+
inputs=[background_image_input],
|
| 384 |
+
outputs=background_image_input
|
| 385 |
+
)
|
| 386 |
+
WeShop.queue(api_open=False).launch(show_api=False)
|
assets/clothing/01.png
ADDED
|
Git LFS Details
|
assets/clothing/02.png
ADDED
|
Git LFS Details
|
assets/clothing/03.png
ADDED
|
Git LFS Details
|
assets/clothing/04.png
ADDED
|
Git LFS Details
|
assets/clothing/05.png
ADDED
|
Git LFS Details
|
assets/clothing/06.png
ADDED
|
Git LFS Details
|
assets/clothing/07.png
ADDED
|
Git LFS Details
|
assets/clothing/08.png
ADDED
|
Git LFS Details
|
assets/clothing/09.png
ADDED
|
Git LFS Details
|
assets/examples/result_01_01.png
ADDED
|
Git LFS Details
|
assets/examples/result_01_02.png
ADDED
|
Git LFS Details
|
assets/examples/result_01_03.png
ADDED
|
Git LFS Details
|
assets/examples/result_02_01.png
ADDED
|
Git LFS Details
|
assets/examples/result_02_02.png
ADDED
|
Git LFS Details
|
assets/examples/result_02_03.png
ADDED
|
Git LFS Details
|
assets/examples/result_03_01.png
ADDED
|
Git LFS Details
|
assets/examples/result_03_02.png
ADDED
|
Git LFS Details
|
assets/examples/result_03_03.png
ADDED
|
Git LFS Details
|
assets/examples/result_04_01.png
ADDED
|
Git LFS Details
|
assets/examples/result_04_02.png
ADDED
|
Git LFS Details
|
assets/examples/result_04_03.png
ADDED
|
Git LFS Details
|
assets/examples/result_05_01.png
ADDED
|
Git LFS Details
|
assets/examples/result_05_02.png
ADDED
|
Git LFS Details
|
assets/examples/result_05_03.png
ADDED
|
Git LFS Details
|
assets/human/01.png
ADDED
|
Git LFS Details
|
assets/human/02.png
ADDED
|
Git LFS Details
|
assets/human/03.png
ADDED
|
Git LFS Details
|
assets/human/04.png
ADDED
|
Git LFS Details
|
assets/human/05.png
ADDED
|
Git LFS Details
|
assets/human/06.png
ADDED
|
Git LFS Details
|
assets/human/07.png
ADDED
|
Git LFS Details
|
assets/human/08.png
ADDED
|
Git LFS Details
|
assets/human/09.png
ADDED
|
Git LFS Details
|
assets/title.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<div>
|
| 2 |
+
<div>
|
| 3 |
+
<div style="display: flex; justify-content: center; align-items: center; text-align: center; font-size: 40px;">
|
| 4 |
+
<b>WeShopAI Virtual Try-On</b>
|
| 5 |
+
</div>
|
| 6 |
+
<br>
|
| 7 |
+
<div style="display: flex; justify-content: center; align-items: center; text-align: center;">
|
| 8 |
+
<a href="https://www.weshop.com/"><img src="https://img.shields.io/static/v1?label=Official Website&message=CN&color=red"></a>  
|
| 9 |
+
<a href="https://www.weshop.ai/"><img src="https://img.shields.io/static/v1?label=Official Website&message=EN&color=blue"></a>
|
| 10 |
+
</div>
|
| 11 |
+
<br>
|
| 12 |
+
<div style="display: flex; text-align: center; font-size: 14px; padding-right: 200px; padding-left: 200px;">
|
| 13 |
+
<strong>Disclaimer: </strong>The WeShopAI-Virtual-Try-On Demo on HuggingFace space is free for trials. Any solicitation for payment based on the free features we provide on HuggingFace Space is a fraudulent act. Beware of scams and do not fall victim to deceit.
|
| 14 |
+
</div>
|
| 15 |
+
</div>
|
| 16 |
+
</div>
|