gokaygokay commited on
Commit
1687d92
1 Parent(s): dcd6781

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -28
app.py CHANGED
@@ -20,43 +20,28 @@ from RealESRGAN import RealESRGAN
20
  import gradio as gr
21
  from gradio_imageslider import ImageSlider
22
 
 
 
23
  USE_TORCH_COMPILE = False
24
  ENABLE_CPU_OFFLOAD = os.getenv("ENABLE_CPU_OFFLOAD", "0") == "1"
25
 
26
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
27
 
28
- def download_file(url, folder_path, filename):
29
- if not os.path.exists(folder_path):
30
- os.makedirs(folder_path)
31
- file_path = os.path.join(folder_path, filename)
32
-
33
- if os.path.isfile(file_path):
34
- print(f"File already exists: {file_path}")
35
- else:
36
- response = requests.get(url, stream=True)
37
- if response.status_code == 200:
38
- with open(file_path, 'wb') as file:
39
- for chunk in response.iter_content(chunk_size=1024):
40
- file.write(chunk)
41
- print(f"File successfully downloaded and saved: {file_path}")
42
- else:
43
- print(f"Error downloading the file. Status code: {response.status_code}")
44
-
45
  def download_models():
46
  models = {
47
- "MODEL": ("https://huggingface.co/dantea1118/juggernaut_reborn/resolve/main/juggernaut_reborn.safetensors?download=true", "models/models/Stable-diffusion", "juggernaut_reborn.safetensors"),
48
- "UPSCALER_X2": ("https://huggingface.co/ai-forever/Real-ESRGAN/resolve/main/RealESRGAN_x2.pth?download=true", "models/upscalers/", "RealESRGAN_x2.pth"),
49
- "UPSCALER_X4": ("https://huggingface.co/ai-forever/Real-ESRGAN/resolve/main/RealESRGAN_x4.pth?download=true", "models/upscalers/", "RealESRGAN_x4.pth"),
50
- "NEGATIVE_1": ("https://huggingface.co/philz1337x/embeddings/resolve/main/verybadimagenegative_v1.3.pt?download=true", "models/embeddings", "verybadimagenegative_v1.3.pt"),
51
- "NEGATIVE_2": ("https://huggingface.co/datasets/AddictiveFuture/sd-negative-embeddings/resolve/main/JuggernautNegative-neg.pt?download=true", "models/embeddings", "JuggernautNegative-neg.pt"),
52
- "LORA_1": ("https://huggingface.co/philz1337x/loras/resolve/main/SDXLrender_v2.0.safetensors?download=true", "models/Lora", "SDXLrender_v2.0.safetensors"),
53
- "LORA_2": ("https://huggingface.co/philz1337x/loras/resolve/main/more_details.safetensors?download=true", "models/Lora", "more_details.safetensors"),
54
- "CONTROLNET": ("https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile.pth?download=true", "models/ControlNet", "control_v11f1e_sd15_tile.pth"),
55
- "VAE": ("https://huggingface.co/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.safetensors?download=true", "models/VAE", "vae-ft-mse-840000-ema-pruned.safetensors"),
56
  }
57
 
58
- for model, (url, folder, filename) in models.items():
59
- download_file(url, folder, filename)
60
 
61
  download_models()
62
 
 
20
  import gradio as gr
21
  from gradio_imageslider import ImageSlider
22
 
23
+ from huggingface_hub import hf_hub_download
24
+
25
  USE_TORCH_COMPILE = False
26
  ENABLE_CPU_OFFLOAD = os.getenv("ENABLE_CPU_OFFLOAD", "0") == "1"
27
 
28
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  def download_models():
31
  models = {
32
+ "MODEL": ("dantea1118/juggernaut_reborn", "juggernaut_reborn.safetensors", "models/models/Stable-diffusion"),
33
+ "UPSCALER_X2": ("ai-forever/Real-ESRGAN", "RealESRGAN_x2.pth", "models/upscalers/"),
34
+ "UPSCALER_X4": ("ai-forever/Real-ESRGAN", "RealESRGAN_x4.pth", "models/upscalers/"),
35
+ "NEGATIVE_1": ("philz1337x/embeddings", "verybadimagenegative_v1.3.pt", "models/embeddings"),
36
+ "NEGATIVE_2": ("philz1337x/embeddings", "JuggernautNegative-neg.pt", "models/embeddings"),
37
+ "LORA_1": ("philz1337x/loras", "SDXLrender_v2.0.safetensors", "models/Lora"),
38
+ "LORA_2": ("philz1337x/loras", "more_details.safetensors", "models/Lora"),
39
+ "CONTROLNET": ("lllyasviel/ControlNet-v1-1", "control_v11f1e_sd15_tile.pth", "models/ControlNet"),
40
+ "VAE": ("stabilityai/sd-vae-ft-mse-original", "vae-ft-mse-840000-ema-pruned.safetensors", "models/VAE"),
41
  }
42
 
43
+ for model, (repo_id, filename, local_dir) in models.items():
44
+ hf_hub_download(repo_id=repo_id, filename=filename, local_dir=local_dir)
45
 
46
  download_models()
47