Spaces:
Runtime error
Runtime error
Update app.py
Browse files151 unmodified lines152153154155156157158159160161388 unmodified lines5505515525535545553 unmodified lines55956056156256356456556656756856957057157224 unmodified lines59759859960060160260366 unmodified lines670671672673674675676677678679680369 unmodified lines105010511052105310541055105610571058105910601061106210631064106510661067106810697 unmodified lines107710781079108010811082108310841085126 unmodified lines121212131214121512161217121812191220122112221223122412251226151 unmodified lines# - **Download SD 1.5 Models**download_model = "https://huggingface.co/frankjoshua/toonyou_beta6/resolve/main/toonyou_beta6.safetensors"# - **Download VAEs**download_vae = "https://huggingface.co/fp16-guy/anything_kl-f8-anime2_vae-ft-mse-840000-ema-pruned_blessed_clearvae_fp16_cleaned/resolve/main/anything_fp16.safetensors"# - **Download LoRAs**download_lora = "https://civitai.com/api/download/models/97655, https://civitai.com/api/download/models/124358"load_diffusers_format_model = ['stabilityai/stable-diffusion-xl-base-1.0', 'runwayml/stable-diffusion-v1-5']CIVITAI_API_KEY = ""hf_token = ""388 unmodified lines#gallery { flex-grow: 1; }"""with gr.Blocks(theme="NoCrypt/miku", css=CSS) as app:gr.Markdown("# 🧩 DiffuseCraft")gr.Markdown(3 unmodified lines)with gr.Tab("Generation"):with gr.Row():with gr.Column(scale=2):task_gui = gr.Dropdown(label="Task", choices=task_model_list, value=task_model_list[0])model_name_gui = gr.Dropdown(label="Model", choices=model_list, value=model_list[0], allow_custom_value=True)prompt_gui = gr.Textbox(lines=5, placeholder="Enter prompt", label="Prompt")neg_prompt_gui = gr.Textbox(lines=3, placeholder="Enter Neg prompt", label="Negative prompt")generate_button = gr.Button(value="GENERATE", variant="primary")result_images = gr.Gallery(label="Generated images",show_label=False,24 unmodified lineswith gr.Accordion("ControlNet / Img2img / Inpaint", open=False, visible=True):image_control = gr.Image(label="Image ControlNet/Inpaint/Img2img", type="filepath")image_mask_gui = gr.Image(label="Image Mask", type="filepath")strength_gui = gr.Slider(minimum=0.01, maximum=1.0, step=0.01, value=0.35, label="Strength")image_resolution_gui = gr.Slider(minimum=64, maximum=2048, step=64, value=1024, label="Image Resolution")preprocessor_name_gui = gr.Dropdown(label="Preprocessor Name", choices=preprocessor_controlnet["canny"])66 unmodified lineswith gr.Accordion("Textual inversion", open=False, visible=False):active_textual_inversion_gui = gr.Checkbox(value=False, label="Active Textual Inversion in prompt")with gr.Accordion("Hires fix", open=False, visible=True):upscaler_keys = list(upscaler_dict_gui.keys())upscaler_model_path_gui = gr.Dropdown(label="Upscaler", choices=upscaler_keys, value=upscaler_keys[0])upscaler_increases_size_gui = gr.Slider(minimum=1.1, maximum=6., step=0.1, value=1.5, label="Upscale by")esrgan_tile_gui = gr.Slider(minimum=0, value=100, maximum=500, step=1, label="ESRGAN Tile")369 unmodified linesoutputs=[result_images],cache_examples=False,)with gr.Tab("Inpaint mask maker", render=True):def create_mask_now(img, invert):import numpy as npimport timetime.sleep(0.5)transparent_image = img["layers"][0]# Extract the alpha channelalpha_channel = np.array(transparent_image)[:, :, 3]# Create a binary mask by thresholding the alpha channelbinary_mask = alpha_channel > 17 unmodified lines# Convert the mask to uint8rgb_mask = rgb_mask.astype(np.uint8) * 255return img["background"], rgb_maskwith gr.Row():with gr.Column(scale=2):# image_base = gr.ImageEditor(label="Base image", show_label=True, brush=gr.Brush(colors=["#000000"]))126 unmodified linesqueue=True,)app.queue() # default_concurrency_limit=40app.launch(# max_threads=40,# share=False,show_error=True,# quiet=False,debug=True,# allowed_paths=["./assets/"],)151 unmodified lines152153154155156157158159160161162163164165166167168169170171172173174175176388 unmodified lines5655665675685695705715725735745755765775785795805815825835845855865875885893 unmodified lines59359459559659759859960060160260360460560660760860961061161261324 unmodified lines63863964064164264364464564664766 unmodified lines714715716717718719720721722723724369 unmodified lines109410951096109710981099110011011102110311041105110611071108110911101111111211137 unmodified lines112111221123112411251126112711281129126 unmodified lines125612571258125912601261126212631264151 unmodified lines# - **Download SD 1.5 Models**download_model = "https://huggingface.co/frankjoshua/toonyou_beta6/resolve/main/toonyou_beta6.safetensors"# - **Download VAEs**download_vae = "https://huggingface.co/nubby/blessed-sdxl-vae-fp16-fix/resolve/main/sdxl_vae-fp16fix-c-1.1-b-0.5.safetensors?download=true, https://huggingface.co/nubby/blessed-sdxl-vae-fp16-fix/resolve/main/sdxl_vae-fp16fix-blessed.safetensors?download=true, https://huggingface.co/digiplay/VAE/resolve/main/vividReal_v20.safetensors?download=true, https://huggingface.co/fp16-guy/anything_kl-f8-anime2_vae-ft-mse-840000-ema-pruned_blessed_clearvae_fp16_cleaned/resolve/main/kl-f8-anime2_fp16.safetensors?download=true, https://huggingface.co/fp16-guy/anything_kl-f8-anime2_vae-ft-mse-840000-ema-pruned_blessed_clearvae_fp16_cleaned/resolve/main/ClearVAE_V2.3_fp16.safetensors?download=true, https://huggingface.co/fp16-guy/anything_kl-f8-anime2_vae-ft-mse-840000-ema-pruned_blessed_clearvae_fp16_cleaned/resolve/main/vae-ft-mse-840000-ema-pruned_fp16.safetensors?download=true, https://huggingface.co/fp16-guy/anything_kl-f8-anime2_vae-ft-mse-840000-ema-pruned_blessed_clearvae_fp16_cleaned/resolve/main/blessed2_fp16.safetensors?download=true, https://huggingface.co/NoCrypt/blessed_vae/resolve/main/blessed-fix.vae.pt?download=true, https://huggingface.co/fp16-guy/anything_kl-f8-anime2_vae-ft-mse-840000-ema-pruned_blessed_clearvae_fp16_cleaned/resolve/main/anything_fp16.safetensors"# - **Download LoRAs**download_lora = "https://civitai.com/api/download/models/97655, https://civitai.com/api/download/models/124358"load_diffusers_format_model = ['stabilityai/stable-diffusion-xl-base-1.0','misri/epicrealismXL_v7FinalDestination','misri/juggernautXL_juggernautX','misri/anima_pencil-XL-v4.0.0','cagliostrolab/animagine-xl-3.1','misri/kohakuXLEpsilon_rev1','kitty7779/ponyDiffusionV6XL','runwayml/stable-diffusion-v1-5','digiplay/majicMIX_realistic_v6','digiplay/majicMIX_realistic_v7','digiplay/DreamShaper_8','digiplay/BeautifulArt_v1','digiplay/DarkSushi2.5D_v1',]CIVITAI_API_KEY = ""hf_token = ""388 unmodified lines#gallery { flex-grow: 1; }"""sdxl_task = task_model_list[:3] + task_model_list[3:8]sd_task = task_model_list[:3] + task_model_list[8:]def update_task_options(model_name, task_name):if model_name in model_list:if "xl" in model_name.lower():new_choices = sdxl_taskelse:new_choices = sd_taskif task_name not in new_choices:task_name = "txt2img"return gr.update(value=task_name, choices=new_choices)else:return gr.update(value=task_name, choices=task_model_list)with gr.Blocks(theme="NoCrypt/miku", css=CSS) as app:gr.Markdown("# 🧩 DiffuseCraft")gr.Markdown(3 unmodified lines)with gr.Tab("Generation"):with gr.Row():with gr.Column(scale=2):task_gui = gr.Dropdown(label="Task", choices=sdxl_task, value=task_model_list[0])model_name_gui = gr.Dropdown(label="Model", choices=model_list, value=model_list[0], allow_custom_value=True)prompt_gui = gr.Textbox(lines=5, placeholder="Enter prompt", label="Prompt")neg_prompt_gui = gr.Textbox(lines=3, placeholder="Enter Neg prompt", label="Negative prompt")generate_button = gr.Button(value="GENERATE", variant="primary")model_name_gui.change(update_task_options,[model_name_gui, task_gui],[task_gui],)result_images = gr.Gallery(label="Generated images",show_label=False,24 unmodified lineswith gr.Accordion("ControlNet / Img2img / Inpaint", open=False, visible=True):image_control = gr.Image(label="Image ControlNet/Inpaint/Img2img", type="filepath")image_mask_gui = gr.Image(label="Image Mask", type="filepath")strength_gui = gr.Slider(minimum=0.01, maximum=1.0, step=0.01, value=0.55, label="Strength",info="This option adjusts the level of changes for img2img and inpainting.")image_resolution_gui = gr.Slider(minimum=64, maximum=2048, step=64, value=1024, label="Image Resolution")preprocessor_name_gui = gr.Dropdown(label="Preprocessor Name", choices=preprocessor_controlnet["canny"])66 unmodified lineswith gr.Accordion("Textual inversion", open=False, visible=False):active_textual_inversion_gui = gr.Checkbox(value=False, label="Active Textual Inversion in prompt")with gr.Accordion("Hires fix", open=False, visible=True):upscaler_keys = list(upscaler_dict_gui.keys())upscaler_model_path_gui = gr.Dropdown(label="Upscaler", choices=upscaler_keys, value=upscaler_keys[0])upscaler_increases_size_gui = gr.Slider(minimum=1.1, maximum=6., step=0.1, value=1.5, label="Upscale by")esrgan_tile_gui = gr.Slider(minimum=0, value=100, maximum=500, step=1, label="ESRGAN Tile")369 unmodified linesoutputs=[result_images],cache_examples=False,)with gr.Tab("Inpaint mask maker", render=True):def create_mask_now(img, invert):import numpy as npimport timetime.sleep(0.5)transparent_image = img["layers"][0]# Extract the alpha channelalpha_channel = np.array(transparent_image)[:, :, 3]# Create a binary mask by thresholding the alpha channelbinary_mask = alpha_channel > 17 unmodified lines# Convert the mask to uint8rgb_mask = rgb_mask.astype(np.uint8) * 255return img["background"], rgb_maskwith gr.Row():with gr.Column(scale=2):# image_base = gr.ImageEditor(label="Base image", show_label=True, brush=gr.Brush(colors=["#000000"]))126 unmodified linesqueue=True,)app.queue()app.launch(show_error=True,debug=True,)
app.py+61-23