Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,37 @@ import requests
|
|
| 8 |
import json
|
| 9 |
import time
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
def tryon(person_img, garment_img, seed, randomize_seed):
|
| 13 |
post_start_time = time.time()
|
|
@@ -150,14 +181,6 @@ def start_tryon(person_img, garment_img, seed, randomize_seed):
|
|
| 150 |
|
| 151 |
MAX_SEED = 999999
|
| 152 |
|
| 153 |
-
example_path = os.path.join(os.path.dirname(__file__), 'assets')
|
| 154 |
-
|
| 155 |
-
garm_list = os.listdir(os.path.join(example_path,"cloth"))
|
| 156 |
-
garm_list_path = [os.path.join(example_path,"cloth",garm) for garm in garm_list]
|
| 157 |
-
|
| 158 |
-
human_list = os.listdir(os.path.join(example_path,"human"))
|
| 159 |
-
human_list_path = [os.path.join(example_path,"human",human) for human in human_list]
|
| 160 |
-
|
| 161 |
css="""
|
| 162 |
#col-left {
|
| 163 |
margin: 0 auto;
|
|
@@ -181,9 +204,12 @@ css="""
|
|
| 181 |
"""
|
| 182 |
|
| 183 |
def load_description(fp):
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
|
|
|
|
|
|
|
|
|
| 187 |
|
| 188 |
def change_imgs(image1, image2):
|
| 189 |
return image1, image2
|
|
@@ -211,7 +237,7 @@ with gr.Blocks(css=css) as Tryon:
|
|
| 211 |
gr.HTML("""
|
| 212 |
<div style="display: flex; justify-content: center; align-items: center; text-align: center; font-size: 20px;">
|
| 213 |
<div>
|
| 214 |
-
Step 3. Press
|
| 215 |
</div>
|
| 216 |
</div>
|
| 217 |
""")
|
|
@@ -219,18 +245,20 @@ with gr.Blocks(css=css) as Tryon:
|
|
| 219 |
with gr.Column(elem_id = "col-left"):
|
| 220 |
imgs = gr.Image(label="Person image", sources='upload', type="numpy")
|
| 221 |
# category = gr.Dropdown(label="Garment category", choices=['upper_body', 'lower_body', 'dresses'], value="upper_body")
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
|
|
|
| 227 |
with gr.Column(elem_id = "col-mid"):
|
| 228 |
garm_img = gr.Image(label="Garment image", sources='upload', type="numpy")
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
|
|
|
| 234 |
with gr.Column(elem_id = "col-right"):
|
| 235 |
image_out = gr.Image(label="Result", show_share_button=False)
|
| 236 |
with gr.Row():
|
|
@@ -245,11 +273,8 @@ with gr.Blocks(css=css) as Tryon:
|
|
| 245 |
with gr.Row():
|
| 246 |
seed_used = gr.Number(label="Seed used")
|
| 247 |
result_info = gr.Text(label="Response")
|
| 248 |
-
# try_button = gr.Button(value="Run", elem_id="button")
|
| 249 |
test_button = gr.Button(value="Run", elem_id="button")
|
| 250 |
|
| 251 |
-
|
| 252 |
-
# try_button.click(fn=start_tryon, inputs=[imgs, garm_img, seed, randomize_seed], outputs=[image_out, seed_used, result_info], api_name='tryon',concurrency_limit=10)
|
| 253 |
test_button.click(fn=tryon, inputs=[imgs, garm_img, seed, randomize_seed], outputs=[image_out, seed_used, result_info], api_name=False, concurrency_limit=45)
|
| 254 |
|
| 255 |
with gr.Column(elem_id = "col-showcase"):
|
|
@@ -272,4 +297,4 @@ with gr.Blocks(css=css) as Tryon:
|
|
| 272 |
label=None
|
| 273 |
)
|
| 274 |
|
| 275 |
-
Tryon.queue(api_open=False).launch(show_api=False)
|
|
|
|
| 8 |
import json
|
| 9 |
import time
|
| 10 |
|
| 11 |
+
# Önce dizinleri kontrol et ve gerekirse oluştur
|
| 12 |
+
example_path = os.path.join(os.path.dirname(__file__), 'assets')
|
| 13 |
+
|
| 14 |
+
# cloth dizini yoksa oluştur
|
| 15 |
+
cloth_path = os.path.join(example_path, "cloth")
|
| 16 |
+
if not os.path.exists(cloth_path):
|
| 17 |
+
os.makedirs(cloth_path, exist_ok=True)
|
| 18 |
+
print(f"'{cloth_path}' dizini oluşturuldu.")
|
| 19 |
+
|
| 20 |
+
# human dizini yoksa oluştur
|
| 21 |
+
human_path = os.path.join(example_path, "human")
|
| 22 |
+
if not os.path.exists(human_path):
|
| 23 |
+
os.makedirs(human_path, exist_ok=True)
|
| 24 |
+
print(f"'{human_path}' dizini oluşturuldu.")
|
| 25 |
+
|
| 26 |
+
# Örnek dosya listelerini al (dizin boşsa boş liste döndür)
|
| 27 |
+
try:
|
| 28 |
+
garm_list = os.listdir(cloth_path)
|
| 29 |
+
garm_list_path = [os.path.join(cloth_path, garm) for garm in garm_list]
|
| 30 |
+
except FileNotFoundError:
|
| 31 |
+
garm_list = []
|
| 32 |
+
garm_list_path = []
|
| 33 |
+
print("cloth dizini bulunamadı, boş örnek listesi kullanılıyor")
|
| 34 |
+
|
| 35 |
+
try:
|
| 36 |
+
human_list = os.listdir(human_path)
|
| 37 |
+
human_list_path = [os.path.join(human_path, human) for human in human_list]
|
| 38 |
+
except FileNotFoundError:
|
| 39 |
+
human_list = []
|
| 40 |
+
human_list_path = []
|
| 41 |
+
print("human dizini bulunamadı, boş örnek listesi kullanılıyor")
|
| 42 |
|
| 43 |
def tryon(person_img, garment_img, seed, randomize_seed):
|
| 44 |
post_start_time = time.time()
|
|
|
|
| 181 |
|
| 182 |
MAX_SEED = 999999
|
| 183 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
css="""
|
| 185 |
#col-left {
|
| 186 |
margin: 0 auto;
|
|
|
|
| 204 |
"""
|
| 205 |
|
| 206 |
def load_description(fp):
|
| 207 |
+
try:
|
| 208 |
+
with open(fp, 'r', encoding='utf-8') as f:
|
| 209 |
+
content = f.read()
|
| 210 |
+
return content
|
| 211 |
+
except FileNotFoundError:
|
| 212 |
+
return "<h1>Virtual Try-On Application</h1>"
|
| 213 |
|
| 214 |
def change_imgs(image1, image2):
|
| 215 |
return image1, image2
|
|
|
|
| 237 |
gr.HTML("""
|
| 238 |
<div style="display: flex; justify-content: center; align-items: center; text-align: center; font-size: 20px;">
|
| 239 |
<div>
|
| 240 |
+
Step 3. Press "Run" to get try-on results
|
| 241 |
</div>
|
| 242 |
</div>
|
| 243 |
""")
|
|
|
|
| 245 |
with gr.Column(elem_id = "col-left"):
|
| 246 |
imgs = gr.Image(label="Person image", sources='upload', type="numpy")
|
| 247 |
# category = gr.Dropdown(label="Garment category", choices=['upper_body', 'lower_body', 'dresses'], value="upper_body")
|
| 248 |
+
if human_list_path: # Sadece örnekler varsa göster
|
| 249 |
+
example = gr.Examples(
|
| 250 |
+
inputs=imgs,
|
| 251 |
+
examples_per_page=12,
|
| 252 |
+
examples=human_list_path
|
| 253 |
+
)
|
| 254 |
with gr.Column(elem_id = "col-mid"):
|
| 255 |
garm_img = gr.Image(label="Garment image", sources='upload', type="numpy")
|
| 256 |
+
if garm_list_path: # Sadece örnekler varsa göster
|
| 257 |
+
example = gr.Examples(
|
| 258 |
+
inputs=garm_img,
|
| 259 |
+
examples_per_page=12,
|
| 260 |
+
examples=garm_list_path
|
| 261 |
+
)
|
| 262 |
with gr.Column(elem_id = "col-right"):
|
| 263 |
image_out = gr.Image(label="Result", show_share_button=False)
|
| 264 |
with gr.Row():
|
|
|
|
| 273 |
with gr.Row():
|
| 274 |
seed_used = gr.Number(label="Seed used")
|
| 275 |
result_info = gr.Text(label="Response")
|
|
|
|
| 276 |
test_button = gr.Button(value="Run", elem_id="button")
|
| 277 |
|
|
|
|
|
|
|
| 278 |
test_button.click(fn=tryon, inputs=[imgs, garm_img, seed, randomize_seed], outputs=[image_out, seed_used, result_info], api_name=False, concurrency_limit=45)
|
| 279 |
|
| 280 |
with gr.Column(elem_id = "col-showcase"):
|
|
|
|
| 297 |
label=None
|
| 298 |
)
|
| 299 |
|
| 300 |
+
Tryon.queue(api_open=False).launch(show_api=False)
|