Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ import gradio as gr
|
|
| 6 |
import spaces
|
| 7 |
import numpy as np
|
| 8 |
import uuid
|
| 9 |
-
from diffusers import PixArtAlphaPipeline, LCMScheduler
|
| 10 |
import torch
|
| 11 |
from typing import Tuple
|
| 12 |
from datetime import datetime
|
|
@@ -78,23 +78,17 @@ STYLE_NAMES = list(styles.keys())
|
|
| 78 |
DEFAULT_STYLE_NAME = "(No style)"
|
| 79 |
NUM_IMAGES_PER_PROMPT = 1
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str, str]:
|
| 82 |
p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
|
| 83 |
if not negative:
|
| 84 |
negative = ""
|
| 85 |
return p.replace("{prompt}", positive), n + negative
|
| 86 |
-
|
| 87 |
-
if torch.cuda.is_available():
|
| 88 |
-
|
| 89 |
-
pipe = PixArtAlphaPipeline.from_pretrained(
|
| 90 |
-
"PixArt-alpha/PixArt-LCM-XL-2-1024-MS",
|
| 91 |
-
torch_dtype=torch.float16,
|
| 92 |
-
use_safetensors=True,
|
| 93 |
-
)
|
| 94 |
-
|
| 95 |
-
pipe.vae = ConsistencyDecoderVAE.from_pretrained("openai/consistency-decoder", torch_dtype=torch.float16)
|
| 96 |
-
|
| 97 |
-
pipe.to(device)
|
| 98 |
|
| 99 |
# speed-up T5
|
| 100 |
pipe.text_encoder.to_bettertransformer()
|
|
@@ -108,8 +102,6 @@ def save_image(img):
|
|
| 108 |
img.save(unique_name)
|
| 109 |
return unique_name
|
| 110 |
|
| 111 |
-
|
| 112 |
-
|
| 113 |
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
| 114 |
if randomize_seed:
|
| 115 |
seed = random.randint(0, MAX_SEED)
|
|
|
|
| 6 |
import spaces
|
| 7 |
import numpy as np
|
| 8 |
import uuid
|
| 9 |
+
from diffusers import PixArtAlphaPipeline, LCMScheduler
|
| 10 |
import torch
|
| 11 |
from typing import Tuple
|
| 12 |
from datetime import datetime
|
|
|
|
| 78 |
DEFAULT_STYLE_NAME = "(No style)"
|
| 79 |
NUM_IMAGES_PER_PROMPT = 1
|
| 80 |
|
| 81 |
+
pipe = PixArtAlphaPipeline.from_pretrained(
|
| 82 |
+
"PixArt-alpha/PixArt-LCM-XL-2-1024-MS",
|
| 83 |
+
torch_dtype=torch.float16,
|
| 84 |
+
use_safetensors=True,
|
| 85 |
+
).to(device)
|
| 86 |
+
|
| 87 |
def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str, str]:
|
| 88 |
p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
|
| 89 |
if not negative:
|
| 90 |
negative = ""
|
| 91 |
return p.replace("{prompt}", positive), n + negative
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
# speed-up T5
|
| 94 |
pipe.text_encoder.to_bettertransformer()
|
|
|
|
| 102 |
img.save(unique_name)
|
| 103 |
return unique_name
|
| 104 |
|
|
|
|
|
|
|
| 105 |
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
| 106 |
if randomize_seed:
|
| 107 |
seed = random.randint(0, MAX_SEED)
|