Update app.py
Browse files
app.py
CHANGED
|
@@ -11,7 +11,6 @@ MODEL_FILE = "CyberRealisticPony_V16.0_FP16.safetensors"
|
|
| 11 |
PONY_POS = "score_9, score_8_up, score_7_up, "
|
| 12 |
PONY_NEG = "score_6, score_5, score_4, "
|
| 13 |
|
| 14 |
-
# ββ Load model on CPU at startup, ZeroGPU moves it to GPU per request βββββββββ
|
| 15 |
print("Downloading model...")
|
| 16 |
local_path = hf_hub_download(repo_id=MODEL_REPO, filename=MODEL_FILE)
|
| 17 |
print("Loading pipeline...")
|
|
@@ -27,7 +26,7 @@ pipe.scheduler = DPMSolverMultistepScheduler.from_config(
|
|
| 27 |
pipe.enable_attention_slicing()
|
| 28 |
print("Pipeline ready.")
|
| 29 |
|
| 30 |
-
# ββ Generation
|
| 31 |
@spaces.GPU(duration=120)
|
| 32 |
def generate(prompt, negative_prompt, width, height, steps, guidance, seed, randomize):
|
| 33 |
if not prompt.strip():
|
|
@@ -36,7 +35,8 @@ def generate(prompt, negative_prompt, width, height, steps, guidance, seed, rand
|
|
| 36 |
seed = random.randint(0, 2**32 - 1)
|
| 37 |
seed = int(seed)
|
| 38 |
|
| 39 |
-
generator
|
|
|
|
| 40 |
|
| 41 |
result = pipe(
|
| 42 |
prompt=PONY_POS + prompt.strip(),
|
|
@@ -61,7 +61,6 @@ body, .gradio-container {
|
|
| 61 |
margin: 0 auto !important;
|
| 62 |
}
|
| 63 |
|
| 64 |
-
/* Header */
|
| 65 |
.site-header {
|
| 66 |
background: linear-gradient(160deg, #12001a, #1e0033, #0d001a);
|
| 67 |
border: 1px solid #6f00ff44;
|
|
@@ -109,7 +108,6 @@ body, .gradio-container {
|
|
| 109 |
position: relative;
|
| 110 |
}
|
| 111 |
|
| 112 |
-
/* Output area */
|
| 113 |
.output-wrap {
|
| 114 |
background: #0f0f1a;
|
| 115 |
border: 1px solid #1e1e35;
|
|
@@ -126,7 +124,6 @@ body, .gradio-container {
|
|
| 126 |
border-radius: 18px;
|
| 127 |
}
|
| 128 |
|
| 129 |
-
/* Seed display */
|
| 130 |
.seed-display input {
|
| 131 |
background: #0f0f1a !important;
|
| 132 |
border: 1px solid #1e1e35 !important;
|
|
@@ -137,7 +134,6 @@ body, .gradio-container {
|
|
| 137 |
padding: 8px !important;
|
| 138 |
}
|
| 139 |
|
| 140 |
-
/* Section headers */
|
| 141 |
.sec-head {
|
| 142 |
color: #7733cc;
|
| 143 |
font-size: 0.7em;
|
|
@@ -157,7 +153,6 @@ body, .gradio-container {
|
|
| 157 |
background: linear-gradient(90deg, #331155, transparent);
|
| 158 |
}
|
| 159 |
|
| 160 |
-
/* Textareas */
|
| 161 |
textarea {
|
| 162 |
background: #0f0f1a !important;
|
| 163 |
border: 1px solid #221133 !important;
|
|
@@ -173,15 +168,9 @@ textarea:focus {
|
|
| 173 |
box-shadow: 0 0 0 3px #7733cc22 !important;
|
| 174 |
outline: none !important;
|
| 175 |
}
|
| 176 |
-
textarea::placeholder {
|
| 177 |
-
color: #443355 !important;
|
| 178 |
-
}
|
| 179 |
|
| 180 |
-
|
| 181 |
-
input[type=range] {
|
| 182 |
-
accent-color: #7733cc !important;
|
| 183 |
-
height: 4px;
|
| 184 |
-
}
|
| 185 |
.gradio-slider {
|
| 186 |
background: #0f0f1a !important;
|
| 187 |
border: 1px solid #1e1e35 !important;
|
|
@@ -197,7 +186,6 @@ input[type=range] {
|
|
| 197 |
letter-spacing: 1px !important;
|
| 198 |
}
|
| 199 |
|
| 200 |
-
/* Number inputs */
|
| 201 |
input[type=number] {
|
| 202 |
background: #0f0f1a !important;
|
| 203 |
border: 1px solid #221133 !important;
|
|
@@ -207,7 +195,6 @@ input[type=number] {
|
|
| 207 |
padding: 10px !important;
|
| 208 |
}
|
| 209 |
|
| 210 |
-
/* Checkbox */
|
| 211 |
.gradio-checkbox {
|
| 212 |
background: #0f0f1a !important;
|
| 213 |
border: 1px solid #1e1e35 !important;
|
|
@@ -225,7 +212,6 @@ input[type=checkbox] {
|
|
| 225 |
font-weight: 600 !important;
|
| 226 |
}
|
| 227 |
|
| 228 |
-
/* Labels */
|
| 229 |
label span {
|
| 230 |
color: #8855bb !important;
|
| 231 |
font-size: 0.78em !important;
|
|
@@ -234,7 +220,6 @@ label span {
|
|
| 234 |
letter-spacing: 1px !important;
|
| 235 |
}
|
| 236 |
|
| 237 |
-
/* Generate button */
|
| 238 |
button.lg.primary {
|
| 239 |
background: linear-gradient(135deg, #7733cc 0%, #5500aa 50%, #3d007a 100%) !important;
|
| 240 |
border: 1px solid #9944ee !important;
|
|
@@ -259,7 +244,6 @@ button.lg.primary:active {
|
|
| 259 |
box-shadow: 0 2px 12px #7733cc44 !important;
|
| 260 |
}
|
| 261 |
|
| 262 |
-
/* Hide gradio footer */
|
| 263 |
footer { display: none !important; }
|
| 264 |
.built-with { display: none !important; }
|
| 265 |
"""
|
|
@@ -275,7 +259,6 @@ with gr.Blocks(css=css, title="CyberRealistic Pony") as demo:
|
|
| 275 |
</div>
|
| 276 |
""")
|
| 277 |
|
| 278 |
-
# Output β top of page so it's the first thing you see on mobile
|
| 279 |
with gr.Group(elem_classes="output-wrap"):
|
| 280 |
output_image = gr.Image(
|
| 281 |
show_label=False,
|
|
@@ -284,12 +267,11 @@ with gr.Blocks(css=css, title="CyberRealistic Pony") as demo:
|
|
| 284 |
)
|
| 285 |
|
| 286 |
used_seed = gr.Number(
|
| 287 |
-
label="Seed used β note this
|
| 288 |
interactive=False,
|
| 289 |
elem_classes="seed-display",
|
| 290 |
)
|
| 291 |
|
| 292 |
-
# Prompt
|
| 293 |
gr.HTML('<div class="sec-head">βοΈ Prompt</div>')
|
| 294 |
prompt = gr.Textbox(
|
| 295 |
show_label=False,
|
|
@@ -309,18 +291,15 @@ with gr.Blocks(css=css, title="CyberRealistic Pony") as demo:
|
|
| 309 |
lines=2,
|
| 310 |
)
|
| 311 |
|
| 312 |
-
# Size
|
| 313 |
gr.HTML('<div class="sec-head">π Size</div>')
|
| 314 |
with gr.Row():
|
| 315 |
-
width = gr.Slider(512, 896, value=832,
|
| 316 |
-
height = gr.Slider(512, 1152, value=
|
| 317 |
|
| 318 |
-
# Sampling
|
| 319 |
gr.HTML('<div class="sec-head">βοΈ Sampling</div>')
|
| 320 |
-
steps = gr.Slider(20, 60,
|
| 321 |
guidance = gr.Slider(1.0, 12.0, value=5.0, step=0.5, label="CFG Scale")
|
| 322 |
|
| 323 |
-
# Seed
|
| 324 |
gr.HTML('<div class="sec-head">π² Seed</div>')
|
| 325 |
with gr.Row():
|
| 326 |
seed = gr.Number(label="Seed", value=42, precision=0, minimum=0, maximum=2**32-1, scale=3)
|
|
|
|
| 11 |
PONY_POS = "score_9, score_8_up, score_7_up, "
|
| 12 |
PONY_NEG = "score_6, score_5, score_4, "
|
| 13 |
|
|
|
|
| 14 |
print("Downloading model...")
|
| 15 |
local_path = hf_hub_download(repo_id=MODEL_REPO, filename=MODEL_FILE)
|
| 16 |
print("Loading pipeline...")
|
|
|
|
| 26 |
pipe.enable_attention_slicing()
|
| 27 |
print("Pipeline ready.")
|
| 28 |
|
| 29 |
+
# ββ Generation ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 30 |
@spaces.GPU(duration=120)
|
| 31 |
def generate(prompt, negative_prompt, width, height, steps, guidance, seed, randomize):
|
| 32 |
if not prompt.strip():
|
|
|
|
| 35 |
seed = random.randint(0, 2**32 - 1)
|
| 36 |
seed = int(seed)
|
| 37 |
|
| 38 |
+
# CPU generator works correctly with ZeroGPU β do not hardcode "cuda"
|
| 39 |
+
generator = torch.Generator(device="cpu").manual_seed(seed)
|
| 40 |
|
| 41 |
result = pipe(
|
| 42 |
prompt=PONY_POS + prompt.strip(),
|
|
|
|
| 61 |
margin: 0 auto !important;
|
| 62 |
}
|
| 63 |
|
|
|
|
| 64 |
.site-header {
|
| 65 |
background: linear-gradient(160deg, #12001a, #1e0033, #0d001a);
|
| 66 |
border: 1px solid #6f00ff44;
|
|
|
|
| 108 |
position: relative;
|
| 109 |
}
|
| 110 |
|
|
|
|
| 111 |
.output-wrap {
|
| 112 |
background: #0f0f1a;
|
| 113 |
border: 1px solid #1e1e35;
|
|
|
|
| 124 |
border-radius: 18px;
|
| 125 |
}
|
| 126 |
|
|
|
|
| 127 |
.seed-display input {
|
| 128 |
background: #0f0f1a !important;
|
| 129 |
border: 1px solid #1e1e35 !important;
|
|
|
|
| 134 |
padding: 8px !important;
|
| 135 |
}
|
| 136 |
|
|
|
|
| 137 |
.sec-head {
|
| 138 |
color: #7733cc;
|
| 139 |
font-size: 0.7em;
|
|
|
|
| 153 |
background: linear-gradient(90deg, #331155, transparent);
|
| 154 |
}
|
| 155 |
|
|
|
|
| 156 |
textarea {
|
| 157 |
background: #0f0f1a !important;
|
| 158 |
border: 1px solid #221133 !important;
|
|
|
|
| 168 |
box-shadow: 0 0 0 3px #7733cc22 !important;
|
| 169 |
outline: none !important;
|
| 170 |
}
|
| 171 |
+
textarea::placeholder { color: #443355 !important; }
|
|
|
|
|
|
|
| 172 |
|
| 173 |
+
input[type=range] { accent-color: #7733cc !important; }
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
.gradio-slider {
|
| 175 |
background: #0f0f1a !important;
|
| 176 |
border: 1px solid #1e1e35 !important;
|
|
|
|
| 186 |
letter-spacing: 1px !important;
|
| 187 |
}
|
| 188 |
|
|
|
|
| 189 |
input[type=number] {
|
| 190 |
background: #0f0f1a !important;
|
| 191 |
border: 1px solid #221133 !important;
|
|
|
|
| 195 |
padding: 10px !important;
|
| 196 |
}
|
| 197 |
|
|
|
|
| 198 |
.gradio-checkbox {
|
| 199 |
background: #0f0f1a !important;
|
| 200 |
border: 1px solid #1e1e35 !important;
|
|
|
|
| 212 |
font-weight: 600 !important;
|
| 213 |
}
|
| 214 |
|
|
|
|
| 215 |
label span {
|
| 216 |
color: #8855bb !important;
|
| 217 |
font-size: 0.78em !important;
|
|
|
|
| 220 |
letter-spacing: 1px !important;
|
| 221 |
}
|
| 222 |
|
|
|
|
| 223 |
button.lg.primary {
|
| 224 |
background: linear-gradient(135deg, #7733cc 0%, #5500aa 50%, #3d007a 100%) !important;
|
| 225 |
border: 1px solid #9944ee !important;
|
|
|
|
| 244 |
box-shadow: 0 2px 12px #7733cc44 !important;
|
| 245 |
}
|
| 246 |
|
|
|
|
| 247 |
footer { display: none !important; }
|
| 248 |
.built-with { display: none !important; }
|
| 249 |
"""
|
|
|
|
| 259 |
</div>
|
| 260 |
""")
|
| 261 |
|
|
|
|
| 262 |
with gr.Group(elem_classes="output-wrap"):
|
| 263 |
output_image = gr.Image(
|
| 264 |
show_label=False,
|
|
|
|
| 267 |
)
|
| 268 |
|
| 269 |
used_seed = gr.Number(
|
| 270 |
+
label="Seed used β note this to recreate",
|
| 271 |
interactive=False,
|
| 272 |
elem_classes="seed-display",
|
| 273 |
)
|
| 274 |
|
|
|
|
| 275 |
gr.HTML('<div class="sec-head">βοΈ Prompt</div>')
|
| 276 |
prompt = gr.Textbox(
|
| 277 |
show_label=False,
|
|
|
|
| 291 |
lines=2,
|
| 292 |
)
|
| 293 |
|
|
|
|
| 294 |
gr.HTML('<div class="sec-head">π Size</div>')
|
| 295 |
with gr.Row():
|
| 296 |
+
width = gr.Slider(512, 896, value=832, step=64, label="Width")
|
| 297 |
+
height = gr.Slider(512, 1152, value=1024, step=64, label="Height")
|
| 298 |
|
|
|
|
| 299 |
gr.HTML('<div class="sec-head">βοΈ Sampling</div>')
|
| 300 |
+
steps = gr.Slider(20, 60, value=30, step=1, label="Steps")
|
| 301 |
guidance = gr.Slider(1.0, 12.0, value=5.0, step=0.5, label="CFG Scale")
|
| 302 |
|
|
|
|
| 303 |
gr.HTML('<div class="sec-head">π² Seed</div>')
|
| 304 |
with gr.Row():
|
| 305 |
seed = gr.Number(label="Seed", value=42, precision=0, minimum=0, maximum=2**32-1, scale=3)
|