Spaces:
Paused
Paused
Update app.py
Browse files20 unmodified lines2122232425262730 unmodified lines5859606162636421 unmodified lines8687888990919293949596979828 unmodified lines12712812913013113213313413513613713891 unmodified lines23023123223323423523623723823954 unmodified lines29429529629729829930082 unmodified lines38338438538638738838942 unmodified lines43243343443543643743843944085 unmodified lines52652752852953053153253353453553653753853954054177 unmodified lines61962062162262362462524 unmodified lines65065165265320 unmodified linesfrom style_template import stylesfrom pipeline_stable_diffusion_xl_instantid_full import StableDiffusionXLInstantIDPipeline, draw_kps# from controlnet_aux import OpenposeDetectorimport gradio as gr30 unmodified lines)app.prepare(ctx_id=0, det_size=(640, 640))# 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_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_canny = ControlNetModel.from_pretrained(controlnet_canny_model, torch_dtype=dtype).to(device)28 unmodified linesreturn Image.fromarray(edges, "L")controlnet_map = {# "pose": controlnet_pose,"canny": controlnet_canny,"depth": controlnet_depth,}controlnet_map_fn = {# "pose": openpose,"canny": get_canny_image,"depth": get_depth_map,}91 unmodified lines20, # num_steps0.8, # identitynet_strength_ratio0.8, # adapter_strength_ratio# 0.4, # pose_strength0.3, # canny_strength0.5, # depth_strength["depth", "canny"], # controlnet_selection5.0, # guidance_scale42, # seed"EulerDiscreteScheduler", # scheduler54 unmodified linesnum_steps,identitynet_strength_ratio,adapter_strength_ratio,# pose_strength,canny_strength,depth_strength,controlnet_selection,82 unmodified linesif len(controlnet_selection) > 0:controlnet_scales = {# "pose": pose_strength,"canny": canny_strength,"depth": depth_strength,}42 unmodified linesdescription = 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"],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,# )canny_strength = gr.Slider(label="Canny strength",minimum=0,77 unmodified linesnum_steps,identitynet_strength_ratio,adapter_strength_ratio,# pose_strength,canny_strength,depth_strength,controlnet_selection,24 unmodified linesgr.Markdown(article)demo.queue(api_open=False)demo.launch()20 unmodified lines2122232425262730 unmodified lines5859606162636421 unmodified lines8687888990919293949596979828 unmodified lines12712812913013113213313413513613713891 unmodified lines23023123223323423523623723823954 unmodified lines29429529629729829930082 unmodified lines38338438538638738838942 unmodified lines43243343443543643743885 unmodified lines52452552652752852953053153253353453553653753853977 unmodified lines61761861962062162262324 unmodified lines64864965065120 unmodified linesfrom style_template import stylesfrom pipeline_stable_diffusion_xl_instantid_full import StableDiffusionXLInstantIDPipeline, draw_kpsfrom controlnet_aux import OpenposeDetectorimport gradio as gr30 unmodified lines)app.prepare(ctx_id=0, det_size=(640, 640))openpose = OpenposeDetector.from_pretrained("lllyasviel/ControlNet")depth_anything = DepthAnything.from_pretrained('LiheYoung/depth_anything_vitl14').to(device).eval()21 unmodified lines)# controlnet-pose/canny/depthcontrolnet_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_canny = ControlNetModel.from_pretrained(controlnet_canny_model, torch_dtype=dtype).to(device)28 unmodified linesreturn Image.fromarray(edges, "L")controlnet_map = {"pose": controlnet_pose,"canny": controlnet_canny,"depth": controlnet_depth,}controlnet_map_fn = {"pose": openpose,"canny": get_canny_image,"depth": get_depth_map,}91 unmodified lines20, # num_steps0.8, # identitynet_strength_ratio0.8, # adapter_strength_ratio0.4, # pose_strength0.3, # canny_strength0.5, # depth_strength["pose", "canny"], # controlnet_selection5.0, # guidance_scale42, # seed"EulerDiscreteScheduler", # scheduler54 unmodified linesnum_steps,identitynet_strength_ratio,adapter_strength_ratio,pose_strength,canny_strength,depth_strength,controlnet_selection,82 unmodified linesif len(controlnet_selection) > 0:controlnet_scales = {"pose": pose_strength,"canny": canny_strength,"depth": depth_strength,}42 unmodified linesdescription = 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(["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,)canny_strength = gr.Slider(label="Canny strength",minimum=0,77 unmodified linesnum_steps,identitynet_strength_ratio,adapter_strength_ratio,pose_strength,canny_strength,depth_strength,controlnet_selection,24 unmodified linesgr.Markdown(article)demo.queue(api_open=False)demo.launch()
app.py+22-24