gokaygokay commited on
Commit
25adc0c
1 Parent(s): b97d3bc

Update app.py

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