Spaces:
Configuration error
Configuration error
定义API接口
Browse files
app.py
CHANGED
|
@@ -319,113 +319,113 @@ def generate_image(
|
|
| 319 |
# .gradio-container {width: 85% !important}
|
| 320 |
# """
|
| 321 |
with gr.Blocks(css=css) as demo:
|
| 322 |
-
#
|
| 323 |
-
#
|
| 324 |
-
#
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
#
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
#
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
#
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
#
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
|
| 430 |
# gr.Examples(
|
| 431 |
# examples=get_example(),
|
|
|
|
| 319 |
# .gradio-container {width: 85% !important}
|
| 320 |
# """
|
| 321 |
with gr.Blocks(css=css) as demo:
|
| 322 |
+
# description
|
| 323 |
+
# gr.Markdown(title)
|
| 324 |
+
# gr.Markdown(description)
|
| 325 |
+
|
| 326 |
+
with gr.Row():
|
| 327 |
+
with gr.Column():
|
| 328 |
+
# upload face image
|
| 329 |
+
face_file = gr.Image(label="Upload a photo of your face", type="filepath")
|
| 330 |
+
|
| 331 |
+
# optional: upload a reference pose image
|
| 332 |
+
pose_file = gr.Image(label="Upload a reference pose image (optional)", type="filepath")
|
| 333 |
+
|
| 334 |
+
# prompt
|
| 335 |
+
prompt = gr.Textbox(
|
| 336 |
+
label="Prompt",
|
| 337 |
+
info="Give simple prompt is enough to achieve good face fedility",
|
| 338 |
+
placeholder="A photo of a person",
|
| 339 |
+
value="",
|
| 340 |
+
)
|
| 341 |
+
|
| 342 |
+
submit = gr.Button("Submit", variant="primary")
|
| 343 |
+
|
| 344 |
+
style = gr.Dropdown(label="Style template", choices=STYLE_NAMES, value=DEFAULT_STYLE_NAME)
|
| 345 |
+
|
| 346 |
+
# strength
|
| 347 |
+
identitynet_strength_ratio = gr.Slider(
|
| 348 |
+
label="IdentityNet strength (for fedility)",
|
| 349 |
+
minimum=0,
|
| 350 |
+
maximum=1.5,
|
| 351 |
+
step=0.05,
|
| 352 |
+
value=0.80,
|
| 353 |
+
)
|
| 354 |
+
adapter_strength_ratio = gr.Slider(
|
| 355 |
+
label="Image adapter strength (for detail)",
|
| 356 |
+
minimum=0,
|
| 357 |
+
maximum=1.5,
|
| 358 |
+
step=0.05,
|
| 359 |
+
value=0.80,
|
| 360 |
+
)
|
| 361 |
+
|
| 362 |
+
with gr.Accordion(open=False, label="Advanced Options"):
|
| 363 |
+
negative_prompt = gr.Textbox(
|
| 364 |
+
label="Negative Prompt",
|
| 365 |
+
placeholder="low quality",
|
| 366 |
+
value="(lowres, low quality, worst quality:1.2), (text:1.2), watermark, (frame:1.2), deformed, ugly, deformed eyes, blur, out of focus, blurry, deformed cat, deformed, nudity,naked, bikini, skimpy, scanty, bare skin, lingerie, swimsuit, exposed, see-through, photo, anthropomorphic cat, monochrome, pet collar, gun, weapon, blue, 3d, drones, drone, buildings in background, green",
|
| 367 |
+
)
|
| 368 |
+
num_steps = gr.Slider(
|
| 369 |
+
label="Number of sample steps",
|
| 370 |
+
minimum=20,
|
| 371 |
+
maximum=100,
|
| 372 |
+
step=1,
|
| 373 |
+
value=30,
|
| 374 |
+
)
|
| 375 |
+
guidance_scale = gr.Slider(
|
| 376 |
+
label="Guidance scale",
|
| 377 |
+
minimum=0.1,
|
| 378 |
+
maximum=10.0,
|
| 379 |
+
step=0.1,
|
| 380 |
+
value=5,
|
| 381 |
+
)
|
| 382 |
+
seed = gr.Slider(
|
| 383 |
+
label="Seed",
|
| 384 |
+
minimum=0,
|
| 385 |
+
maximum=MAX_SEED,
|
| 386 |
+
step=1,
|
| 387 |
+
value=42,
|
| 388 |
+
)
|
| 389 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 390 |
+
enhance_face_region = gr.Checkbox(label="Enhance non-face region", value=True)
|
| 391 |
+
|
| 392 |
+
with gr.Column():
|
| 393 |
+
output_image = gr.Image(label="Generated Image")
|
| 394 |
+
usage_tips = gr.Markdown(label="Usage tips of InstantID", value=tips, visible=False)
|
| 395 |
+
|
| 396 |
+
submit.click(
|
| 397 |
+
fn=remove_tips,
|
| 398 |
+
outputs=usage_tips,
|
| 399 |
+
queue=False,
|
| 400 |
+
api_name=False,
|
| 401 |
+
).then(
|
| 402 |
+
fn=randomize_seed_fn,
|
| 403 |
+
inputs=[seed, randomize_seed],
|
| 404 |
+
outputs=seed,
|
| 405 |
+
queue=False,
|
| 406 |
+
api_name=False,
|
| 407 |
+
).then(
|
| 408 |
+
fn=check_input_image,
|
| 409 |
+
inputs=face_file,
|
| 410 |
+
queue=False,
|
| 411 |
+
api_name=False,
|
| 412 |
+
).success(
|
| 413 |
+
fn=generate_image,
|
| 414 |
+
inputs=[
|
| 415 |
+
face_file,
|
| 416 |
+
pose_file,
|
| 417 |
+
prompt,
|
| 418 |
+
negative_prompt,
|
| 419 |
+
style,
|
| 420 |
+
enhance_face_region,
|
| 421 |
+
num_steps,
|
| 422 |
+
identitynet_strength_ratio,
|
| 423 |
+
adapter_strength_ratio,
|
| 424 |
+
guidance_scale,
|
| 425 |
+
seed,
|
| 426 |
+
],
|
| 427 |
+
outputs=[output_image, usage_tips],
|
| 428 |
+
)
|
| 429 |
|
| 430 |
# gr.Examples(
|
| 431 |
# examples=get_example(),
|