Zaiiida commited on
Commit
fa7e77a
·
verified ·
1 Parent(s): 271726a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -9
app.py CHANGED
@@ -5,6 +5,7 @@ import spaces
5
  from diffusers import DiffusionPipeline
6
  import torch
7
 
 
8
  device = "cuda" if torch.cuda.is_available() else "cpu"
9
  model_repo_id = "stabilityai/stable-diffusion-3.5-large"
10
 
@@ -17,22 +18,36 @@ pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
17
  pipe = pipe.to(device)
18
 
19
  MAX_SEED = np.iinfo(np.int32).max
20
- MAX_IMAGE_SIZE = 1024
21
- examples = [
22
- "A full-body depiction of a futuristic cyberpunk warrior wearing neon armor with intricate details, holding a sleek glowing katana in a ready stance. The character stands confidently with glowing eyes and a dynamic pose that exudes strength and mystery. Isolated on a clean, transparent, or neutral background to emphasize the character's design and details, with subtle reflections and lighting to enhance the neon glow and textures.",
23
- ]
24
- @spaces.GPU(duration=30) # Установите меньшее значение
 
 
 
 
 
25
  def infer(
26
  prompt,
27
  negative_prompt="",
28
- seed=20,
29
  randomize_seed=False,
30
- width=768,
31
- height=1024,
32
  guidance_scale=4.5,
33
- num_inference_steps=12,
34
  progress=gr.Progress(track_tqdm=True),
35
  ):
 
 
 
 
 
 
 
 
 
36
  if randomize_seed:
37
  seed = random.randint(0, MAX_SEED)
38
 
 
5
  from diffusers import DiffusionPipeline
6
  import torch
7
 
8
+ # Подключение к устройству
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
  model_repo_id = "stabilityai/stable-diffusion-3.5-large"
11
 
 
18
  pipe = pipe.to(device)
19
 
20
  MAX_SEED = np.iinfo(np.int32).max
21
+ MAX_IMAGE_SIZE = 512 # Базовый размер изображения
22
+
23
+ # Проверка доступного времени GPU
24
+ def get_available_gpu_quota():
25
+ # Симуляция запроса (в реальном случае можно подключить API Hugging Face)
26
+ # Здесь вы можете вручную ввести оставшееся время
27
+ return 20 # Пример: 20 секунд доступно
28
+
29
+ # Динамическая настройка
30
+ @spaces.GPU(duration=min(get_available_gpu_quota(), 30)) # Устанавливаем время в пределах доступного
31
  def infer(
32
  prompt,
33
  negative_prompt="",
34
+ seed=42,
35
  randomize_seed=False,
36
+ width=None, # Размер будет определён динамически
37
+ height=None, # Размер будет определён динамически
38
  guidance_scale=4.5,
39
+ num_inference_steps=10, # Базовое значение
40
  progress=gr.Progress(track_tqdm=True),
41
  ):
42
+ available_time = get_available_gpu_quota() # Получаем доступное время
43
+ # Настраиваем параметры под оставшееся время
44
+ if available_time < 20:
45
+ num_inference_steps = max(5, int(available_time / 2)) # Уменьшаем шаги
46
+ width = height = min(MAX_IMAGE_SIZE, 384) # Уменьшаем размер
47
+ else:
48
+ num_inference_steps = 15
49
+ width = height = 512 # Стандартный размер
50
+
51
  if randomize_seed:
52
  seed = random.randint(0, MAX_SEED)
53