Spaces:
Running
on
Zero
Running
on
Zero
Tanut
commited on
Commit
·
0e6feda
1
Parent(s):
6400e55
Testing 2 Stable Diffusion
Browse files
app.py
CHANGED
@@ -15,10 +15,19 @@ from diffusers import (
|
|
15 |
# Quiet matplotlib cache warning on Spaces
|
16 |
os.environ.setdefault("MPLCONFIGDIR", "/tmp/mpl")
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
# ---- base models for the two tabs ----
|
19 |
BASE_MODELS = {
|
20 |
"stable-diffusion-v1-5": "runwayml/stable-diffusion-v1-5",
|
21 |
-
"dream":
|
22 |
}
|
23 |
|
24 |
# ControlNet (QR Monster v2 for SD15)
|
@@ -88,7 +97,12 @@ def _base_scheduler_for(pipe):
|
|
88 |
def get_cn():
|
89 |
global _CN
|
90 |
if _CN is None:
|
91 |
-
_CN = ControlNetModel.from_pretrained(
|
|
|
|
|
|
|
|
|
|
|
92 |
return _CN
|
93 |
|
94 |
def get_qrmon_txt2img_pipe(model_id: str):
|
@@ -100,6 +114,7 @@ def get_qrmon_txt2img_pipe(model_id: str):
|
|
100 |
safety_checker=None,
|
101 |
use_safetensors=True,
|
102 |
low_cpu_mem_usage=True,
|
|
|
103 |
)
|
104 |
_CN_TXT2IMG[model_id] = _base_scheduler_for(pipe)
|
105 |
return _CN_TXT2IMG[model_id]
|
@@ -113,6 +128,7 @@ def get_qrmon_img2img_pipe(model_id: str):
|
|
113 |
safety_checker=None,
|
114 |
use_safetensors=True,
|
115 |
low_cpu_mem_usage=True,
|
|
|
116 |
)
|
117 |
_CN_IMG2IMG[model_id] = _base_scheduler_for(pipe)
|
118 |
return _CN_IMG2IMG[model_id]
|
@@ -196,7 +212,7 @@ def qr_txt2img_dream(*args):
|
|
196 |
with gr.Blocks() as demo:
|
197 |
gr.Markdown("# ZeroGPU • Method 1: QR Control (two base models)")
|
198 |
|
199 |
-
# ---- Tab 1: stable-diffusion-v1-5
|
200 |
with gr.Tab("stable-diffusion-v1-5"):
|
201 |
url1 = gr.Textbox(label="URL/Text", value="http://www.mybirdfire.com")
|
202 |
s_prompt1 = gr.Textbox(label="Style prompt", value="japanese painting, elegant shrine and torii, distant mount fuji, autumn maple trees, warm sunlight, 1girl in kimono, highly detailed, intricate patterns, anime key visual, dramatic composition")
|
@@ -219,7 +235,7 @@ with gr.Blocks() as demo:
|
|
219 |
low_img1 = gr.Image(label="Low-res (Stage A) preview")
|
220 |
ctrl_img1 = gr.Image(label="Control QR used")
|
221 |
|
222 |
-
gr.Button("Generate with
|
223 |
qr_txt2img_anything,
|
224 |
[url1, s_prompt1, s_negative1, steps1, cfg1, size1, border1, qr_w1, seed1,
|
225 |
use_hires1, hires_up1, hires_str1, repair1, feather1],
|
@@ -257,4 +273,5 @@ with gr.Blocks() as demo:
|
|
257 |
)
|
258 |
|
259 |
if __name__ == "__main__":
|
|
|
260 |
demo.queue(max_size=12).launch()
|
|
|
15 |
# Quiet matplotlib cache warning on Spaces
|
16 |
os.environ.setdefault("MPLCONFIGDIR", "/tmp/mpl")
|
17 |
|
18 |
+
# ---- HF auth helper (works for public & private/gated repos) ----
|
19 |
+
def _hf_auth():
|
20 |
+
# Add this in Space Settings → Variables → New secret
|
21 |
+
# Name: HUGGINGFACE_HUB_TOKEN Value: <your HF token>
|
22 |
+
tok = os.getenv("HUGGINGFACE_HUB_TOKEN") or os.getenv("HF_TOKEN")
|
23 |
+
if not tok:
|
24 |
+
return {}
|
25 |
+
return {"token": tok, "use_auth_token": tok}
|
26 |
+
|
27 |
# ---- base models for the two tabs ----
|
28 |
BASE_MODELS = {
|
29 |
"stable-diffusion-v1-5": "runwayml/stable-diffusion-v1-5",
|
30 |
+
"dream": "Lykon/dreamshaper-8",
|
31 |
}
|
32 |
|
33 |
# ControlNet (QR Monster v2 for SD15)
|
|
|
97 |
def get_cn():
|
98 |
global _CN
|
99 |
if _CN is None:
|
100 |
+
_CN = ControlNetModel.from_pretrained(
|
101 |
+
CN_QRMON,
|
102 |
+
torch_dtype=DTYPE,
|
103 |
+
use_safetensors=True,
|
104 |
+
**_hf_auth()
|
105 |
+
)
|
106 |
return _CN
|
107 |
|
108 |
def get_qrmon_txt2img_pipe(model_id: str):
|
|
|
114 |
safety_checker=None,
|
115 |
use_safetensors=True,
|
116 |
low_cpu_mem_usage=True,
|
117 |
+
**_hf_auth()
|
118 |
)
|
119 |
_CN_TXT2IMG[model_id] = _base_scheduler_for(pipe)
|
120 |
return _CN_TXT2IMG[model_id]
|
|
|
128 |
safety_checker=None,
|
129 |
use_safetensors=True,
|
130 |
low_cpu_mem_usage=True,
|
131 |
+
**_hf_auth()
|
132 |
)
|
133 |
_CN_IMG2IMG[model_id] = _base_scheduler_for(pipe)
|
134 |
return _CN_IMG2IMG[model_id]
|
|
|
212 |
with gr.Blocks() as demo:
|
213 |
gr.Markdown("# ZeroGPU • Method 1: QR Control (two base models)")
|
214 |
|
215 |
+
# ---- Tab 1: stable-diffusion-v1-5 ----
|
216 |
with gr.Tab("stable-diffusion-v1-5"):
|
217 |
url1 = gr.Textbox(label="URL/Text", value="http://www.mybirdfire.com")
|
218 |
s_prompt1 = gr.Textbox(label="Style prompt", value="japanese painting, elegant shrine and torii, distant mount fuji, autumn maple trees, warm sunlight, 1girl in kimono, highly detailed, intricate patterns, anime key visual, dramatic composition")
|
|
|
235 |
low_img1 = gr.Image(label="Low-res (Stage A) preview")
|
236 |
ctrl_img1 = gr.Image(label="Control QR used")
|
237 |
|
238 |
+
gr.Button("Generate with stable-diffusion-v1-5").click(
|
239 |
qr_txt2img_anything,
|
240 |
[url1, s_prompt1, s_negative1, steps1, cfg1, size1, border1, qr_w1, seed1,
|
241 |
use_hires1, hires_up1, hires_str1, repair1, feather1],
|
|
|
273 |
)
|
274 |
|
275 |
if __name__ == "__main__":
|
276 |
+
# Private Spaces: no share=True
|
277 |
demo.queue(max_size=12).launch()
|