Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -152,10 +152,25 @@ os.makedirs(directory_vaes, exist_ok=True)
|
|
| 152 |
# - **Download SD 1.5 Models**
|
| 153 |
download_model = "https://huggingface.co/frankjoshua/toonyou_beta6/resolve/main/toonyou_beta6.safetensors"
|
| 154 |
# - **Download VAEs**
|
| 155 |
-
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"
|
| 156 |
# - **Download LoRAs**
|
| 157 |
download_lora = "https://civitai.com/api/download/models/97655, https://civitai.com/api/download/models/124358"
|
| 158 |
-
load_diffusers_format_model = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
CIVITAI_API_KEY = ""
|
| 160 |
hf_token = ""
|
| 161 |
|
|
@@ -550,6 +565,25 @@ CSS ="""
|
|
| 550 |
#gallery { flex-grow: 1; }
|
| 551 |
"""
|
| 552 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 553 |
with gr.Blocks(theme="NoCrypt/miku", css=CSS) as app:
|
| 554 |
gr.Markdown("# 🧩 DiffuseCraft")
|
| 555 |
gr.Markdown(
|
|
@@ -559,14 +593,21 @@ with gr.Blocks(theme="NoCrypt/miku", css=CSS) as app:
|
|
| 559 |
)
|
| 560 |
with gr.Tab("Generation"):
|
| 561 |
with gr.Row():
|
| 562 |
-
|
| 563 |
with gr.Column(scale=2):
|
| 564 |
-
|
|
|
|
| 565 |
model_name_gui = gr.Dropdown(label="Model", choices=model_list, value=model_list[0], allow_custom_value=True)
|
| 566 |
prompt_gui = gr.Textbox(lines=5, placeholder="Enter prompt", label="Prompt")
|
| 567 |
neg_prompt_gui = gr.Textbox(lines=3, placeholder="Enter Neg prompt", label="Negative prompt")
|
| 568 |
generate_button = gr.Button(value="GENERATE", variant="primary")
|
| 569 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 570 |
result_images = gr.Gallery(
|
| 571 |
label="Generated images",
|
| 572 |
show_label=False,
|
|
@@ -597,7 +638,10 @@ with gr.Blocks(theme="NoCrypt/miku", css=CSS) as app:
|
|
| 597 |
with gr.Accordion("ControlNet / Img2img / Inpaint", open=False, visible=True):
|
| 598 |
image_control = gr.Image(label="Image ControlNet/Inpaint/Img2img", type="filepath")
|
| 599 |
image_mask_gui = gr.Image(label="Image Mask", type="filepath")
|
| 600 |
-
strength_gui = gr.Slider(
|
|
|
|
|
|
|
|
|
|
| 601 |
image_resolution_gui = gr.Slider(minimum=64, maximum=2048, step=64, value=1024, label="Image Resolution")
|
| 602 |
preprocessor_name_gui = gr.Dropdown(label="Preprocessor Name", choices=preprocessor_controlnet["canny"])
|
| 603 |
|
|
@@ -670,11 +714,11 @@ with gr.Blocks(theme="NoCrypt/miku", css=CSS) as app:
|
|
| 670 |
|
| 671 |
with gr.Accordion("Textual inversion", open=False, visible=False):
|
| 672 |
active_textual_inversion_gui = gr.Checkbox(value=False, label="Active Textual Inversion in prompt")
|
| 673 |
-
|
| 674 |
with gr.Accordion("Hires fix", open=False, visible=True):
|
| 675 |
-
|
| 676 |
upscaler_keys = list(upscaler_dict_gui.keys())
|
| 677 |
-
|
| 678 |
upscaler_model_path_gui = gr.Dropdown(label="Upscaler", choices=upscaler_keys, value=upscaler_keys[0])
|
| 679 |
upscaler_increases_size_gui = gr.Slider(minimum=1.1, maximum=6., step=0.1, value=1.5, label="Upscale by")
|
| 680 |
esrgan_tile_gui = gr.Slider(minimum=0, value=100, maximum=500, step=1, label="ESRGAN Tile")
|
|
@@ -1050,20 +1094,20 @@ with gr.Blocks(theme="NoCrypt/miku", css=CSS) as app:
|
|
| 1050 |
outputs=[result_images],
|
| 1051 |
cache_examples=False,
|
| 1052 |
)
|
| 1053 |
-
|
| 1054 |
with gr.Tab("Inpaint mask maker", render=True):
|
| 1055 |
-
|
| 1056 |
def create_mask_now(img, invert):
|
| 1057 |
import numpy as np
|
| 1058 |
import time
|
| 1059 |
-
|
| 1060 |
time.sleep(0.5)
|
| 1061 |
|
| 1062 |
transparent_image = img["layers"][0]
|
| 1063 |
-
|
| 1064 |
# Extract the alpha channel
|
| 1065 |
alpha_channel = np.array(transparent_image)[:, :, 3]
|
| 1066 |
-
|
| 1067 |
# Create a binary mask by thresholding the alpha channel
|
| 1068 |
binary_mask = alpha_channel > 1
|
| 1069 |
|
|
@@ -1077,9 +1121,9 @@ with gr.Blocks(theme="NoCrypt/miku", css=CSS) as app:
|
|
| 1077 |
|
| 1078 |
# Convert the mask to uint8
|
| 1079 |
rgb_mask = rgb_mask.astype(np.uint8) * 255
|
| 1080 |
-
|
| 1081 |
return img["background"], rgb_mask
|
| 1082 |
-
|
| 1083 |
with gr.Row():
|
| 1084 |
with gr.Column(scale=2):
|
| 1085 |
# image_base = gr.ImageEditor(label="Base image", show_label=True, brush=gr.Brush(colors=["#000000"]))
|
|
@@ -1212,15 +1256,9 @@ with gr.Blocks(theme="NoCrypt/miku", css=CSS) as app:
|
|
| 1212 |
queue=True,
|
| 1213 |
)
|
| 1214 |
|
| 1215 |
-
|
| 1216 |
-
|
| 1217 |
-
app.queue() # default_concurrency_limit=40
|
| 1218 |
|
| 1219 |
app.launch(
|
| 1220 |
-
# max_threads=40,
|
| 1221 |
-
# share=False,
|
| 1222 |
show_error=True,
|
| 1223 |
-
# quiet=False,
|
| 1224 |
debug=True,
|
| 1225 |
-
# allowed_paths=["./assets/"],
|
| 1226 |
)
|
|
|
|
| 152 |
# - **Download SD 1.5 Models**
|
| 153 |
download_model = "https://huggingface.co/frankjoshua/toonyou_beta6/resolve/main/toonyou_beta6.safetensors"
|
| 154 |
# - **Download VAEs**
|
| 155 |
+
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"
|
| 156 |
# - **Download LoRAs**
|
| 157 |
download_lora = "https://civitai.com/api/download/models/97655, https://civitai.com/api/download/models/124358"
|
| 158 |
+
load_diffusers_format_model = [
|
| 159 |
+
'stabilityai/stable-diffusion-xl-base-1.0',
|
| 160 |
+
'misri/epicrealismXL_v7FinalDestination',
|
| 161 |
+
'misri/juggernautXL_juggernautX',
|
| 162 |
+
'misri/anima_pencil-XL-v4.0.0',
|
| 163 |
+
'cagliostrolab/animagine-xl-3.1',
|
| 164 |
+
'misri/kohakuXLEpsilon_rev1',
|
| 165 |
+
'kitty7779/ponyDiffusionV6XL',
|
| 166 |
+
'runwayml/stable-diffusion-v1-5',
|
| 167 |
+
'digiplay/majicMIX_realistic_v6',
|
| 168 |
+
'digiplay/majicMIX_realistic_v7',
|
| 169 |
+
'digiplay/DreamShaper_8',
|
| 170 |
+
'digiplay/BeautifulArt_v1',
|
| 171 |
+
'digiplay/DarkSushi2.5D_v1',
|
| 172 |
+
]
|
| 173 |
+
|
| 174 |
CIVITAI_API_KEY = ""
|
| 175 |
hf_token = ""
|
| 176 |
|
|
|
|
| 565 |
#gallery { flex-grow: 1; }
|
| 566 |
"""
|
| 567 |
|
| 568 |
+
sdxl_task = task_model_list[:3] + task_model_list[3:8]
|
| 569 |
+
sd_task = task_model_list[:3] + task_model_list[8:]
|
| 570 |
+
|
| 571 |
+
|
| 572 |
+
def update_task_options(model_name, task_name):
|
| 573 |
+
if model_name in model_list:
|
| 574 |
+
if "xl" in model_name.lower():
|
| 575 |
+
new_choices = sdxl_task
|
| 576 |
+
else:
|
| 577 |
+
new_choices = sd_task
|
| 578 |
+
|
| 579 |
+
if task_name not in new_choices:
|
| 580 |
+
task_name = "txt2img"
|
| 581 |
+
|
| 582 |
+
return gr.update(value=task_name, choices=new_choices)
|
| 583 |
+
else:
|
| 584 |
+
return gr.update(value=task_name, choices=task_model_list)
|
| 585 |
+
|
| 586 |
+
|
| 587 |
with gr.Blocks(theme="NoCrypt/miku", css=CSS) as app:
|
| 588 |
gr.Markdown("# 🧩 DiffuseCraft")
|
| 589 |
gr.Markdown(
|
|
|
|
| 593 |
)
|
| 594 |
with gr.Tab("Generation"):
|
| 595 |
with gr.Row():
|
| 596 |
+
|
| 597 |
with gr.Column(scale=2):
|
| 598 |
+
|
| 599 |
+
task_gui = gr.Dropdown(label="Task", choices=sdxl_task, value=task_model_list[0])
|
| 600 |
model_name_gui = gr.Dropdown(label="Model", choices=model_list, value=model_list[0], allow_custom_value=True)
|
| 601 |
prompt_gui = gr.Textbox(lines=5, placeholder="Enter prompt", label="Prompt")
|
| 602 |
neg_prompt_gui = gr.Textbox(lines=3, placeholder="Enter Neg prompt", label="Negative prompt")
|
| 603 |
generate_button = gr.Button(value="GENERATE", variant="primary")
|
| 604 |
+
|
| 605 |
+
model_name_gui.change(
|
| 606 |
+
update_task_options,
|
| 607 |
+
[model_name_gui, task_gui],
|
| 608 |
+
[task_gui],
|
| 609 |
+
)
|
| 610 |
+
|
| 611 |
result_images = gr.Gallery(
|
| 612 |
label="Generated images",
|
| 613 |
show_label=False,
|
|
|
|
| 638 |
with gr.Accordion("ControlNet / Img2img / Inpaint", open=False, visible=True):
|
| 639 |
image_control = gr.Image(label="Image ControlNet/Inpaint/Img2img", type="filepath")
|
| 640 |
image_mask_gui = gr.Image(label="Image Mask", type="filepath")
|
| 641 |
+
strength_gui = gr.Slider(
|
| 642 |
+
minimum=0.01, maximum=1.0, step=0.01, value=0.55, label="Strength",
|
| 643 |
+
info="This option adjusts the level of changes for img2img and inpainting."
|
| 644 |
+
)
|
| 645 |
image_resolution_gui = gr.Slider(minimum=64, maximum=2048, step=64, value=1024, label="Image Resolution")
|
| 646 |
preprocessor_name_gui = gr.Dropdown(label="Preprocessor Name", choices=preprocessor_controlnet["canny"])
|
| 647 |
|
|
|
|
| 714 |
|
| 715 |
with gr.Accordion("Textual inversion", open=False, visible=False):
|
| 716 |
active_textual_inversion_gui = gr.Checkbox(value=False, label="Active Textual Inversion in prompt")
|
| 717 |
+
|
| 718 |
with gr.Accordion("Hires fix", open=False, visible=True):
|
| 719 |
+
|
| 720 |
upscaler_keys = list(upscaler_dict_gui.keys())
|
| 721 |
+
|
| 722 |
upscaler_model_path_gui = gr.Dropdown(label="Upscaler", choices=upscaler_keys, value=upscaler_keys[0])
|
| 723 |
upscaler_increases_size_gui = gr.Slider(minimum=1.1, maximum=6., step=0.1, value=1.5, label="Upscale by")
|
| 724 |
esrgan_tile_gui = gr.Slider(minimum=0, value=100, maximum=500, step=1, label="ESRGAN Tile")
|
|
|
|
| 1094 |
outputs=[result_images],
|
| 1095 |
cache_examples=False,
|
| 1096 |
)
|
| 1097 |
+
|
| 1098 |
with gr.Tab("Inpaint mask maker", render=True):
|
| 1099 |
+
|
| 1100 |
def create_mask_now(img, invert):
|
| 1101 |
import numpy as np
|
| 1102 |
import time
|
| 1103 |
+
|
| 1104 |
time.sleep(0.5)
|
| 1105 |
|
| 1106 |
transparent_image = img["layers"][0]
|
| 1107 |
+
|
| 1108 |
# Extract the alpha channel
|
| 1109 |
alpha_channel = np.array(transparent_image)[:, :, 3]
|
| 1110 |
+
|
| 1111 |
# Create a binary mask by thresholding the alpha channel
|
| 1112 |
binary_mask = alpha_channel > 1
|
| 1113 |
|
|
|
|
| 1121 |
|
| 1122 |
# Convert the mask to uint8
|
| 1123 |
rgb_mask = rgb_mask.astype(np.uint8) * 255
|
| 1124 |
+
|
| 1125 |
return img["background"], rgb_mask
|
| 1126 |
+
|
| 1127 |
with gr.Row():
|
| 1128 |
with gr.Column(scale=2):
|
| 1129 |
# image_base = gr.ImageEditor(label="Base image", show_label=True, brush=gr.Brush(colors=["#000000"]))
|
|
|
|
| 1256 |
queue=True,
|
| 1257 |
)
|
| 1258 |
|
| 1259 |
+
app.queue()
|
|
|
|
|
|
|
| 1260 |
|
| 1261 |
app.launch(
|
|
|
|
|
|
|
| 1262 |
show_error=True,
|
|
|
|
| 1263 |
debug=True,
|
|
|
|
| 1264 |
)
|