gokaygokay commited on
Commit
e3799c1
β€’
1 Parent(s): 5f1b905

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -85
app.py CHANGED
@@ -15,7 +15,11 @@ import gradio as gr
15
  USE_TORCH_COMPILE = 0
16
  ENABLE_CPU_OFFLOAD = 0
17
 
18
- # Function to download files
 
 
 
 
19
  def download_file(url, folder_path, filename):
20
  if not os.path.exists(folder_path):
21
  os.makedirs(folder_path)
@@ -34,73 +38,26 @@ def download_file(url, folder_path, filename):
34
  print(f"Error downloading the file. Status code: {response.status_code}")
35
 
36
  # Download necessary models and files
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
 
39
-
40
- # MODEL
41
- download_file(
42
- "https://huggingface.co/dantea1118/juggernaut_reborn/resolve/main/juggernaut_reborn.safetensors?download=true",
43
- "models/models/Stable-diffusion",
44
- "juggernaut_reborn.safetensors"
45
- )
46
-
47
- # UPSCALER
48
-
49
- download_file(
50
- "https://huggingface.co/ai-forever/Real-ESRGAN/resolve/main/RealESRGAN_x2.pth?download=true",
51
- "models/upscalers/",
52
- "RealESRGAN_x2.pth"
53
- )
54
-
55
- download_file(
56
- "https://huggingface.co/ai-forever/Real-ESRGAN/resolve/main/RealESRGAN_x4.pth?download=true",
57
- "models/upscalers/",
58
- "RealESRGAN_x4.pth"
59
- )
60
-
61
- # NEGATIVE
62
- download_file(
63
- "https://huggingface.co/philz1337x/embeddings/resolve/main/verybadimagenegative_v1.3.pt?download=true",
64
- "models/embeddings",
65
- "verybadimagenegative_v1.3.pt"
66
- )
67
- download_file(
68
- "https://huggingface.co/datasets/AddictiveFuture/sd-negative-embeddings/resolve/main/JuggernautNegative-neg.pt?download=true",
69
- "models/embeddings",
70
- "JuggernautNegative-neg.pt"
71
- )
72
-
73
- # LORA
74
-
75
- download_file(
76
- "https://huggingface.co/philz1337x/loras/resolve/main/SDXLrender_v2.0.safetensors?download=true",
77
- "models/Lora",
78
- "SDXLrender_v2.0.safetensors"
79
- )
80
- download_file(
81
- "https://huggingface.co/philz1337x/loras/resolve/main/more_details.safetensors?download=true",
82
- "models/Lora",
83
- "more_details.safetensors"
84
- )
85
-
86
- # CONTROLNET
87
-
88
- download_file(
89
- "https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile.pth?download=true",
90
- "models/ControlNet",
91
- "control_v11f1e_sd15_tile.pth"
92
- )
93
-
94
- # VAE
95
-
96
- download_file(
97
- "https://huggingface.co/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.safetensors?download=true",
98
- "models/VAE",
99
- "vae-ft-mse-840000-ema-pruned.safetensors"
100
- )
101
 
102
- # Set up the device
103
- device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
104
 
105
  class LazyRealESRGAN:
106
  def __init__(self, device, scale):
@@ -215,26 +172,7 @@ class ImageProcessor:
215
 
216
  return pipe
217
 
218
- def process_image(self, input_image, prompt, negative_prompt, resolution=2048, num_inference_steps=50, guidance_scale=3, strength=0.35, hdr=0):
219
- condition_image = resize_and_upscale(input_image, resolution)
220
- condition_image = create_hdr_effect(condition_image, hdr)
221
-
222
- result = self.pipe(
223
- prompt=prompt,
224
- negative_prompt=negative_prompt,
225
- image=condition_image,
226
- control_image=condition_image,
227
- width=condition_image.size[0],
228
- height=condition_image.size[1],
229
- strength=strength,
230
- num_inference_steps=num_inference_steps,
231
- guidance_scale=guidance_scale,
232
- generator=torch.manual_seed(0),
233
- ).images[0]
234
-
235
- return result
236
-
237
- # Create an instance of ImageProcessor
238
  image_processor = ImageProcessor()
239
 
240
  @spaces.GPU
 
15
  USE_TORCH_COMPILE = 0
16
  ENABLE_CPU_OFFLOAD = 0
17
 
18
+ # Set up the device
19
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
20
+
21
+
22
+ # Function to download files (from the example)
23
  def download_file(url, folder_path, filename):
24
  if not os.path.exists(folder_path):
25
  os.makedirs(folder_path)
 
38
  print(f"Error downloading the file. Status code: {response.status_code}")
39
 
40
  # Download necessary models and files
41
+ def download_models():
42
+ models = {
43
+ "MODEL": ("https://huggingface.co/dantea1118/juggernaut_reborn/resolve/main/juggernaut_reborn.safetensors?download=true", "models/models/Stable-diffusion", "juggernaut_reborn.safetensors"),
44
+ "UPSCALER_X2": ("https://huggingface.co/ai-forever/Real-ESRGAN/resolve/main/RealESRGAN_x2.pth?download=true", "models/upscalers/", "RealESRGAN_x2.pth"),
45
+ "UPSCALER_X4": ("https://huggingface.co/ai-forever/Real-ESRGAN/resolve/main/RealESRGAN_x4.pth?download=true", "models/upscalers/", "RealESRGAN_x4.pth"),
46
+ "NEGATIVE_1": ("https://huggingface.co/philz1337x/embeddings/resolve/main/verybadimagenegative_v1.3.pt?download=true", "models/embeddings", "verybadimagenegative_v1.3.pt"),
47
+ "NEGATIVE_2": ("https://huggingface.co/datasets/AddictiveFuture/sd-negative-embeddings/resolve/main/JuggernautNegative-neg.pt?download=true", "models/embeddings", "JuggernautNegative-neg.pt"),
48
+ "LORA_1": ("https://huggingface.co/philz1337x/loras/resolve/main/SDXLrender_v2.0.safetensors?download=true", "models/Lora", "SDXLrender_v2.0.safetensors"),
49
+ "LORA_2": ("https://huggingface.co/philz1337x/loras/resolve/main/more_details.safetensors?download=true", "models/Lora", "more_details.safetensors"),
50
+ "CONTROLNET": ("https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile.pth?download=true", "models/ControlNet", "control_v11f1e_sd15_tile.pth"),
51
+ "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"),
52
+ }
53
+
54
+ for model, (url, folder, filename) in models.items():
55
+ download_file(url, folder, filename)
56
+
57
+ download_models()
58
 
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
 
 
61
 
62
  class LazyRealESRGAN:
63
  def __init__(self, device, scale):
 
172
 
173
  return pipe
174
 
175
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
  image_processor = ImageProcessor()
177
 
178
  @spaces.GPU