Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -16,13 +16,11 @@ DESCRIPTION = """## Qwen Image Hpc/."""
|
|
16 |
|
17 |
# Helper functions
|
18 |
def save_image(img):
|
19 |
-
"""Saves a PIL image to a file with a unique name."""
|
20 |
unique_name = str(uuid.uuid4()) + ".png"
|
21 |
img.save(unique_name)
|
22 |
return unique_name
|
23 |
|
24 |
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
25 |
-
"""Generates a random seed if the randomize option is enabled."""
|
26 |
if randomize_seed:
|
27 |
seed = random.randint(0, MAX_SEED)
|
28 |
return seed
|
@@ -35,27 +33,15 @@ dtype = torch.bfloat16
|
|
35 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
36 |
|
37 |
# --- Model Loading ---
|
38 |
-
|
39 |
-
pipe_qwen = DiffusionPipeline.from_pretrained(
|
40 |
-
"Qwen/Qwen-Image",
|
41 |
-
torch_dtype=dtype
|
42 |
-
).to(device)
|
43 |
-
|
44 |
-
# --- Regional Compilation ---
|
45 |
-
# Apply regional compilation to speed up cold-starts while retaining benefits.
|
46 |
-
# This compiles the repeated transformer blocks for ~2x faster initialization.
|
47 |
-
print("Applying regional compilation...")
|
48 |
-
pipe_qwen.transformer.compile(fullgraph=True, mode="reduce-overhead")
|
49 |
-
print("Compilation complete.")
|
50 |
-
|
51 |
|
52 |
# Aspect ratios
|
53 |
aspect_ratios = {
|
54 |
-
"1:1": (
|
55 |
-
"16:9": (
|
56 |
-
"9:16": (
|
57 |
-
"4:3": (
|
58 |
-
"3:4": (
|
59 |
}
|
60 |
|
61 |
# Generation function for Qwen/Qwen-Image
|
@@ -292,4 +278,4 @@ with gr.Blocks(css=css, theme="bethecloud/storj_theme") as demo:
|
|
292 |
)
|
293 |
|
294 |
if __name__ == "__main__":
|
295 |
-
demo.queue(max_size=50).launch(share=False)
|
|
|
16 |
|
17 |
# Helper functions
|
18 |
def save_image(img):
|
|
|
19 |
unique_name = str(uuid.uuid4()) + ".png"
|
20 |
img.save(unique_name)
|
21 |
return unique_name
|
22 |
|
23 |
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
|
|
24 |
if randomize_seed:
|
25 |
seed = random.randint(0, MAX_SEED)
|
26 |
return seed
|
|
|
33 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
34 |
|
35 |
# --- Model Loading ---
|
36 |
+
pipe_qwen = DiffusionPipeline.from_pretrained("Qwen/Qwen-Image", torch_dtype=dtype).to(device)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
# Aspect ratios
|
39 |
aspect_ratios = {
|
40 |
+
"1:1": (1328, 1328),
|
41 |
+
"16:9": (1664, 928),
|
42 |
+
"9:16": (928, 1664),
|
43 |
+
"4:3": (1472, 1140),
|
44 |
+
"3:4": (1140, 1472)
|
45 |
}
|
46 |
|
47 |
# Generation function for Qwen/Qwen-Image
|
|
|
278 |
)
|
279 |
|
280 |
if __name__ == "__main__":
|
281 |
+
demo.queue(max_size=50).launch(share=False, mcp_server=True, ssr_mode=False, show_error=True)
|