Files changed (8) hide show
  1. README.md +1 -0
  2. app.py +1 -33
  3. constants.py +1 -1
  4. env.py +0 -6
  5. modutils.py +0 -0
  6. packages.txt +1 -2
  7. requirements.txt +6 -5
  8. utils.py +20 -35
README.md CHANGED
@@ -13,6 +13,7 @@ duplicated_from: r3gm/DiffuseCraft
13
  short_description: Stunning images using stable diffusion.
14
  preload_from_hub:
15
  - madebyollin/sdxl-vae-fp16-fix config.json,diffusion_pytorch_model.safetensors
 
16
  ---
17
 
18
  ## Using this Space programmatically
 
13
  short_description: Stunning images using stable diffusion.
14
  preload_from_hub:
15
  - madebyollin/sdxl-vae-fp16-fix config.json,diffusion_pytorch_model.safetensors
16
+ hf_oauth: true
17
  ---
18
 
19
  ## Using this Space programmatically
app.py CHANGED
@@ -199,11 +199,6 @@ class GuiSD:
199
  # Avoid duplicate downloads
200
  self.active_downloads = set()
201
  self.download_lock = threading.Lock()
202
-
203
- # Anti-abuse: track new model requests.
204
- self.used_models = []
205
- self.new_model_history = []
206
-
207
  def update_storage_models(self, storage_floor_gb=24, required_inventory_for_purge=3):
208
  while get_used_storage_gb() > storage_floor_gb:
209
  if len(self.inventory) < required_inventory_for_purge:
@@ -228,34 +223,6 @@ class GuiSD:
228
  print(self.inventory)
229
 
230
  def load_new_model(self, model_name, vae_model, task, controlnet_model, progress=gr.Progress(track_tqdm=True)):
231
-
232
- if model_name != model_list[0]:
233
- # --- Anti-Abuse Check Start ---
234
- if model_name in self.used_models:
235
- # Move to the end to mark as the most recently used.
236
- self.used_models.remove(model_name)
237
- self.used_models.append(model_name)
238
- else:
239
- current_time = datetime.now()
240
- # Retain history of new model requests from the last 20 minutes.
241
- self.new_model_history = [
242
- t for t in self.new_model_history
243
- if (current_time - t).total_seconds() < 1200
244
- ]
245
-
246
- # Allow a maximum of 5 new model requests per 20 minutes.
247
- if len(self.new_model_history) >= 5:
248
- yield "Rate limit exceeded: Too many new models requested."
249
- raise gr.Error("Too many new models requested. Please reuse your previously loaded models or wait a few minutes before trying new ones.")
250
-
251
- self.new_model_history.append(current_time)
252
- self.used_models.append(model_name)
253
-
254
- # Cap the reuse list to the 5 most recent models.
255
- if len(self.used_models) > 5:
256
- self.used_models.pop(0)
257
- # --- Anti-Abuse Check End ---
258
-
259
  lock_key = model_name
260
 
261
  while True:
