Files changed (1) hide show
  1. app.py +9 -105
app.py CHANGED
@@ -1,110 +1,14 @@
1
- import gradio as gr
2
- import spaces
3
- import torch
4
-
5
-
6
- #@spaces.GPU
7
- #def greet(n):
8
- # print(zero.device) # <-- 'cuda:0' 🤗
9
- # return f"Hello {zero + n} Tensor"
10
-
11
- #demo = gr.Interface(fn=greet, inputs=gr.Number(), outputs=gr.Text())
12
- #demo.launch()
13
-
14
  import os
15
- import subprocess
16
- import urllib.request
17
- import torch
18
- zero = torch.Tensor([0]).cuda()
19
- print(zero.device) # <-- 'cpu' 🤔
20
- print("Torch version:", torch.__version__)
21
- if torch.cuda.is_available():
22
- cap = torch.cuda.get_device_capability(0)
23
- print("CUDA device capability:", cap)
24
- else:
25
- print("CUDA is not available!")
26
-
27
- import subprocess
28
-
29
- try:
30
- result = subprocess.run(["nvidia-smi"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True)
31
- print("nvidia-smi output:\n", result.stdout.decode())
32
- except Exception as e:
33
- print("Error running nvidia-smi:", e)
34
-
35
-
36
- # --------- Step 1: Clone the Repository (if not already present) ---------
37
- if not os.path.exists("stable-diffusion-webui-forge"):
38
- print("Cloning stable-diffusion-webui-forge repository...")
39
- subprocess.run(["git", "clone", "https://github.com/lllyasviel/stable-diffusion-webui-forge"], check=True)
40
- else:
41
- print("stable-diffusion-webui-forge repository already exists.")
42
-
43
-
44
 
45
- # --------- Step 2: Define Directories and Ensure They Exist ---------
46
- BASE_DIR = os.getcwd()
47
- SD_UI_DIR = os.path.join(BASE_DIR, "stable-diffusion-webui-forge")
48
- STABLE_DIFF_DIR = os.path.join(SD_UI_DIR, "models", "Stable-diffusion")
49
- VAE_DIR = os.path.join(SD_UI_DIR, "models", "VAE")
50
- LORA_DIR = os.path.join(SD_UI_DIR, "models", "Lora")
51
 
52
- os.makedirs(STABLE_DIFF_DIR, exist_ok=True)
53
- os.makedirs(VAE_DIR, exist_ok=True)
54
- os.makedirs(LORA_DIR, exist_ok=True)
55
-
56
- # --------- Step 3: Define Model URLs ---------
57
- EDEN_URL = "https://edenartlab-lfs.s3.amazonaws.com/models/checkpoints/Eden_SDXL.safetensors"
58
- JUG_URL = "https://huggingface.co/KamCastle/jugg/resolve/main/juggernaut_reborn.safetensors"
59
- SDXL_URL = "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors?download=true"
60
- FLUX1_DEV_URL = "https://huggingface.co/lllyasviel/flux1-dev-bnb-nf4/resolve/main/flux1-dev-bnb-nf4-v2.safetensors"
61
- VAE_URL = "https://huggingface.co/stabilityai/sdxl-vae/resolve/main/sdxl_vae.safetensors"
62
- LORA_FAE_URL = "https://huggingface.co/kayte0342/eden_fae/resolve/main/fairy_punk_sdxl_lora.safetensors?download=true"
63
- LORA_KAYTE_EDEN_URL = "https://huggingface.co/kayte0342/kayte_eden/resolve/main/kayte_sdxl_lora.safetensors?download=true"
64
- LORA_KAYTE_SD_URL = "https://huggingface.co/kayte0342/kayte_eden/resolve/main/kayteSD.safetensors?download=true"
65
- LORA_KAYTE_FLUX_URL = "https://huggingface.co/kayte0342/kayte_flux/resolve/main/kayte_epoch_3.safetensors?download=true"
66
- LORA_FAE_FLUX_URL = "https://huggingface.co/kayte0342/fairycore_flux/blob/main/fairy-core_epoch_4.safetensors"
67
-
68
- # --------- Helper Function to Download a File ---------
69
- def download_model(url, output_path):
70
- if not os.path.exists(output_path):
71
- print(f"Downloading {url} to {output_path}...")
72
- urllib.request.urlretrieve(url, output_path)
73
- else:
74
- print(f"File {output_path} already exists.")
75
-
76
- # --------- Step 4: Download Models ---------
77
- # Stable Diffusion weights
78
- download_model(EDEN_URL, os.path.join(STABLE_DIFF_DIR, "Eden_SDXL.safetensors"))
79
- download_model(JUG_URL, os.path.join(STABLE_DIFF_DIR, "juggernaut_reborn.safetensors"))
80
- download_model(SDXL_URL, os.path.join(STABLE_DIFF_DIR, "stable-diffusion-XL.safetensors"))
81
- download_model(FLUX1_DEV_URL, os.path.join(STABLE_DIFF_DIR, "flux1-dev-bnb-nf4-v2.safetensors"))
82
-
83
- # VAE model
84
- download_model(VAE_URL, os.path.join(VAE_DIR, "sdxl_vae.safetensors"))
85
-
86
- # LoRA models
87
- download_model(LORA_FAE_URL, os.path.join(LORA_DIR, "fae_sdxl.safetensors"))
88
- download_model(LORA_KAYTE_EDEN_URL, os.path.join(LORA_DIR, "kayte_eden.safetensors"))
89
- download_model(LORA_KAYTE_SD_URL, os.path.join(LORA_DIR, "kayte_SD.safetensors"))
90
- download_model(LORA_KAYTE_FLUX_URL, os.path.join(LORA_DIR, "kayte_epoch_3.safetensors"))
91
- download_model(LORA_FAE_FLUX_URL, os.path.join(LORA_DIR, "fairy-core_epoch_4.safetensors"))
92
 
93
- # --------- Step 5: Launch the Forge Web UI ---------
94
- # Get the port from the environment (Spaces sets PORT), default to 7860 if not set.
95
  port = int(os.environ.get("PORT", 7860))
96
-
97
- # Change directory to the stable-diffusion-webui-forge folder
98
- os.chdir(SD_UI_DIR)
99
-
100
- # Construct the command to launch the web UI.
101
- # Note: Remove the '--share' flag since Spaces provides a public URL.
102
- launch_command = [
103
- "python", "launch.py",
104
- f"--port={port}",
105
- "--host=0.0.0.0"
106
- ]
107
-
108
- print("Launching stable-diffusion-webui-forge with command:")
109
- print(" ".join(launch_command))
110
- subprocess.run(launch_command, check=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
+ import sys
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
+ # Ensure the repository is in the Python path
5
+ repo_path = os.path.join(os.getcwd(), "stable-diffusion-webui-forge")
6
+ sys.path.insert(0, repo_path)
 
 
 
7
 
8
+ try:
9
+ from launch import demo
10
+ except ImportError:
11
+ raise ImportError("Could not import 'demo' from launch.py. Please check if the repository exposes a Gradio interface.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
 
 
13
  port = int(os.environ.get("PORT", 7860))
14
+ demo.launch(server_name="0.0.0.0", server_port=port)