Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
-
#!/usr/bin/env python
|
2 |
-
|
3 |
import os
|
4 |
import random
|
5 |
import uuid
|
@@ -36,26 +34,23 @@ if torch.cuda.is_available():
|
|
36 |
if ENABLE_CPU_OFFLOAD:
|
37 |
pipe.enable_model_cpu_offload()
|
38 |
else:
|
39 |
-
pipe.to(device)
|
40 |
print("Loaded on Device!")
|
41 |
-
|
42 |
if USE_TORCH_COMPILE:
|
43 |
pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
|
44 |
print("Model Compiled!")
|
45 |
|
46 |
-
|
47 |
def save_image(img):
|
48 |
unique_name = str(uuid.uuid4()) + ".png"
|
49 |
img.save(unique_name)
|
50 |
return unique_name
|
51 |
|
52 |
-
|
53 |
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
54 |
if randomize_seed:
|
55 |
seed = random.randint(0, MAX_SEED)
|
56 |
return seed
|
57 |
|
58 |
-
|
59 |
@spaces.GPU(enable_queue=True)
|
60 |
def generate(
|
61 |
prompt: str,
|
@@ -69,7 +64,6 @@ def generate(
|
|
69 |
use_resolution_binning: bool = True,
|
70 |
progress=gr.Progress(track_tqdm=True),
|
71 |
):
|
72 |
-
pipe = some_function_to_create_pipe()
|
73 |
seed = int(randomize_seed_fn(seed, randomize_seed))
|
74 |
generator = torch.Generator().manual_seed(seed)
|
75 |
|
@@ -93,7 +87,6 @@ def generate(
|
|
93 |
print(image_paths)
|
94 |
return image_paths, seed
|
95 |
|
96 |
-
|
97 |
examples = [
|
98 |
"neon holography crystal cat",
|
99 |
"a cat eating a piece of cheese",
|
@@ -203,4 +196,4 @@ with gr.Blocks(css=css) as demo:
|
|
203 |
)
|
204 |
|
205 |
if __name__ == "__main__":
|
206 |
-
demo.queue(max_size=20).launch()
|
|
|
|
|
|
|
1 |
import os
|
2 |
import random
|
3 |
import uuid
|
|
|
34 |
if ENABLE_CPU_OFFLOAD:
|
35 |
pipe.enable_model_cpu_offload()
|
36 |
else:
|
37 |
+
pipe.to(device)
|
38 |
print("Loaded on Device!")
|
39 |
+
|
40 |
if USE_TORCH_COMPILE:
|
41 |
pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
|
42 |
print("Model Compiled!")
|
43 |
|
|
|
44 |
def save_image(img):
|
45 |
unique_name = str(uuid.uuid4()) + ".png"
|
46 |
img.save(unique_name)
|
47 |
return unique_name
|
48 |
|
|
|
49 |
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
50 |
if randomize_seed:
|
51 |
seed = random.randint(0, MAX_SEED)
|
52 |
return seed
|
53 |
|
|
|
54 |
@spaces.GPU(enable_queue=True)
|
55 |
def generate(
|
56 |
prompt: str,
|
|
|
64 |
use_resolution_binning: bool = True,
|
65 |
progress=gr.Progress(track_tqdm=True),
|
66 |
):
|
|
|
67 |
seed = int(randomize_seed_fn(seed, randomize_seed))
|
68 |
generator = torch.Generator().manual_seed(seed)
|
69 |
|
|
|
87 |
print(image_paths)
|
88 |
return image_paths, seed
|
89 |
|
|
|
90 |
examples = [
|
91 |
"neon holography crystal cat",
|
92 |
"a cat eating a piece of cheese",
|
|
|
196 |
)
|
197 |
|
198 |
if __name__ == "__main__":
|
199 |
+
demo.queue(max_size=20).launch()
|