ArmanRV commited on
Commit
d530eca
·
verified ·
1 Parent(s): d1443b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -13
app.py CHANGED
@@ -4,7 +4,7 @@ import time
4
  import tempfile
5
 
6
  import gradio as gr
7
- import spaces # required for ZeroGPU (needs at least one @spaces.GPU function)
8
  from PIL import Image
9
  from gradio_client import Client, handle_file
10
  from huggingface_hub import login
@@ -34,12 +34,19 @@ def reset_client():
34
 
35
 
36
  def get_client():
 
 
 
 
37
  global _client
38
  if _client is None:
39
- # HF_TOKEN может помочь при приватных спейсах / ограничениях
40
- if HF_TOKEN:
41
- _client = Client(SPACE, hf_token=HF_TOKEN)
42
- else:
 
 
 
43
  _client = Client(SPACE)
44
  return _client
45
 
@@ -60,9 +67,6 @@ def save_pil_temp(pil_img: Image.Image, suffix: str = ".png") -> str:
60
  return path
61
 
62
 
63
- # ✅ ZeroGPU: должна быть хотя бы одна функция, помеченная @spaces.GPU
64
- # ВАЖНО: в твоём текущем решении GPU локально не используется (ты вызываешь удалённый Space),
65
- # но декоратор нужен, чтобы ZeroGPU runtime не падал на старте.
66
  @spaces.GPU(duration=180)
67
  def tryon_remote(person_pil, garment_pil, garment_desc, auto_mask, crop_center, denoise_steps, seed):
68
  if person_pil is None:
@@ -73,7 +77,6 @@ def tryon_remote(person_pil, garment_pil, garment_desc, auto_mask, crop_center,
73
  denoise_steps = clamp_int(denoise_steps, 10, 40)
74
  seed = clamp_int(seed, 0, 999999)
75
 
76
- # если описание пустое — дадим нейтральный дефолт (повышает стабильность)
77
  garment_desc = (garment_desc or "").strip()
78
  if not garment_desc:
79
  garment_desc = "a photo of a garment"
@@ -102,8 +105,6 @@ def tryon_remote(person_pil, garment_pil, garment_desc, auto_mask, crop_center,
102
  if isinstance(result, (list, tuple)):
103
  result = result[0]
104
 
105
- # result обычно путь к файлу (temp) или URL — Image.open умеет путь,
106
- # но если придёт нечто странное, поймаем исключение ниже.
107
  out = Image.open(result).convert("RGB")
108
  return out, f"✅ Готово (steps={denoise_steps}, seed={seed}, crop={crop_center})"
109
 
@@ -126,7 +127,6 @@ def tryon_remote(person_pil, garment_pil, garment_desc, auto_mask, crop_center,
126
  or "zerogpu" in msg
127
  )
128
 
129
- # ✅ ключевая правка под ZeroGPU-прокси
130
  is_expired = "expired zerogpu proxy token" in msg or "zerogpu proxy token" in msg
131
 
132
  if is_timeout or is_busy or is_expired:
@@ -157,7 +157,6 @@ div[class*="footer"] {display:none !important;}
157
  button[aria-label="Settings"] {display:none !important;}
158
  """
159
 
160
- # ✅ CSS правильно задаём на уровне Blocks
161
  with gr.Blocks(title="Virtual Try-On Rendez-vous", css=CUSTOM_CSS) as demo:
162
  gr.Markdown("# Virtual Try-On Rendez-vous")
163
 
 
4
  import tempfile
5
 
6
  import gradio as gr
7
+ import spaces # required for ZeroGPU runtime (needs at least one @spaces.GPU function)
8
  from PIL import Image
9
  from gradio_client import Client, handle_file
10
  from huggingface_hub import login
 
34
 
35
 
36
  def get_client():
37
+ """
38
+ gradio_client в разных версиях поддерживает разные параметры.
39
+ В некоторых версиях нет hf_token=..., поэтому делаем fallback.
40
+ """
41
  global _client
42
  if _client is None:
43
+ try:
44
+ if HF_TOKEN:
45
+ _client = Client(SPACE, hf_token=HF_TOKEN) # new gradio_client
46
+ else:
47
+ _client = Client(SPACE)
48
+ except TypeError:
49
+ # old gradio_client: no hf_token kwarg
50
  _client = Client(SPACE)
51
  return _client
52
 
 
67
  return path
68
 
69
 
 
 
 
70
  @spaces.GPU(duration=180)
71
  def tryon_remote(person_pil, garment_pil, garment_desc, auto_mask, crop_center, denoise_steps, seed):
72
  if person_pil is None:
 
77
  denoise_steps = clamp_int(denoise_steps, 10, 40)
78
  seed = clamp_int(seed, 0, 999999)
79
 
 
80
  garment_desc = (garment_desc or "").strip()
81
  if not garment_desc:
82
  garment_desc = "a photo of a garment"
 
105
  if isinstance(result, (list, tuple)):
106
  result = result[0]
107
 
 
 
108
  out = Image.open(result).convert("RGB")
109
  return out, f"✅ Готово (steps={denoise_steps}, seed={seed}, crop={crop_center})"
110
 
 
127
  or "zerogpu" in msg
128
  )
129
 
 
130
  is_expired = "expired zerogpu proxy token" in msg or "zerogpu proxy token" in msg
131
 
132
  if is_timeout or is_busy or is_expired:
 
157
  button[aria-label="Settings"] {display:none !important;}
158
  """
159
 
 
160
  with gr.Blocks(title="Virtual Try-On Rendez-vous", css=CUSTOM_CSS) as demo:
161
  gr.Markdown("# Virtual Try-On Rendez-vous")
162