zerhero commited on
Commit
169b607
1 Parent(s): 72c217e
app.py CHANGED
@@ -1,11 +1,8 @@
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,7 +19,6 @@ from stablepy import (
22
  SD15_TASKS,
23
  SDXL_TASKS,
24
  )
25
- import urllib.parse
26
  from config import (
27
  MINIMUM_IMAGE_NUMBER,
28
  MAXIMUM_IMAGE_NUMBER,
@@ -31,7 +27,15 @@ from config import (
31
  )
32
  from models.vae import VAE_LIST as download_vae
33
  from models.checkpoints import CHECKPOINT_LIST as download_model
 
 
 
34
  from examples.examples import example_prompts
 
 
 
 
 
35
 
36
  preprocessor_controlnet = {
37
  "openpose": [
@@ -112,73 +116,6 @@ task_stablepy = {
112
 
113
  task_model_list = list(task_stablepy.keys())
114
 
115
-
116
- def download_things(directory, url, hf_token="", civitai_api_key=""):
117
- url = url.strip()
118
-
119
- if "drive.google.com" in url:
120
- original_dir = os.getcwd()
121
- os.chdir(directory)
122
- os.system(f"gdown --fuzzy {url}")
123
- os.chdir(original_dir)
124
- elif "huggingface.co" in url:
125
- url = url.replace("?download=true", "")
126
- # url = urllib.parse.quote(url, safe=':/') # fix encoding
127
- if "/blob/" in url:
128
- url = url.replace("/blob/", "/resolve/")
129
- user_header = f'"Authorization: Bearer {hf_token}"'
130
- if hf_token:
131
- os.system(
132
- f"aria2c --console-log-level=error --summary-interval=10 --header={user_header} -c -x 16 -k 1M -s 16 {url} -d {directory} -o {url.split('/')[-1]}")
133
- else:
134
- os.system(
135
- f"aria2c --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -c -x 16 -k "
136
- f"1M -s 16 {url} -d {directory} -o {url.split('/')[-1]}")
137
- elif "civitai.com" in url:
138
- if "?" in url:
139
- url = url.split("?")[0]
140
- if civitai_api_key:
141
- url = url + f"?token={civitai_api_key}"
142
- os.system(
143
- f"aria2c --console-log-level=error --summary-interval=10 -c -x 16 -k 1M -s 16 -d {directory} {url}")
144
- else:
145
- print("\033[91mYou need an API key to download Civitai models.\033[0m")
146
- else:
147
- os.system(f"aria2c --console-log-level=error --summary-interval=10 -c -x 16 -k 1M -s 16 -d {directory} {url}")
148
-
149
-
150
- def get_model_list(directory_path):
151
- model_list: list = []
152
- valid_extensions = {
153
- '.ckpt',
154
- '.pt',
155
- '.pth',
156
- '.safetensors',
157
- '.bin'
158
- }
159
-
160
- for filename in os.listdir(directory_path):
161
- if os.path.splitext(filename)[1] in valid_extensions:
162
- name_without_extension = os.path.splitext(filename)[0]
163
- file_path = os.path.join(directory_path, filename)
164
- # model_list.append((name_without_extension, file_path))
165
- model_list.append(file_path)
166
- print('\033[34mFILE: ' + file_path + '\033[0m')
167
- return model_list
168
-
169
-
170
- def process_string(input_string):
171
- parts = input_string.split('/')
172
-
173
- if len(parts) == 2:
174
- first_element = parts[1]
175
- complete_string = input_string
176
- result = (first_element, complete_string)
177
- return result
178
- else:
179
- return None
180
-
181
-
182
  directory_models = 'models'
183
  os.makedirs(directory_models, exist_ok=True)
184
  directory_loras = 'loras'
@@ -186,74 +123,42 @@ os.makedirs(directory_loras, exist_ok=True)
186
  directory_vaes = 'vaes'
187
  os.makedirs(directory_vaes, exist_ok=True)
188
 
189
- # - **Download LoRAs**
190
- download_lora = (
191
- "https://civitai.com/api/download/models/423719, "
192
- "https://civitai.com/api/download/models/50503, "
193
- "https://civitai.com/api/download/models/133160, "
194
- "https://civitai.com/api/download/models/29332, "
195
- "https://huggingface.co/Leopain/color/resolve/main/Coloring_book_-_LineArt.safetensors, "
196
- "https://civitai.com/api/download/models/135867, "
197
- "https://civitai.com/api/download/models/145907, "
198
- "https://huggingface.co/Linaqruf/anime-detailer-xl-lora/resolve/main/anime-detailer-xl.safetensors?download=true, "
199
- "https://huggingface.co/Linaqruf/style-enhancer-xl-lora/resolve/main/style-enhancer-xl.safetensors?download=true, "
200
- "https://civitai.com/api/download/models/28609, "
201
- "https://huggingface.co/ByteDance/Hyper-SD/resolve/main/Hyper-SD15-8steps-CFG-lora.safetensors?download=true, "
202
- "https://huggingface.co/ByteDance/Hyper-SD/resolve/main/Hyper-SDXL-8steps-CFG-lora.safetensors?download=true, "
203
- "https://civitai.com/api/download/models/30666 "
204
- )
205
-
206
- load_diffusers_format_model = [
207
- 'stabilityai/stable-diffusion-xl-base-1.0',
208
- 'cagliostrolab/animagine-xl-3.1',
209
- 'misri/epicrealismXL_v7FinalDestination',
210
- 'misri/juggernautXL_juggernautX',
211
- 'misri/zavychromaxl_v80',
212
- 'SG161222/RealVisXL_V4.0',
213
- 'misri/newrealityxlAllInOne_Newreality40',
214
- 'eienmojiki/Anything-XL',
215
- 'eienmojiki/Starry-XL-v5.2',
216
- 'gsdf/CounterfeitXL',
217
- 'kitty7779/ponyDiffusionV6XL',
218
- 'John6666/ebara-mfcg-pony-mix-v12-sdxl',
219
- 'John6666/t-ponynai3-v51-sdxl',
220
- 'yodayo-ai/kivotos-xl-2.0',
221
- 'yodayo-ai/holodayo-xl-2.1',
222
- 'digiplay/majicMIX_sombre_v2',
223
- 'digiplay/majicMIX_realistic_v6',
224
- 'digiplay/majicMIX_realistic_v7',
225
- 'digiplay/DreamShaper_8',
226
- 'digiplay/BeautifulArt_v1',
227
- 'digiplay/DarkSushi2.5D_v1',
228
- 'digiplay/darkphoenix3D_v1.1',
229
- 'digiplay/BeenYouLiteL11_diffusers',
230
- 'rubbrband/revAnimated_v2Rebirth',
231
- 'youknownothing/cyberrealistic_v50',
232
- 'votepurchase/counterfeitV30_v30',
233
- 'Meina/MeinaMix_V11',
234
- 'Meina/MeinaUnreal_V5',
235
- 'Meina/MeinaPastel_V7',
236
- 'rubbrband/realcartoon3d_v16',
237
- 'rubbrband/realcartoonRealistic_v14',
238
- ]
239
-
240
  CIVITAI_API_KEY: str = os.environ.get("CIVITAI_API_KEY")
241
  hf_token: str = os.environ.get("HF_TOKEN")
242
 
243
  # Download stuffs
244
  for url in [url.strip() for url in download_model.split(',')]:
245
  if not os.path.exists(f"./models/{url.split('/')[-1]}"):
246
- download_things(directory_models, url, hf_token, CIVITAI_API_KEY)
 
 
 
 
 
247
  for url in [url.strip() for url in download_vae.split(',')]:
248
  if not os.path.exists(f"./vaes/{url.split('/')[-1]}"):
249
- download_things(directory_vaes, url, hf_token, CIVITAI_API_KEY)
 
 
 
 
 
250
  for url in [url.strip() for url in download_lora.split(',')]:
251
  if not os.path.exists(f"./loras/{url.split('/')[-1]}"):
252
- download_things(directory_loras, url, hf_token, CIVITAI_API_KEY)
 
 
 
 
 
253
 
254
  # Download Embeddings
255
  directory_embeds = 'embedings'
256
- os.makedirs(directory_embeds, exist_ok=True)
 
 
 
257
  download_embeds = [
258
  'https://huggingface.co/datasets/Nerfgun3/bad_prompt/blob/main/bad_prompt_version2.pt',
259
  'https://huggingface.co/embed/negative/resolve/main/EasyNegativeV2.safetensors',
@@ -262,7 +167,12 @@ download_embeds = [
262
 
263
  for url_embed in download_embeds:
264
  if not os.path.exists(f"./embedings/{url_embed.split('/')[-1]}"):
265
- download_things(directory_embeds, url_embed, hf_token, CIVITAI_API_KEY)
 
 
 
 
 
266
 
267
  # Build list models
268
  embed_list = get_model_list(directory_embeds)
@@ -277,7 +187,12 @@ vae_model_list.insert(0, "None")
277
  def get_my_lora(link_url):
278
  for url in [url.strip() for url in link_url.split(',')]:
279
  if not os.path.exists(f"./loras/{url.split('/')[-1]}"):
280
- download_things(directory_loras, url, hf_token, CIVITAI_API_KEY)
 
 
 
 
 
281
  new_lora_model_list = get_model_list(directory_loras)
282
  new_lora_model_list.insert(0, "None")
283
 
@@ -291,32 +206,11 @@ def get_my_lora(link_url):
291
  choices=new_lora_model_list
292
  ), gr.update(
293
  choices=new_lora_model_list
294
- ),
295
 
296
 
297
  print('\033[33m🏁 Download and listing of valid models completed.\033[0m')
298
 
299
- upscaler_dict_gui = {
300
- None: None,
301
- "Lanczos": "Lanczos",
302
- "Nearest": "Nearest",
303
- "RealESRGAN_x4plus": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth",
304
- "RealESRNet_x4plus": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/RealESRNet_x4plus.pth",
305
- "RealESRGAN_x4plus_anime_6B": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth",
306
- "RealESRGAN_x2plus": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth",
307
- "realesr-animevideov3": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-animevideov3.pth",
308
- "realesr-general-x4v3": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth",
309
- "realesr-general-wdn-x4v3": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-wdn-x4v3.pth",
310
- "4x-UltraSharp": "https://huggingface.co/Shandypur/ESRGAN-4x-UltraSharp/resolve/main/4x-UltraSharp.pth",
311
- "4x_foolhardy_Remacri": "https://huggingface.co/FacehugmanIII/4x_foolhardy_Remacri/resolve/main/4x_foolhardy_Remacri.pth",
312
- "Remacri4xExtraSmoother": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/Remacri%204x%20ExtraSmoother.pth",
313
- "AnimeSharp4x": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/AnimeSharp%204x.pth",
314
- "lollypop": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/lollypop.pth",
315
- "RealisticRescaler4x": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/RealisticRescaler%204x.pth",
316
- "NickelbackFS4x": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/NickelbackFS%204x.pth"
317
- }
318
-
319
-
320
  def extract_parameters(input_string):
321
  parameters = {}
322
  input_string = input_string.replace("\n", "")
@@ -764,9 +658,9 @@ class GuiSD:
764
  # Maybe fix lora issue: 'Cannot copy out of meta tensor; no data!''
765
  self.model.pipe.to("cuda:0" if torch.cuda.is_available() else "cpu")
766
 
767
- info_state = f"PROCESSING "
768
  for img, seed, data in self.model(**pipe_params):
769
- info_state += ">"
770
  if data:
771
  info_state = f"COMPLETED. Seeds: {str(seed)}"
772
  if vae_msg:
@@ -1018,6 +912,7 @@ with gr.Blocks(css=CSS) as app:
1018
  vae_model_gui = gr.Dropdown(
1019
  label="VAE Model",
1020
  choices=vae_model_list,
 
1021
  )
1022
 
1023
  with gr.Accordion("Hires fix", open=False, visible=True):
@@ -1642,7 +1537,7 @@ with gr.Blocks(css=CSS) as app:
1642
  )
1643
 
1644
 
1645
- def send_img(img_source, img_result):
1646
  return img_source, img_result
1647
 
1648
 
@@ -1767,7 +1662,10 @@ with gr.Blocks(css=CSS) as app:
1767
  mode_ip2,
1768
  scale_ip2,
1769
  ],
1770
- outputs=[result_images, actual_task_info],
 
 
 
1771
  queue=True,
1772
  show_progress="minimal",
1773
  )
 
 
1
  import os
2
  from stablepy import Model_Diffusers
 
3
  from stablepy.diffusers_vanilla.style_prompt_config import STYLE_NAMES
4
  import torch
5
  import re
 
6
  import random
7
  from stablepy import (
8
  CONTROLNET_MODEL_IDS,
 
19
  SD15_TASKS,
20
  SDXL_TASKS,
21
  )
 
22
  from config import (
23
  MINIMUM_IMAGE_NUMBER,
24
  MAXIMUM_IMAGE_NUMBER,
 
27
  )
28
  from models.vae import VAE_LIST as download_vae
29
  from models.checkpoints import CHECKPOINT_LIST as download_model
30
+ from models.loras import LORA_LIST as download_lora
31
+ from models.format_models import FORMAT_MODELS as load_diffusers_format_model
32
+ from models.upscaler import upscaler_dict_gui
33
  from examples.examples import example_prompts
34
+ from utils.download_utils import download_things
35
+ from utils.model_utils import get_model_list
36
+
37
+
38
+ # from utils.string_utils import process_string
39
 
40
  preprocessor_controlnet = {
41
  "openpose": [
 
116
 
117
  task_model_list = list(task_stablepy.keys())
118
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  directory_models = 'models'
120
  os.makedirs(directory_models, exist_ok=True)
121
  directory_loras = 'loras'
 
123
  directory_vaes = 'vaes'
124
  os.makedirs(directory_vaes, exist_ok=True)
125
 
126
+ # LOAD ALL ENV TOKEN
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  CIVITAI_API_KEY: str = os.environ.get("CIVITAI_API_KEY")
128
  hf_token: str = os.environ.get("HF_TOKEN")
129
 
130
  # Download stuffs
131
  for url in [url.strip() for url in download_model.split(',')]:
132
  if not os.path.exists(f"./models/{url.split('/')[-1]}"):
133
+ download_things(
134
+ directory_models,
135
+ url,
136
+ hf_token,
137
+ CIVITAI_API_KEY
138
+ )
139
  for url in [url.strip() for url in download_vae.split(',')]:
140
  if not os.path.exists(f"./vaes/{url.split('/')[-1]}"):
141
+ download_things(
142
+ directory_vaes,
143
+ url,
144
+ hf_token,
145
+ CIVITAI_API_KEY
146
+ )
147
  for url in [url.strip() for url in download_lora.split(',')]:
148
  if not os.path.exists(f"./loras/{url.split('/')[-1]}"):
149
+ download_things(
150
+ directory_loras,
151
+ url,
152
+ hf_token,
153
+ CIVITAI_API_KEY
154
+ )
155
 
156
  # Download Embeddings
157
  directory_embeds = 'embedings'
158
+ os.makedirs(
159
+ directory_embeds,
160
+ exist_ok=True
161
+ )
162
  download_embeds = [
163
  'https://huggingface.co/datasets/Nerfgun3/bad_prompt/blob/main/bad_prompt_version2.pt',
164
  'https://huggingface.co/embed/negative/resolve/main/EasyNegativeV2.safetensors',
 
167
 
168
  for url_embed in download_embeds:
169
  if not os.path.exists(f"./embedings/{url_embed.split('/')[-1]}"):
170
+ download_things(
171
+ directory_embeds,
172
+ url_embed,
173
+ hf_token,
174
+ CIVITAI_API_KEY
175
+ )
176
 
177
  # Build list models
178
  embed_list = get_model_list(directory_embeds)
 
187
  def get_my_lora(link_url):
188
  for url in [url.strip() for url in link_url.split(',')]:
189
  if not os.path.exists(f"./loras/{url.split('/')[-1]}"):
190
+ download_things(
191
+ directory_loras,
192
+ url,
193
+ hf_token,
194
+ CIVITAI_API_KEY
195
+ )
196
  new_lora_model_list = get_model_list(directory_loras)
197
  new_lora_model_list.insert(0, "None")
198
 
 
206
  choices=new_lora_model_list
207
  ), gr.update(
208
  choices=new_lora_model_list
209
+ )
210
 
211
 
212
  print('\033[33m🏁 Download and listing of valid models completed.\033[0m')
213
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
  def extract_parameters(input_string):
215
  parameters = {}
216
  input_string = input_string.replace("\n", "")
 
658
  # Maybe fix lora issue: 'Cannot copy out of meta tensor; no data!''
659
  self.model.pipe.to("cuda:0" if torch.cuda.is_available() else "cpu")
660
 
661
+ info_state = f"PROCESSING"
662
  for img, seed, data in self.model(**pipe_params):
663
+ info_state += "."
664
  if data:
665
  info_state = f"COMPLETED. Seeds: {str(seed)}"
666
  if vae_msg:
 
912
  vae_model_gui = gr.Dropdown(
913
  label="VAE Model",
914
  choices=vae_model_list,
915
+ value=vae_model_list[0]
916
  )
917
 
918
  with gr.Accordion("Hires fix", open=False, visible=True):
 
1537
  )
1538
 
1539
 
1540
+ def send_img(img_source, img_result) -> tuple:
1541
  return img_source, img_result
1542
 
1543
 
 
1662
  mode_ip2,
1663
  scale_ip2,
1664
  ],
1665
+ outputs=[
1666
+ result_images,
1667
+ actual_task_info
1668
+ ],
1669
  queue=True,
1670
  show_progress="minimal",
1671
  )
models/format_models.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FORMAT_MODELS: list = [
2
+ 'stabilityai/stable-diffusion-xl-base-1.0',
3
+ 'cagliostrolab/animagine-xl-3.1',
4
+ 'misri/epicrealismXL_v7FinalDestination',
5
+ 'misri/juggernautXL_juggernautX',
6
+ 'misri/zavychromaxl_v80',
7
+ 'SG161222/RealVisXL_V4.0',
8
+ 'misri/newrealityxlAllInOne_Newreality40',
9
+ 'eienmojiki/Anything-XL',
10
+ 'eienmojiki/Starry-XL-v5.2',
11
+ 'gsdf/CounterfeitXL',
12
+ 'kitty7779/ponyDiffusionV6XL',
13
+ 'John6666/ebara-mfcg-pony-mix-v12-sdxl',
14
+ 'John6666/t-ponynai3-v51-sdxl',
15
+ 'yodayo-ai/kivotos-xl-2.0',
16
+ 'yodayo-ai/holodayo-xl-2.1',
17
+ 'digiplay/majicMIX_sombre_v2',
18
+ 'digiplay/majicMIX_realistic_v6',
19
+ 'digiplay/majicMIX_realistic_v7',
20
+ 'digiplay/DreamShaper_8',
21
+ 'digiplay/BeautifulArt_v1',
22
+ 'digiplay/DarkSushi2.5D_v1',
23
+ 'digiplay/darkphoenix3D_v1.1',
24
+ 'digiplay/BeenYouLiteL11_diffusers',
25
+ 'rubbrband/revAnimated_v2Rebirth',
26
+ 'youknownothing/cyberrealistic_v50',
27
+ 'votepurchase/counterfeitV30_v30',
28
+ 'Meina/MeinaMix_V11',
29
+ 'Meina/MeinaUnreal_V5',
30
+ 'Meina/MeinaPastel_V7',
31
+ 'rubbrband/realcartoon3d_v16',
32
+ 'rubbrband/realcartoonRealistic_v14',
33
+ ]
models/loras.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ LORA_LIST = (
2
+ "https://civitai.com/api/download/models/423719, "
3
+ "https://civitai.com/api/download/models/50503, "
4
+ "https://civitai.com/api/download/models/133160, "
5
+ "https://civitai.com/api/download/models/29332, "
6
+ "https://huggingface.co/Leopain/color/resolve/main/Coloring_book_-_LineArt.safetensors, "
7
+ "https://civitai.com/api/download/models/135867, "
8
+ "https://civitai.com/api/download/models/145907, "
9
+ "https://huggingface.co/Linaqruf/anime-detailer-xl-lora/resolve/main/anime-detailer-xl.safetensors?download=true, "
10
+ "https://huggingface.co/Linaqruf/style-enhancer-xl-lora/resolve/main/style-enhancer-xl.safetensors?download=true, "
11
+ "https://civitai.com/api/download/models/28609, "
12
+ "https://huggingface.co/ByteDance/Hyper-SD/resolve/main/Hyper-SD15-8steps-CFG-lora.safetensors?download=true, "
13
+ "https://huggingface.co/ByteDance/Hyper-SD/resolve/main/Hyper-SDXL-8steps-CFG-lora.safetensors?download=true, "
14
+ "https://civitai.com/api/download/models/30666 "
15
+ )
models/upscaler.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ upscaler_dict_gui: dict = {
2
+ None: None,
3
+ "Lanczos": "Lanczos",
4
+ "Nearest": "Nearest",
5
+ "RealESRGAN_x4plus": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth",
6
+ "RealESRNet_x4plus": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.1/RealESRNet_x4plus.pth",
7
+ "RealESRGAN_x4plus_anime_6B": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth",
8
+ "RealESRGAN_x2plus": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth",
9
+ "realesr-animevideov3": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-animevideov3.pth",
10
+ "realesr-general-x4v3": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-x4v3.pth",
11
+ "realesr-general-wdn-x4v3": "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.5.0/realesr-general-wdn-x4v3.pth",
12
+ "4x-UltraSharp": "https://huggingface.co/Shandypur/ESRGAN-4x-UltraSharp/resolve/main/4x-UltraSharp.pth",
13
+ "4x_foolhardy_Remacri": "https://huggingface.co/FacehugmanIII/4x_foolhardy_Remacri/resolve/main/4x_foolhardy_Remacri.pth",
14
+ "Remacri4xExtraSmoother": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/Remacri%204x%20ExtraSmoother.pth",
15
+ "AnimeSharp4x": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/AnimeSharp%204x.pth",
16
+ "lollypop": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/lollypop.pth",
17
+ "RealisticRescaler4x": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/RealisticRescaler%204x.pth",
18
+ "NickelbackFS4x": "https://huggingface.co/hollowstrawberry/upscalers-backup/resolve/main/ESRGAN/NickelbackFS%204x.pth"
19
+ }
utils/download_utils.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def download_things(
2
+ directory: str,
3
+ url: str,
4
+ hf_token: str = "",
5
+ civitai_api_key: str = ""):
6
+ """
7
+ :param directory: String, directory to save the downloaded file
8
+ :param url: String, URL to download the file from
9
+ :param hf_token: String, Hugging Face API token
10
+ :param civitai_api_key: String, Civitai API key
11
+ """
12
+ import os
13
+ url = url.strip()
14
+
15
+ if "drive.google.com" in url:
16
+ original_dir = os.getcwd()
17
+ os.chdir(directory)
18
+ os.system(f"gdown --fuzzy {url}")
19
+ os.chdir(original_dir)
20
+ elif "huggingface.co" in url:
21
+ url = url.replace("?download=true", "")
22
+ # url = urllib.parse.quote(url, safe=':/') # fix encoding
23
+ if "/blob/" in url:
24
+ url = url.replace("/blob/", "/resolve/")
25
+ user_header = f'"Authorization: Bearer {hf_token}"'
26
+ if hf_token:
27
+ os.system(
28
+ f"aria2c --console-log-level=error --summary-interval=10 --header={user_header} -c -x 16 -k 1M -s 16 {url} -d {directory} -o {url.split('/')[-1]}")
29
+ else:
30
+ os.system(
31
+ f"aria2c --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -c -x 16 -k "
32
+ f"1M -s 16 {url} -d {directory} -o {url.split('/')[-1]}")
33
+ elif "civitai.com" in url:
34
+ if "?" in url:
35
+ url = url.split("?")[0]
36
+ if civitai_api_key:
37
+ url = url + f"?token={civitai_api_key}"
38
+ os.system(
39
+ f"aria2c --console-log-level=error --summary-interval=10 -c -x 16 -k 1M -s 16 -d {directory} {url}")
40
+ else:
41
+ print("\033[91mYou need an API key to download Civitai models.\033[0m")
42
+ else:
43
+ os.system(f"aria2c --console-log-level=error --summary-interval=10 -c -x 16 -k 1M -s 16 -d {directory} {url}")
utils/model_utils.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def get_model_list(directory_path):
2
+ import os
3
+ model_list: list = []
4
+ valid_extensions = {
5
+ '.ckpt',
6
+ '.pt',
7
+ '.pth',
8
+ '.safetensors',
9
+ '.bin'
10
+ }
11
+
12
+ for filename in os.listdir(directory_path):
13
+ if os.path.splitext(filename)[1] in valid_extensions:
14
+ name_without_extension = os.path.splitext(filename)[0]
15
+ file_path = os.path.join(directory_path, filename)
16
+ # model_list.append((name_without_extension, file_path))
17
+ model_list.append(file_path)
18
+ print('\033[34mFILE: ' + file_path + '\033[0m')
19
+ return model_list
utils/string_utils.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def process_string(input_string: str):
2
+ """
3
+ :param input_string:
4
+ :return:
5
+ """
6
+ parts = input_string.split('/')
7
+
8
+ if len(parts) == 2:
9
+ first_element = parts[1]
10
+ complete_string = input_string
11
+ result = (first_element, complete_string)
12
+ return result
13
+ else:
14
+ return None