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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -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 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,19 +34,14 @@ def reset_client():
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
 
@@ -63,11 +58,13 @@ def save_pil_temp(pil_img: Image.Image, suffix: str = ".png") -> str:
63
  f = tempfile.NamedTemporaryFile(delete=False, suffix=suffix)
64
  path = f.name
65
  f.close()
66
- pil_img.save(path, format="PNG") # без ресайза и компрессии
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:
73
  return None, "❌ Загрузите фото человека"
@@ -165,10 +162,7 @@ with gr.Blocks(title="Virtual Try-On Rendez-vous", css=CUSTOM_CSS) as demo:
165
  person = gr.Image(label="Фото человека", type="pil", height=420)
166
  garment = gr.Image(label="Одежда", type="pil", height=320)
167
 
168
- garment_desc = gr.Textbox(
169
- label="Описание одежды",
170
- value=""
171
- )
172
 
173
  with gr.Accordion("Настройки", open=False):
174
  auto_mask = gr.Checkbox(label="Auto-mask (Space)", value=True)
 
4
  import tempfile
5
 
6
  import gradio as gr
7
+ import spaces
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
  global _client
38
  if _client is None:
39
  try:
40
  if HF_TOKEN:
41
+ _client = Client(SPACE, hf_token=HF_TOKEN)
42
  else:
43
  _client = Client(SPACE)
44
  except TypeError:
 
45
  _client = Client(SPACE)
46
  return _client
47
 
 
58
  f = tempfile.NamedTemporaryFile(delete=False, suffix=suffix)
59
  path = f.name
60
  f.close()
61
+ pil_img.save(path, format="PNG")
62
  return path
63
 
64
 
65
+ # ✅ УМЕНЬШЕН GPU duration (было 180)
66
+ # ZeroGPU теперь будет резервировать максимум 20 секунд
67
+ @spaces.GPU(duration=20)
68
  def tryon_remote(person_pil, garment_pil, garment_desc, auto_mask, crop_center, denoise_steps, seed):
69
  if person_pil is None:
70
  return None, "❌ Загрузите фото человека"
 
162
  person = gr.Image(label="Фото человека", type="pil", height=420)
163
  garment = gr.Image(label="Одежда", type="pil", height=320)
164
 
165
+ garment_desc = gr.Textbox(label="Описание одежды", value="")
 
 
 
166
 
167
  with gr.Accordion("Настройки", open=False):
168
  auto_mask = gr.Checkbox(label="Auto-mask (Space)", value=True)