Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -17,10 +17,46 @@ else:
|
|
17 |
pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
|
18 |
pipe = pipe.to(device)
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
MAX_SEED = np.iinfo(np.int32).max
|
21 |
MAX_IMAGE_SIZE = 1024
|
22 |
|
23 |
-
@spaces.GPU(duration=
|
24 |
def infer(
|
25 |
prompt,
|
26 |
negative_prompt="",
|
@@ -35,6 +71,10 @@ def infer(
|
|
35 |
if randomize_seed:
|
36 |
seed = random.randint(0, MAX_SEED)
|
37 |
|
|
|
|
|
|
|
|
|
38 |
generator = torch.Generator().manual_seed(seed)
|
39 |
|
40 |
image = pipe(
|
|
|
17 |
pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
|
18 |
pipe = pipe.to(device)
|
19 |
|
20 |
+
def adjust_to_nearest_multiple(value, divisor=8):
|
21 |
+
"""
|
22 |
+
Adjusts the input value to the nearest multiple of the divisor.
|
23 |
+
|
24 |
+
Args:
|
25 |
+
value (int): The value to adjust.
|
26 |
+
divisor (int): The divisor to which the value should be divisible. Default is 8.
|
27 |
+
Returns:
|
28 |
+
int: The nearest multiple of the divisor.
|
29 |
+
"""
|
30 |
+
if value % divisor == 0:
|
31 |
+
return value
|
32 |
+
else:
|
33 |
+
# Round to the nearest multiple of divisor
|
34 |
+
return round(value / divisor) * divisor
|
35 |
+
|
36 |
+
def adjust_dimensions(height, width):
|
37 |
+
"""
|
38 |
+
Adjusts the height and width to be divisible by 8.
|
39 |
+
|
40 |
+
Args:
|
41 |
+
height (int): The height to adjust.
|
42 |
+
width (int): The width to adjust.
|
43 |
+
Returns:
|
44 |
+
tuple: Adjusted height and width.
|
45 |
+
"""
|
46 |
+
new_height = adjust_to_nearest_multiple(height)
|
47 |
+
new_width = adjust_to_nearest_multiple(width)
|
48 |
+
|
49 |
+
return new_height, new_width
|
50 |
+
|
51 |
+
|
52 |
+
# MAX_SEED = np.iinfo(np.int32).max
|
53 |
+
# MAX_IMAGE_SIZE = 4100
|
54 |
+
|
55 |
+
|
56 |
MAX_SEED = np.iinfo(np.int32).max
|
57 |
MAX_IMAGE_SIZE = 1024
|
58 |
|
59 |
+
@spaces.GPU(duration=100)
|
60 |
def infer(
|
61 |
prompt,
|
62 |
negative_prompt="",
|
|
|
71 |
if randomize_seed:
|
72 |
seed = random.randint(0, MAX_SEED)
|
73 |
|
74 |
+
width = min(width, MAX_IMAGE_SIZE // 2)
|
75 |
+
height = min(height, MAX_IMAGE_SIZE // 2)
|
76 |
+
height, width = adjust_dimensions(height, width)
|
77 |
+
|
78 |
generator = torch.Generator().manual_seed(seed)
|
79 |
|
80 |
image = pipe(
|