zerhero commited on
Commit
c3408ce
1 Parent(s): 0509eb5
Files changed (1) hide show
  1. app.py +63 -22
app.py CHANGED
@@ -1,9 +1,11 @@
1
- import spaces # must imported when using spaces
2
  import os
3
  from stablepy import Model_Diffusers
 
4
  from stablepy.diffusers_vanilla.style_prompt_config import STYLE_NAMES
5
  import torch
6
  import re
 
7
  import random
8
  from stablepy import (
9
  CONTROLNET_MODEL_IDS,
@@ -20,6 +22,7 @@ from stablepy import (
20
  SD15_TASKS,
21
  SDXL_TASKS,
22
  )
 
23
  from config import (
24
  MINIMUM_IMAGE_NUMBER,
25
  MAXIMUM_IMAGE_NUMBER,
@@ -65,7 +68,6 @@ task_stablepy: dict = {
65
  CIVITAI_API_KEY: str = os.environ.get("CIVITAI_API_KEY")
66
  hf_token: str = os.environ.get("HF_TOKEN")
67
 
68
-
69
  task_model_list = list(task_stablepy.keys())
70
 
71
  directory_models: str = 'models'
@@ -251,7 +253,7 @@ class GuiSD:
251
  )
252
  yield f"Model loaded: {model_name}"
253
 
254
- @spaces.GPU(duration=60)
255
  def generate_pipeline(
256
  self,
257
  prompt,
@@ -354,12 +356,10 @@ class GuiSD:
354
  mask_ip2,
355
  model_ip2,
356
  mode_ip2,
357
- scale_ip2,
358
- ):
359
-
360
  vae_model = vae_model if vae_model != "None" else None
361
- loras_list = [lora1, lora2, lora3, lora4, lora5]
362
- vae_msg = f"VAE: {vae_model}" if vae_model else ""
363
  msg_lora: list = []
364
 
365
  if model_name in model_list:
@@ -637,7 +637,6 @@ with gr.Blocks(css=CSS) as app:
637
  gr.Markdown("# 🧩 (Ivan) DiffuseCraft")
638
  with gr.Tab("Generation"):
639
  with gr.Row():
640
-
641
  with gr.Column(scale=2):
642
 
643
  task_gui = gr.Dropdown(
@@ -667,6 +666,7 @@ with gr.Blocks(css=CSS) as app:
667
  set_params_gui = gr.Button(value="↙️")
668
  clear_prompt_gui = gr.Button(value="🗑️")
669
  set_random_seed = gr.Button(value="🎲")
 
670
  generate_button = gr.Button(
671
  value="GENERATE",
672
  variant="primary"
@@ -857,7 +857,6 @@ with gr.Blocks(css=CSS) as app:
857
  choices=upscaler_keys,
858
  value=upscaler_keys[0]
859
  )
860
-
861
  upscaler_increases_size_gui = gr.Slider(
862
  minimum=1.1,
863
  maximum=6.,
@@ -986,7 +985,13 @@ with gr.Blocks(css=CSS) as app:
986
  )
987
 
988
  with gr.Accordion("IP-Adapter", open=False, visible=True): # IP-Adapter
989
- IP_MODELS = sorted(list(set(IP_ADAPTERS_SD + IP_ADAPTERS_SDXL)))
 
 
 
 
 
 
990
  MODE_IP_OPTIONS = [
991
  "original",
992
  "style",
@@ -1048,7 +1053,10 @@ with gr.Blocks(css=CSS) as app:
1048
  label="Scale"
1049
  )
1050
 
1051
- with gr.Accordion("ControlNet / Img2img / Inpaint", open=False, visible=True):
 
 
 
1052
  image_control = gr.Image(
1053
  label="Image ControlNet/Inpaint/Img2img",
1054
  type="filepath"
@@ -1170,7 +1178,10 @@ with gr.Blocks(css=CSS) as app:
1170
  label="Adapter Conditioning Factor (%)"
1171
  )
1172
 
1173
- with gr.Accordion("Styles", open=False, visible=True):
 
 
 
1174
 
1175
  try:
1176
  style_names_found = sd_gen.model.STYLE_NAMES
@@ -1191,11 +1202,17 @@ with gr.Blocks(css=CSS) as app:
1191
  def load_json_style_file(json):
1192
  if not sd_gen.model:
1193
  gr.Info("First load the model")
1194
- return gr.update(value=None, choices=STYLE_NAMES)
 
 
 
1195
 
1196
  sd_gen.model.load_style_file(json)
1197
  gr.Info(f"{len(sd_gen.model.STYLE_NAMES)} styles loaded")
1198
- return gr.update(value=None, choices=sd_gen.model.STYLE_NAMES)
 
 
 
1199
 
1200
 
1201
  style_button.click(
@@ -1296,12 +1313,33 @@ with gr.Blocks(css=CSS) as app:
1296
  minimum=0.01,
1297
  maximum=1.0
1298
  )
1299
- face_detector_ad_b_gui = gr.Checkbox(label="Face detector", value=True)
1300
- person_detector_ad_b_gui = gr.Checkbox(label="Person detector", value=True)
1301
- hand_detector_ad_b_gui = gr.Checkbox(label="Hand detector", value=False)
1302
- mask_dilation_b_gui = gr.Number(label="Mask dilation:", value=4, minimum=1)
1303
- mask_blur_b_gui = gr.Number(label="Mask blur:", value=4, minimum=1)
1304
- mask_padding_b_gui = gr.Number(label="Mask padding:", value=32, minimum=1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1305
 
1306
  with gr.Accordion(
1307
  "Other settings",
@@ -1501,7 +1539,10 @@ with gr.Blocks(css=CSS) as app:
1501
  ),
1502
  eraser=gr.Eraser(default_size="16")
1503
  )
1504
- invert_mask = gr.Checkbox(value=False, label="Invert mask")
 
 
 
1505
  btn = gr.Button("Create mask")
1506
  with gr.Column(scale=1):
1507
  img_source = gr.Image(interactive=False)
 
1
+ import spaces
2
  import os
3
  from stablepy import Model_Diffusers
4
+ from stablepy.diffusers_vanilla.model import scheduler_names
5
  from stablepy.diffusers_vanilla.style_prompt_config import STYLE_NAMES
6
  import torch
7
  import re
8
+ import shutil
9
  import random
10
  from stablepy import (
11
  CONTROLNET_MODEL_IDS,
 
22
  SD15_TASKS,
23
  SDXL_TASKS,
24
  )
25
+ import urllib.parse
26
  from config import (
27
  MINIMUM_IMAGE_NUMBER,
28
  MAXIMUM_IMAGE_NUMBER,
 
68
  CIVITAI_API_KEY: str = os.environ.get("CIVITAI_API_KEY")
69
  hf_token: str = os.environ.get("HF_TOKEN")
70
 
 
71
  task_model_list = list(task_stablepy.keys())
72
 
73
  directory_models: str = 'models'
 
253
  )
254
  yield f"Model loaded: {model_name}"
255
 
256
+ @spaces.GPU
257
  def generate_pipeline(
258
  self,
259
  prompt,
 
356
  mask_ip2,
357
  model_ip2,
358
  mode_ip2,
359
+ scale_ip2):
 
 
360
  vae_model = vae_model if vae_model != "None" else None
361
+ loras_list: list = [lora1, lora2, lora3, lora4, lora5]
362
+ vae_msg: str = f"VAE: {vae_model}" if vae_model else ""
363
  msg_lora: list = []
364
 
365
  if model_name in model_list:
 
637
  gr.Markdown("# 🧩 (Ivan) DiffuseCraft")
638
  with gr.Tab("Generation"):
639
  with gr.Row():
 
640
  with gr.Column(scale=2):
641
 
642
  task_gui = gr.Dropdown(
 
666
  set_params_gui = gr.Button(value="↙️")
667
  clear_prompt_gui = gr.Button(value="🗑️")
668
  set_random_seed = gr.Button(value="🎲")
669
+
670
  generate_button = gr.Button(
671
  value="GENERATE",
672
  variant="primary"
 
857
  choices=upscaler_keys,
858
  value=upscaler_keys[0]
859
  )
 
860
  upscaler_increases_size_gui = gr.Slider(
861
  minimum=1.1,
862
  maximum=6.,
 
985
  )
986
 
987
  with gr.Accordion("IP-Adapter", open=False, visible=True): # IP-Adapter
988
+ IP_MODELS = sorted(
989
+ list(
990
+ set(
991
+ IP_ADAPTERS_SD + IP_ADAPTERS_SDXL
992
+ )
993
+ )
994
+ )
995
  MODE_IP_OPTIONS = [
996
  "original",
997
  "style",
 
1053
  label="Scale"
1054
  )
1055
 
1056
+ with gr.Accordion(
1057
+ "ControlNet / Img2img / Inpaint",
1058
+ open=False,
1059
+ visible=True):
1060
  image_control = gr.Image(
1061
  label="Image ControlNet/Inpaint/Img2img",
1062
  type="filepath"
 
1178
  label="Adapter Conditioning Factor (%)"
1179
  )
1180
 
1181
+ with gr.Accordion(
1182
+ "Styles",
1183
+ open=False,
1184
+ visible=True):
1185
 
1186
  try:
1187
  style_names_found = sd_gen.model.STYLE_NAMES
 
1202
  def load_json_style_file(json):
1203
  if not sd_gen.model:
1204
  gr.Info("First load the model")
1205
+ return gr.update(
1206
+ value=None,
1207
+ choices=STYLE_NAMES
1208
+ )
1209
 
1210
  sd_gen.model.load_style_file(json)
1211
  gr.Info(f"{len(sd_gen.model.STYLE_NAMES)} styles loaded")
1212
+ return gr.update(
1213
+ value=None,
1214
+ choices=sd_gen.model.STYLE_NAMES
1215
+ )
1216
 
1217
 
1218
  style_button.click(
 
1313
  minimum=0.01,
1314
  maximum=1.0
1315
  )
1316
+ face_detector_ad_b_gui = gr.Checkbox(
1317
+ label="Face detector",
1318
+ value=True
1319
+ )
1320
+ person_detector_ad_b_gui = gr.Checkbox(
1321
+ label="Person detector",
1322
+ value=True
1323
+ )
1324
+ hand_detector_ad_b_gui = gr.Checkbox(
1325
+ label="Hand detector",
1326
+ value=False
1327
+ )
1328
+ mask_dilation_b_gui = gr.Number(
1329
+ label="Mask dilation:",
1330
+ value=4,
1331
+ minimum=1
1332
+ )
1333
+ mask_blur_b_gui = gr.Number(
1334
+ label="Mask blur:",
1335
+ value=4,
1336
+ minimum=1
1337
+ )
1338
+ mask_padding_b_gui = gr.Number(
1339
+ label="Mask padding:",
1340
+ value=32,
1341
+ minimum=1
1342
+ )
1343
 
1344
  with gr.Accordion(
1345
  "Other settings",
 
1539
  ),
1540
  eraser=gr.Eraser(default_size="16")
1541
  )
1542
+ invert_mask = gr.Checkbox(
1543
+ value=False,
1544
+ label="Invert mask"
1545
+ )
1546
  btn = gr.Button("Create mask")
1547
  with gr.Column(scale=1):
1548
  img_source = gr.Image(interactive=False)