Spaces:
Paused
Paused
Update app.py
Browse files20 unmodified lines212223242425262730 unmodified lines585960616162636421 unmodified lines868788898990919293949593949596979828 unmodified lines12712812913013013113213313413513513613713891 unmodified lines23023123223323323423523623623723823954 unmodified lines29429529629729729829930082 unmodified lines38338438538638638738838942 unmodified lines43243343443543543743643743885 unmodified lines52452552652952752852953253353453553653753853053153253353453553653753853977 unmodified lines61761861962262062162262324 unmodified lines64864965065365120 unmodified linesfrom style_template import stylesfrom pipeline_stable_diffusion_xl_instantid_full import StableDiffusionXLInstantIDPipeline, draw_kps
# from controlnet_aux import OpenposeDetectorfrom controlnet_aux import OpenposeDetector
import gradio as gr
30 unmodified lines)app.prepare(ctx_id=0, det_size=(640, 640))
# openpose = OpenposeDetector.from_pretrained("lllyasviel/ControlNet")openpose = OpenposeDetector.from_pretrained("lllyasviel/ControlNet")
depth_anything = DepthAnything.from_pretrained('LiheYoung/depth_anything_vitl14').to(device).eval()
21 unmodified lines)
# controlnet-pose/canny/depth# controlnet_pose_model = "thibaud/controlnet-openpose-sdxl-1.0"controlnet_pose_model = "thibaud/controlnet-openpose-sdxl-1.0"controlnet_canny_model = "diffusers/controlnet-canny-sdxl-1.0"controlnet_depth_model = "diffusers/controlnet-depth-sdxl-1.0-small"
# controlnet_pose = ControlNetModel.from_pretrained(# controlnet_pose_model, torch_dtype=dtype# ).to(device)controlnet_pose = ControlNetModel.from_pretrained( controlnet_pose_model, torch_dtype=dtype).to(device)controlnet_canny = ControlNetModel.from_pretrained( controlnet_canny_model, torch_dtype=dtype).to(device)28 unmodified lines return Image.fromarray(edges, "L")
controlnet_map = { # "pose": controlnet_pose, "pose": controlnet_pose, "canny": controlnet_canny, "depth": controlnet_depth,}controlnet_map_fn = { # "pose": openpose, "pose": openpose, "canny": get_canny_image, "depth": get_depth_map,}91 unmodified lines 20, # num_steps 0.8, # identitynet_strength_ratio 0.8, # adapter_strength_ratio # 0.4, # pose_strength 0.4, # pose_strength 0.3, # canny_strength 0.5, # depth_strength ["depth", "canny"], # controlnet_selection ["pose", "canny"], # controlnet_selection 5.0, # guidance_scale 42, # seed "EulerDiscreteScheduler", # scheduler54 unmodified lines num_steps, identitynet_strength_ratio, adapter_strength_ratio, # pose_strength, pose_strength, canny_strength, depth_strength, controlnet_selection,82 unmodified lines
if len(controlnet_selection) > 0: controlnet_scales = { # "pose": pose_strength, "pose": pose_strength, "canny": canny_strength, "depth": depth_strength, }42 unmodified lines
description = r"""<b>Official 🤗 Gradio demo</b> for <a href='https://github.com/InstantID/InstantID' target='_blank'><b>InstantID: Zero-shot Identity-Preserving Generation in Seconds</b></a>.<br>
We are organizing a Spring Festival event with HuggingFace from 2.7 to 2.25, and you can now generate pictures of Spring Festival costumes. Happy Dragon Year 🐲 ! Share the joy with your family.<br>
How to use:<br>1. Upload an image with a face. For images with multiple faces, we will only detect the largest face. Ensure the face is not too small and is clearly visible without significant obstructions or blurring.2. (Optional) You can upload another image as a reference for the face pose. If you don't, we will use the first detected face image to extract facial landmarks. If you use a cropped face at step 1, it is recommended to upload it to define a new face pose.85 unmodified lines ) with gr.Accordion("Controlnet"): controlnet_selection = gr.CheckboxGroup( ["canny", "depth"], label="Controlnet", value=["canny"], ["pose", "canny", "depth"], label="Controlnet", value=["pose"], info="Use pose for skeleton inference, canny for edge detection, and depth for depth map estimation. You can try all three to control the generation process" ) # pose_strength = gr.Slider( # label="Pose strength", # minimum=0, # maximum=1.5, # step=0.05, # value=0.40, # ) pose_strength = gr.Slider( label="Pose strength", minimum=0, maximum=1.5, step=0.05, value=0.40, ) canny_strength = gr.Slider( label="Canny strength", minimum=0,77 unmodified lines num_steps, identitynet_strength_ratio, adapter_strength_ratio, # pose_strength, pose_strength, canny_strength, depth_strength, controlnet_selection,24 unmodified lines gr.Markdown(article)
demo.queue(api_open=False)demo.launch()demo.launch()app.py+22-24