Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -259,8 +259,7 @@ def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
|
| 259 |
@spaces.GPU
|
| 260 |
def infer(
|
| 261 |
prompt: str,
|
| 262 |
-
negative_prompt: str = "
|
| 263 |
-
use_negative_prompt: bool = True,
|
| 264 |
seed: int = 7,
|
| 265 |
width: int = 1024,
|
| 266 |
height: int = 1536,
|
|
@@ -280,12 +279,12 @@ def infer(
|
|
| 280 |
requires_pooled=[False, True],
|
| 281 |
truncate_long_prompts=False
|
| 282 |
)
|
| 283 |
-
# 在 infer 函数中调用 get_embed_new
|
| 284 |
-
if not use_negative_prompt:
|
| 285 |
-
negative_prompt = ""
|
| 286 |
|
| 287 |
original_prompt = prompt # Store original prompt for metadata
|
|
|
|
| 288 |
prompt = get_embed_new(prompt, pipe, compel, only_convert_string=True)
|
|
|
|
|
|
|
| 289 |
negative_prompt = get_embed_new(negative_prompt, pipe, compel, only_convert_string=True)
|
| 290 |
conditioning, pooled = compel([prompt, negative_prompt]) # 必须同时处理来保证长度相等
|
| 291 |
|
|
@@ -322,21 +321,7 @@ def infer(
|
|
| 322 |
|
| 323 |
return image_with_metadata, seed
|
| 324 |
|
| 325 |
-
|
| 326 |
-
"nahida (genshin impact)",
|
| 327 |
-
"klee (genshin impact)",
|
| 328 |
-
]
|
| 329 |
-
|
| 330 |
-
css = '''
|
| 331 |
-
.gradio-container {
|
| 332 |
-
max-width: 560px !important;
|
| 333 |
-
margin-left: auto !important;
|
| 334 |
-
margin-right: auto !important;
|
| 335 |
-
}
|
| 336 |
-
h1{text-align:center}
|
| 337 |
-
'''
|
| 338 |
-
|
| 339 |
-
with gr.Blocks(css=css) as demo:
|
| 340 |
with gr.Group():
|
| 341 |
with gr.Row():
|
| 342 |
prompt = gr.Text(
|
|
@@ -347,16 +332,14 @@ with gr.Blocks(css=css) as demo:
|
|
| 347 |
container=False,
|
| 348 |
)
|
| 349 |
run_button = gr.Button("生成", scale=0, variant="primary")
|
| 350 |
-
result = gr.Image(label="Result", show_label=False, format="png")
|
| 351 |
-
with gr.Accordion("高级选项", open=False):
|
| 352 |
with gr.Row():
|
| 353 |
-
use_negative_prompt = gr.Checkbox(label="使用反向词条", value=True)
|
| 354 |
negative_prompt = gr.Text(
|
| 355 |
label="反向词条",
|
| 356 |
max_lines=5,
|
| 357 |
lines=4,
|
| 358 |
placeholder="输入你要排除的图片关键词",
|
| 359 |
-
value="
|
| 360 |
visible=True,
|
| 361 |
)
|
| 362 |
seed = gr.Slider(
|
|
@@ -373,14 +356,14 @@ with gr.Blocks(css=css) as demo:
|
|
| 373 |
minimum=512,
|
| 374 |
maximum=MAX_IMAGE_SIZE,
|
| 375 |
step=64,
|
| 376 |
-
value=
|
| 377 |
)
|
| 378 |
height = gr.Slider(
|
| 379 |
label="高度",
|
| 380 |
minimum=512,
|
| 381 |
maximum=MAX_IMAGE_SIZE,
|
| 382 |
step=64,
|
| 383 |
-
value=
|
| 384 |
)
|
| 385 |
with gr.Row():
|
| 386 |
guidance_scale = gr.Slider(
|
|
@@ -395,29 +378,15 @@ with gr.Blocks(css=css) as demo:
|
|
| 395 |
minimum=1,
|
| 396 |
maximum=50,
|
| 397 |
step=1,
|
| 398 |
-
value=
|
| 399 |
)
|
| 400 |
|
| 401 |
-
gr.Examples(
|
| 402 |
-
examples=examples,
|
| 403 |
-
inputs=prompt,
|
| 404 |
-
outputs=[result, seed],
|
| 405 |
-
fn=infer
|
| 406 |
-
)
|
| 407 |
-
|
| 408 |
-
use_negative_prompt.change(
|
| 409 |
-
fn=lambda x: gr.update(visible=x),
|
| 410 |
-
inputs=use_negative_prompt,
|
| 411 |
-
outputs=negative_prompt,
|
| 412 |
-
)
|
| 413 |
-
|
| 414 |
gr.on(
|
| 415 |
triggers=[prompt.submit, run_button.click],
|
| 416 |
fn=infer,
|
| 417 |
inputs=[
|
| 418 |
prompt,
|
| 419 |
negative_prompt,
|
| 420 |
-
use_negative_prompt,
|
| 421 |
seed,
|
| 422 |
width,
|
| 423 |
height,
|
|
|
|
| 259 |
@spaces.GPU
|
| 260 |
def infer(
|
| 261 |
prompt: str,
|
| 262 |
+
negative_prompt: str = "",
|
|
|
|
| 263 |
seed: int = 7,
|
| 264 |
width: int = 1024,
|
| 265 |
height: int = 1536,
|
|
|
|
| 279 |
requires_pooled=[False, True],
|
| 280 |
truncate_long_prompts=False
|
| 281 |
)
|
|
|
|
|
|
|
|
|
|
| 282 |
|
| 283 |
original_prompt = prompt # Store original prompt for metadata
|
| 284 |
+
prompt = f"masterpiece, best quality, amazing quality, very aesthetic, absurdres, newest, volumetric lighting, dramatic lighting,{prompt},"
|
| 285 |
prompt = get_embed_new(prompt, pipe, compel, only_convert_string=True)
|
| 286 |
+
|
| 287 |
+
negative_prompt = f"{negative_prompt},lowres, bad quality, worst quality, bad anatomy, sketch, jpeg artifacts, ugly, poorly drawn, (signature, watermark, username, logo, web address, twitter_username, patreon_username, character_name, copyright_name), (censored, mosaic_censoring, convenient_censoring, bar_censor, heart_censor), blurry, simple background, transparent background,"
|
| 288 |
negative_prompt = get_embed_new(negative_prompt, pipe, compel, only_convert_string=True)
|
| 289 |
conditioning, pooled = compel([prompt, negative_prompt]) # 必须同时处理来保证长度相等
|
| 290 |
|
|
|
|
| 321 |
|
| 322 |
return image_with_metadata, seed
|
| 323 |
|
| 324 |
+
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 325 |
with gr.Group():
|
| 326 |
with gr.Row():
|
| 327 |
prompt = gr.Text(
|
|
|
|
| 332 |
container=False,
|
| 333 |
)
|
| 334 |
run_button = gr.Button("生成", scale=0, variant="primary")
|
| 335 |
+
result = gr.Image(label="Result", show_label=False, format="png")
|
|
|
|
| 336 |
with gr.Row():
|
|
|
|
| 337 |
negative_prompt = gr.Text(
|
| 338 |
label="反向词条",
|
| 339 |
max_lines=5,
|
| 340 |
lines=4,
|
| 341 |
placeholder="输入你要排除的图片关键词",
|
| 342 |
+
value="",
|
| 343 |
visible=True,
|
| 344 |
)
|
| 345 |
seed = gr.Slider(
|
|
|
|
| 356 |
minimum=512,
|
| 357 |
maximum=MAX_IMAGE_SIZE,
|
| 358 |
step=64,
|
| 359 |
+
value=1152,
|
| 360 |
)
|
| 361 |
height = gr.Slider(
|
| 362 |
label="高度",
|
| 363 |
minimum=512,
|
| 364 |
maximum=MAX_IMAGE_SIZE,
|
| 365 |
step=64,
|
| 366 |
+
value=1728,
|
| 367 |
)
|
| 368 |
with gr.Row():
|
| 369 |
guidance_scale = gr.Slider(
|
|
|
|
| 378 |
minimum=1,
|
| 379 |
maximum=50,
|
| 380 |
step=1,
|
| 381 |
+
value=25,
|
| 382 |
)
|
| 383 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 384 |
gr.on(
|
| 385 |
triggers=[prompt.submit, run_button.click],
|
| 386 |
fn=infer,
|
| 387 |
inputs=[
|
| 388 |
prompt,
|
| 389 |
negative_prompt,
|
|
|
|
| 390 |
seed,
|
| 391 |
width,
|
| 392 |
height,
|