@@ -2288,6 +2255,7 @@ with gr.Blocks(theme=args.theme, elem_id="main", fill_width=True, fill_height=Fa
2288
  gr.api(generate_image, api_name="generate_image", show_api=True, queue=True, concurrency_id="gpu")
2289
  gr.api(generate_image_stream, api_name="generate_image_stream", show_api=True, queue=True, concurrency_id="gpu")
2290
 
 
2291
  gr.DuplicateButton(value="Duplicate Space for private use (This demo does not work on CPU. Requires GPU Space)")
2292
 
2293
 
 
199
  # Avoid duplicate downloads
200
  self.active_downloads = set()
201
  self.download_lock = threading.Lock()
 
 
 
 
 
202
  def update_storage_models(self, storage_floor_gb=24, required_inventory_for_purge=3):
203
  while get_used_storage_gb() > storage_floor_gb:
204
  if len(self.inventory) < required_inventory_for_purge:
 
223
  print(self.inventory)
224
 
225
  def load_new_model(self, model_name, vae_model, task, controlnet_model, progress=gr.Progress(track_tqdm=True)):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
  lock_key = model_name
227
 
228
  while True:
 
2255
  gr.api(generate_image, api_name="generate_image", show_api=True, queue=True, concurrency_id="gpu")
2256
  gr.api(generate_image_stream, api_name="generate_image_stream", show_api=True, queue=True, concurrency_id="gpu")
2257
 
2258
+ gr.LoginButton()
2259
  gr.DuplicateButton(value="Duplicate Space for private use (This demo does not work on CPU. Requires GPU Space)")
2260
 
2261
 
constants.py CHANGED
@@ -19,7 +19,7 @@ DOWNLOAD_MODEL = "https://huggingface.co/zuv0/test/resolve/main/milkyWonderland_
19
  DOWNLOAD_VAE = "https://huggingface.co/Anzhc/Anzhcs-VAEs/resolve/main/SDXL%20Anime%20VAE%20Dec-only%20B3.safetensors, 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"
20
 
21
  # - **Download LoRAs**
22
- DOWNLOAD_LORA = "https://huggingface.co/Leopain/color/resolve/main/Coloring_book_-_LineArt.safetensors, https://civitai.com/api/download/models/135867, https://huggingface.co/Linaqruf/anime-detailer-xl-lora/resolve/main/anime-detailer-xl.safetensors?download=true, https://huggingface.co/Linaqruf/style-enhancer-xl-lora/resolve/main/style-enhancer-xl.safetensors?download=true"
23
 
24
  LOAD_DIFFUSERS_FORMAT_MODEL = [
25
  'TestOrganizationPleaseIgnore/potato_quality_anime_plzwork_sdxl',
 
19
  DOWNLOAD_VAE = "https://huggingface.co/Anzhc/Anzhcs-VAEs/resolve/main/SDXL%20Anime%20VAE%20Dec-only%20B3.safetensors, 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"
20
 
21
  # - **Download LoRAs**
22
+ DOWNLOAD_LORA = "https://huggingface.co/Leopain/color/resolve/main/Coloring_book_-_LineArt.safetensors, https://civitai.com/api/download/models/135867, https://huggingface.co/Linaqruf/anime-detailer-xl-lora/resolve/main/anime-detailer-xl.safetensors?download=true, https://huggingface.co/Linaqruf/style-enhancer-xl-lora/resolve/main/style-enhancer-xl.safetensors?download=true, https://huggingface.co/ByteDance/Hyper-SD/resolve/main/Hyper-SD15-8steps-CFG-lora.safetensors?download=true, https://huggingface.co/ByteDance/Hyper-SD/resolve/main/Hyper-SDXL-8steps-CFG-lora.safetensors?download=true"
23
 
24
  LOAD_DIFFUSERS_FORMAT_MODEL = [
25
  'TestOrganizationPleaseIgnore/potato_quality_anime_plzwork_sdxl',
env.py CHANGED
@@ -30,8 +30,6 @@ LOAD_DIFFUSERS_FORMAT_MODEL = [
30
  'BlueDancer/Artisanica_XL',
31
  'neta-art/neta-noob-1.0',
32
  'OnomaAIResearch/Illustrious-xl-early-release-v0',
33
- 'martineux/bismuth7-xl',
34
- 'martineux/perfectdeliberate8',
35
  'Raelina/Rae-Diffusion-XL-V2',
36
  'Raelina/Raemu-XL-V4',
37
  'Raelina/Raemu-XL-V5',
@@ -47,10 +45,6 @@ LOAD_DIFFUSERS_FORMAT_MODEL = [
47
  'Raelina/Raehoshi-illust-XL-7',
48
  'Raelina/Raehoshi-illust-XL-7.1',
49
  'Raelina/Raehoshi-illust-XL-8',
50
- 'Raelina/Raehoshi-illust-XL-8.1',
51
- 'Raelina/Raehoshi-illust-XL-9',
52
- 'Raelina/Raehoshi-illust-XL-9.1',
53
- 'Raelina/Raehoshi-illust-vpred',
54
  'camenduru/FLUX.1-dev-diffusers',
55
  'black-forest-labs/FLUX.1-schnell',
56
  'sayakpaul/FLUX.1-merged',
 
30
  'BlueDancer/Artisanica_XL',
31
  'neta-art/neta-noob-1.0',
32
  'OnomaAIResearch/Illustrious-xl-early-release-v0',
 
 
33
  'Raelina/Rae-Diffusion-XL-V2',
34
  'Raelina/Raemu-XL-V4',
35
  'Raelina/Raemu-XL-V5',
 
45
  'Raelina/Raehoshi-illust-XL-7',
46
  'Raelina/Raehoshi-illust-XL-7.1',
47
  'Raelina/Raehoshi-illust-XL-8',
 
 
 
 
48
  'camenduru/FLUX.1-dev-diffusers',
49
  'black-forest-labs/FLUX.1-schnell',
50
  'sayakpaul/FLUX.1-merged',
modutils.py CHANGED
The diff for this file is too large to render. See raw diff
 
packages.txt CHANGED
@@ -1,2 +1 @@
1
- git-lfs
2
- ffmpeg
 
1
+ git-lfs aria2 ffmpeg
 
requirements.txt CHANGED
@@ -3,8 +3,10 @@ diffusers
3
  transformers
4
  accelerate
5
  huggingface_hub
6
- spaces
7
- torch==2.8.0
 
 
8
  numpy<2
9
  gdown
10
  opencv-python
@@ -17,6 +19,5 @@ rapidfuzz
17
  sentencepiece
18
  unidecode
19
  matplotlib-inline
20
- mediapipe==0.10.5
21
- einops
22
- # pydantic==2.10.6
 
3
  transformers
4
  accelerate
5
  huggingface_hub
6
+ hf_transfer
7
+ hf_xet
8
+ torch==2.5.1
9
+ torchvision
10
  numpy<2
11
  gdown
12
  opencv-python
 
19
  sentencepiece
20
  unidecode
21
  matplotlib-inline
22
+ https://github.com/mjun0812/flash-attention-prebuild-wheels/releases/download/v0.4.11/flash_attn-2.8.3+cu124torch2.5-cp310-cp310-linux_x86_64.whl
23
+ pydantic==2.10.6
 
utils.py CHANGED
@@ -275,11 +275,11 @@ def civ_redirect_down(url, dir_, civitai_api_key, romanize, alternative_name):
275
  elif os.path.exists(os.path.join(dir_, filename_base)):
276
  return os.path.join(dir_, filename_base), filename_base
277
 
278
- wget_command = (
279
- f'wget -c -nv '
280
- f'-O "{os.path.join(dir_, filename_base)}" "{redirect_url}"'
281
  )
282
- r_code = os.system(wget_command) # noqa
283
 
284
  # if r_code != 0:
285
  # raise RuntimeError(f"Failed to download file: {filename_base}. Error code: {r_code}")
@@ -293,32 +293,27 @@ def civ_redirect_down(url, dir_, civitai_api_key, romanize, alternative_name):
293
 
294
  def civ_api_down(url, dir_, civitai_api_key, civ_filename):
295
  """
296
- This method is susceptible to being blocked because it generates a lot of temp redirect links with wget.
297
- If an API key limit is reached, generating a new API key and using it can fix the issue. no
298
  """
299
  output_path = None
300
-
301
  url_dl = url + f"?token={civitai_api_key}"
302
-
303
  if not civ_filename:
304
- wget_command = (
305
- f'wget -c -nv '
306
- f'-P "{dir_}" "{url_dl}"'
307
- )
308
- os.system(wget_command)
309
-
310
  else:
311
  output_path = os.path.join(dir_, civ_filename)
312
-
313
  if not os.path.exists(output_path):
314
- wget_command = (
315
- f'wget -c -nv '
316
- f'-O "{output_path}" "{url_dl}"'
317
  )
318
- os.system(wget_command)
319
-
320
  return output_path
321
 
 
322
  def drive_down(url, dir_):
323
  import gdown
324
 
@@ -359,16 +354,10 @@ def hf_down(url, dir_, hf_token, romanize):
359
  url = url.replace("/blob/", "/resolve/")
360
 
361
  if hf_token:
362
- os.system(
363
- f'wget -c -nv '
364
- f'--header="Authorization: Bearer {hf_token}" '
365
- f'-O "{os.path.join(dir_, filename)}" "{url}"'
366
- )
367
  else:
368
- os.system(
369
- f'wget -c -nv '
370
- f'-O "{os.path.join(dir_, filename)}" "{url}"'
371
- )
372
 
373
  return output_path
374
 
@@ -381,8 +370,7 @@ def download_things(directory, url, hf_token="", civitai_api_key="", romanize=Fa
381
  downloaded_file_path = drive_down(url, directory)
382
  elif "huggingface.co" in url:
383
  downloaded_file_path = hf_down(url, directory, hf_token, romanize)
384
- elif "civitai." in url:
385
- url = url.replace("civitai.red", "civitai.com")
386
  if not civitai_api_key:
387
  msg = "You need an API key to download Civitai models."
388
  print(f"\033[91m{msg}\033[0m")
@@ -405,10 +393,7 @@ def download_things(directory, url, hf_token="", civitai_api_key="", romanize=Fa
405
  gr.Warning(msg)
406
  downloaded_file_path = civ_api_down(url, directory, civitai_api_key, civ_filename)
407
  else:
408
- os.system(
409
- f'wget -c -nv '
410
- f'-P "{directory}" "{url}"'
411
- )
412
 
413
  return downloaded_file_path
414
 
 
275
  elif os.path.exists(os.path.join(dir_, filename_base)):
276
  return os.path.join(dir_, filename_base), filename_base
277
 
278
+ aria2_command = (
279
+ f'aria2c --console-log-level=error --summary-interval=10 -c -x 16 '
280
+ f'-k 1M -s 16 -d "{dir_}" -o "{filename_base}" "{redirect_url}"'
281
  )
282
+ r_code = os.system(aria2_command) # noqa
283
 
284
  # if r_code != 0:
285
  # raise RuntimeError(f"Failed to download file: {filename_base}. Error code: {r_code}")
 
293
 
294
  def civ_api_down(url, dir_, civitai_api_key, civ_filename):
295
  """
296
+ This method is susceptible to being blocked because it generates a lot of temp redirect links with aria2c.
297
+ If an API key limit is reached, generating a new API key and using it can fix the issue.
298
  """
299
  output_path = None
300
+
301
  url_dl = url + f"?token={civitai_api_key}"
 
302
  if not civ_filename:
303
+ aria2_command = f'aria2c -c -x 1 -s 1 -d "{dir_}" "{url_dl}"'
304
+ os.system(aria2_command)
 
 
 
 
305
  else:
306
  output_path = os.path.join(dir_, civ_filename)
 
307
  if not os.path.exists(output_path):
308
+ aria2_command = (
309
+ f'aria2c --console-log-level=error --summary-interval=10 -c -x 16 '
310
+ f'-k 1M -s 16 -d "{dir_}" -o "{civ_filename}" "{url_dl}"'
311
  )
312
+ os.system(aria2_command)
313
+
314
  return output_path
315
 
316
+
317
  def drive_down(url, dir_):
318
  import gdown
319
 
 
354
  url = url.replace("/blob/", "/resolve/")
355
 
356
  if hf_token:
357
+ user_header = f'"Authorization: Bearer {hf_token}"'
358
+ os.system(f"aria2c --console-log-level=error --summary-interval=10 --header={user_header} -c -x 16 -k 1M -s 16 {url} -d {dir_} -o {filename}")
 
 
 
359
  else:
360
+ os.system(f"aria2c --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -c -x 16 -k 1M -s 16 {url} -d {dir_} -o {filename}")
 
 
 
361
 
362
  return output_path
363
 
 
370
  downloaded_file_path = drive_down(url, directory)
371
  elif "huggingface.co" in url:
372
  downloaded_file_path = hf_down(url, directory, hf_token, romanize)
373
+ elif "civitai.com" in url:
 
374
  if not civitai_api_key:
375
  msg = "You need an API key to download Civitai models."
376
  print(f"\033[91m{msg}\033[0m")
 
393
  gr.Warning(msg)
394
  downloaded_file_path = civ_api_down(url, directory, civitai_api_key, civ_filename)
395
  else:
396
+ os.system(f"aria2c --console-log-level=error --summary-interval=10 -c -x 16 -k 1M -s 16 -d {directory} {url}")
 
 
 
397
 
398
  return downloaded_file_path
399