Spaces:
Runtime error
Runtime error
hyper sdxl
Browse files4 unmodified lines5678910111213141516171819202114 unmodified lines363738394041423 unmodified lines4647484950515253545556575859606162162 unmodified lines2252262272282292307 unmodified lines23823924024124224314 unmodified lines25825926026126226326482 unmodified lines34734834935035135235335435535633 unmodified lines3903913923933943954 unmodified linesimport numpy as npfrom pathlib import Pathfrom PIL import Imagefrom diffusers import (ControlNetModel,StableDiffusionXLControlNetPipeline,UNet2DConditionModel,EulerDiscreteScheduler,)import spacesimport gradio as grfrom huggingface_hub import hf_hub_download, snapshot_downloadfrom ip_adapter import IPAdapterXLfrom safetensors.torch import load_filesnapshot_download(repo_id="h94/IP-Adapter", allow_patterns="sdxl_models/*", local_dir="."14 unmodified linescontrolnet_path, use_safetensors=False, torch_dtype=torch.float16).to(device)# load SDXL lightniningpipe = StableDiffusionXLControlNetPipeline.from_pretrained(base_model_path,3 unmodified linesadd_watermarker=False,).to(device)pipe.set_progress_bar_config(disable=True)pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing", prediction_type="epsilon")pipe.unet.load_state_dict(load_file(hf_hub_download("ByteDance/SDXL-Lightning", "sdxl_lightning_2step_unet.safetensors"),device="cuda",))# load ip-adapter# target_blocks=["block"] for original IP-Adapter162 unmodified linescontrolnet_conditioning_scale=float(control_scale),neg_content_prompt=neg_content_prompt,neg_content_scale=neg_content_scale,)else:images = ip_model.generate(7 unmodified linesseed=seed,image=canny_map,controlnet_conditioning_scale=float(control_scale),)image = images[0]with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as tmpfile:14 unmodified linesdescription = r"""<b>Forked from <a href='https://github.com/InstantStyle/InstantStyle' target='_blank'>InstantStyle: Free Lunch towards Style-Preserving in Text-to-Image Generation</a>.<br><b>Model by <a href='https://huggingface.co/ByteDance/SDXL-Lightning' target='_blank'>SDXL Lightning</a> and <a href='https://huggingface.co/h94/IP-Adapter' target='_blank'>IP-Adapter</a>.</b><br>"""article = r"""82 unmodified lineslabel="guidance scale",)num_inference_steps = gr.Slider(minimum=2,maximum=50.0,step=1.0,value=2,label="num inference steps",)seed = gr.Slider(33 unmodified linesscale.input,control_scale.input,seed.input,],fn=create_image,inputs=inputs,4 unmodified lines5678910111213141514 unmodified lines303132333435363 unmodified lines4041424344454647484950162 unmodified lines2132142152162172182197 unmodified lines22722822923023123223314 unmodified lines24824925025125225325482 unmodified lines33733833934034134234334434534633 unmodified lines3803813823833843853863873883894 unmodified linesimport numpy as npfrom pathlib import Pathfrom PIL import Imagefrom diffusers import ControlNetModel, StableDiffusionXLControlNetPipeline, TCDSchedulerimport spacesimport gradio as grfrom huggingface_hub import hf_hub_download, snapshot_downloadfrom ip_adapter import IPAdapterXLsnapshot_download(repo_id="h94/IP-Adapter", allow_patterns="sdxl_models/*", local_dir="."14 unmodified linescontrolnet_path, use_safetensors=False, torch_dtype=torch.float16).to(device)# load Hyper SDpipe = StableDiffusionXLControlNetPipeline.from_pretrained(base_model_path,3 unmodified linesadd_watermarker=False,).to(device)pipe.set_progress_bar_config(disable=True)pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)pipe.load_lora_weights(hf_hub_download("ByteDance/Hyper-SD", "Hyper-SDXL-1step-lora.safetensors"))eta = 1.0# load ip-adapter# target_blocks=["block"] for original IP-Adapter162 unmodified linescontrolnet_conditioning_scale=float(control_scale),neg_content_prompt=neg_content_prompt,neg_content_scale=neg_content_scale,eta=1.0,)else:images = ip_model.generate(7 unmodified linesseed=seed,image=canny_map,controlnet_conditioning_scale=float(control_scale),eta=1.0,)image = images[0]with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as tmpfile:14 unmodified linesdescription = r"""<b>Forked from <a href='https://github.com/InstantStyle/InstantStyle' target='_blank'>InstantStyle: Free Lunch towards Style-Preserving in Text-to-Image Generation</a>.<br><b>Model by <a href='https://huggingface.co/ByteDance/Hyper-SD' target='_blank'>Hyper-SD</a> and <a href='https://huggingface.co/h94/IP-Adapter' target='_blank'>IP-Adapter</a>.</b><br>"""article = r"""82 unmodified lineslabel="guidance scale",)num_inference_steps = gr.Slider(minimum=1,maximum=10.0,step=1.0,value=1,label="num inference steps",)seed = gr.Slider(33 unmodified linesscale.input,control_scale.input,seed.input,num_inference_steps.input,target.input,neg_content_prompt.input,neg_content_scale.input,],fn=create_image,inputs=inputs,
app.py+16-22