Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -20,35 +20,36 @@ pipe = pipe.to(device)
|
|
20 |
MAX_SEED = np.iinfo(np.int32).max
|
21 |
MAX_IMAGE_SIZE = 1024
|
22 |
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
def infer(
|
25 |
prompt,
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
height=1024,
|
31 |
-
guidance_scale=4.5,
|
32 |
-
num_inference_steps=20,
|
33 |
-
progress=gr.Progress(track_tqdm=True),
|
34 |
):
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
height=height,
|
48 |
-
generator=generator,
|
49 |
-
).images[0]
|
50 |
|
51 |
-
return image, seed
|
52 |
|
53 |
except Exception as e:
|
54 |
# Log the exception if needed
|
@@ -60,9 +61,7 @@ def infer(
|
|
60 |
"Please wait a moment and try again."
|
61 |
)
|
62 |
|
63 |
-
|
64 |
-
"A border collie lying in some Fall leaves as the forest trees change colors",
|
65 |
-
]
|
66 |
|
67 |
# Define the custom theme with input styles
|
68 |
class CustomTheme(gr.themes.Base):
|
|
|
20 |
MAX_SEED = np.iinfo(np.int32).max
|
21 |
MAX_IMAGE_SIZE = 1024
|
22 |
|
23 |
+
def calculate_duration(width, height, num_inference_steps):
|
24 |
+
# Примерная оценка времени выполнения
|
25 |
+
base_time = 10 # Минимальное время для 512x512, 10 шагов
|
26 |
+
time_factor = (width * height) / (512 * 512) # Увеличение времени от размера
|
27 |
+
step_factor = num_inference_steps / 10 # Увеличение времени от числа шагов
|
28 |
+
return int(base_time * time_factor * step_factor)
|
29 |
+
examples = [
|
30 |
+
"A border collie lying in some Fall leaves as the forest trees change colors",
|
31 |
+
]
|
32 |
+
@spaces.GPU(duration=30) # Устанавливаем 30 секунд
|
33 |
def infer(
|
34 |
prompt,
|
35 |
+
width=512,
|
36 |
+
height=512,
|
37 |
+
num_inference_steps=20, # Оптимальные шаги
|
38 |
+
guidance_scale=7.5,
|
|
|
|
|
|
|
|
|
39 |
):
|
40 |
+
# Оценка необходимого времени
|
41 |
+
duration = calculate_duration(width, height, num_inference_steps)
|
42 |
+
print(f"Запрашиваемая квота: {duration} секунд")
|
43 |
+
# Настраиваем параметры в pipe
|
44 |
+
image = pipe(
|
45 |
+
prompt=prompt,
|
46 |
+
num_inference_steps=num_inference_steps,
|
47 |
+
width=width,
|
48 |
+
height=height,
|
49 |
+
guidance_scale=guidance_scale,
|
50 |
+
).images[0]
|
51 |
+
return image
|
|
|
|
|
|
|
52 |
|
|
|
53 |
|
54 |
except Exception as e:
|
55 |
# Log the exception if needed
|
|
|
61 |
"Please wait a moment and try again."
|
62 |
)
|
63 |
|
64 |
+
|
|
|
|
|
65 |
|
66 |
# Define the custom theme with input styles
|
67 |
class CustomTheme(gr.themes.Base):
|