ArmanRV commited on
Commit
9e832a5
·
verified ·
1 Parent(s): 486cf9e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -12
app.py CHANGED
@@ -7,6 +7,26 @@ import spaces
7
  import gradio as gr
8
  from PIL import Image
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  import torch
11
  import numpy as np
12
  from torchvision import transforms
@@ -59,12 +79,12 @@ def ensure_garments_downloaded() -> None:
59
  if HF_TOKEN:
60
  try:
61
  login(token=HF_TOKEN, add_to_git_credential=False)
62
- print("HF login: OK")
63
  except Exception as e:
64
- print("HF login: FAILED:", str(e)[:200])
65
 
66
  if not GARMENTS_DATASET:
67
- print("GARMENTS_DATASET not set. Using local ./garments (if any).")
68
  return
69
 
70
  try:
@@ -75,9 +95,9 @@ def ensure_garments_downloaded() -> None:
75
  local_dir_use_symlinks=False,
76
  token=HF_TOKEN if HF_TOKEN else None,
77
  )
78
- print(f"Garments dataset downloaded: {GARMENTS_DATASET} -> {GARMENT_DIR}/")
79
  except Exception as e:
80
- print("Garments download FAILED:", str(e)[:300])
81
 
82
 
83
  def list_garments() -> List[str]:
@@ -145,7 +165,7 @@ base_path = "yisol/IDM-VTON"
145
 
146
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
147
  DTYPE = torch.float16 if DEVICE == "cuda" else torch.float32
148
- print("DEVICE:", DEVICE, "DTYPE:", DTYPE)
149
 
150
  tensor_transfrom = transforms.Compose(
151
  [transforms.ToTensor(), transforms.Normalize([0.5], [0.5])]
@@ -390,7 +410,6 @@ def tryon_ui(person_pil, selected_filename):
390
  )
391
  yield out, "✅ Готово"
392
  except Exception as e:
393
- # В UI покажем коротко, но в консоль уйдёт полный traceback через show_error=True
394
  yield None, f"❌ Ошибка: {type(e).__name__}: {str(e)[:220]}"
395
 
396
 
@@ -431,24 +450,22 @@ with gr.Blocks(title="Virtual Try-On Rendez-vous", css=CUSTOM_CSS) as demo:
431
  fn=on_gallery_select,
432
  inputs=[garment_files_state],
433
  outputs=[selected_garment_state, selected_label],
434
- concurrency_limit=8, # чтобы выбор в галерее не блокировался инференсом
435
  )
436
 
437
  refresh_btn.click(
438
  fn=refresh_catalog,
439
  inputs=[],
440
  outputs=[garment_gallery, garment_files_state, selected_garment_state, status],
441
- concurrency_limit=2,
442
  )
443
 
444
  run.click(
445
  fn=tryon_ui,
446
  inputs=[person, selected_garment_state],
447
  outputs=[out, status],
448
- concurrency_limit=1, # ✅ вместо demo.queue(concurrency_count=...)
449
  )
450
 
451
- # IMPORTANT: queue helps stability on GPU (Gradio 4.x: no concurrency_count)
452
  demo.queue(max_size=20)
453
 
454
  if __name__ == "__main__":
@@ -458,5 +475,6 @@ if __name__ == "__main__":
458
  share=False,
459
  auth=APP_AUTH,
460
  max_threads=4,
461
- show_error=True, # ✅ чтобы видеть настоящие ошибки, если "ничего не происходит"
 
462
  )
 
7
  import gradio as gr
8
  from PIL import Image
9
 
10
+ # =========================
11
+ # FIX: gradio 4.24 / gradio_client boolean schema crash in /api_info
12
+ # =========================
13
+ try:
14
+ import gradio_client.utils as gcu
15
+
16
+ _orig_get_type = gcu.get_type
17
+
18
+ def _get_type_patched(schema):
19
+ # JSON Schema allows boolean schemas (true/false). gradio_client 0.x may crash on bool.
20
+ if isinstance(schema, bool):
21
+ return "any"
22
+ return _orig_get_type(schema)
23
+
24
+ gcu.get_type = _get_type_patched
25
+ print("Patched gradio_client.utils.get_type for boolean schemas", flush=True)
26
+ except Exception as _e:
27
+ print("gradio_client patch skipped:", repr(_e), flush=True)
28
+
29
+
30
  import torch
31
  import numpy as np
32
  from torchvision import transforms
 
79
  if HF_TOKEN:
80
  try:
81
  login(token=HF_TOKEN, add_to_git_credential=False)
82
+ print("HF login: OK", flush=True)
83
  except Exception as e:
84
+ print("HF login: FAILED:", str(e)[:200], flush=True)
85
 
86
  if not GARMENTS_DATASET:
87
+ print("GARMENTS_DATASET not set. Using local ./garments (if any).", flush=True)
88
  return
89
 
90
  try:
 
95
  local_dir_use_symlinks=False,
96
  token=HF_TOKEN if HF_TOKEN else None,
97
  )
98
+ print(f"Garments dataset downloaded: {GARMENTS_DATASET} -> {GARMENT_DIR}/", flush=True)
99
  except Exception as e:
100
+ print("Garments download FAILED:", str(e)[:300], flush=True)
101
 
102
 
103
  def list_garments() -> List[str]:
 
165
 
166
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
167
  DTYPE = torch.float16 if DEVICE == "cuda" else torch.float32
168
+ print("DEVICE:", DEVICE, "DTYPE:", DTYPE, flush=True)
169
 
170
  tensor_transfrom = transforms.Compose(
171
  [transforms.ToTensor(), transforms.Normalize([0.5], [0.5])]
 
410
  )
411
  yield out, "✅ Готово"
412
  except Exception as e:
 
413
  yield None, f"❌ Ошибка: {type(e).__name__}: {str(e)[:220]}"
414
 
415
 
 
450
  fn=on_gallery_select,
451
  inputs=[garment_files_state],
452
  outputs=[selected_garment_state, selected_label],
 
453
  )
454
 
455
  refresh_btn.click(
456
  fn=refresh_catalog,
457
  inputs=[],
458
  outputs=[garment_gallery, garment_files_state, selected_garment_state, status],
 
459
  )
460
 
461
  run.click(
462
  fn=tryon_ui,
463
  inputs=[person, selected_garment_state],
464
  outputs=[out, status],
465
+ concurrency_limit=1, # ✅ правильный лимит в gradio 4.x
466
  )
467
 
468
+ # Gradio 4.x: no concurrency_count here
469
  demo.queue(max_size=20)
470
 
471
  if __name__ == "__main__":
 
475
  share=False,
476
  auth=APP_AUTH,
477
  max_threads=4,
478
+ show_error=True,
479
+ show_api=False, # ✅ главное: не дергаем /api_info (там у тебя падало)
480
  )