Spaces:
Running on Zero
Running on Zero
Restore multiple style selection in Space
Browse files- README.md +3 -2
- app.py +1 -1
- hf_space.py +11 -5
- tests/test_hf_space.py +24 -0
README.md
CHANGED
|
@@ -23,8 +23,9 @@ Space repository. The Space builds from the root `requirements.txt` and starts
|
|
| 23 |
|
| 24 |
The Space offers text-to-image generation, one image per request, style
|
| 25 |
selection, negative prompts, seed, dimensions, steps, guidance, and a model
|
| 26 |
-
picker. It loads SDXL Base 1.0 from Hugging Face at
|
| 27 |
-
Ragnarok checkpoint is absent at startup, it
|
|
|
|
| 28 |
checkpoint version (`1759168`) and verifies its SHA-256 before loading it.
|
| 29 |
Subsequent requests reuse the cached file while the Space disk remains intact.
|
| 30 |
The optional `CIVITAI_TOKEN` Space secret is sent as a bearer token if Civitai
|
|
|
|
| 23 |
|
| 24 |
The Space offers text-to-image generation, one image per request, style
|
| 25 |
selection, negative prompts, seed, dimensions, steps, guidance, and a model
|
| 26 |
+
picker and multi-style selection. It loads SDXL Base 1.0 from Hugging Face at
|
| 27 |
+
startup. If the Juggernaut XL Ragnarok checkpoint is absent at startup, it
|
| 28 |
+
downloads the matching Civitai
|
| 29 |
checkpoint version (`1759168`) and verifies its SHA-256 before loading it.
|
| 30 |
Subsequent requests reuse the cached file while the Space disk remains intact.
|
| 31 |
The optional `CIVITAI_TOKEN` Space secret is sent as a bearer token if Civitai
|
app.py
CHANGED
|
@@ -77,7 +77,7 @@ with gr.Blocks(title="RuinedFooocus · ZeroGPU") as demo:
|
|
| 77 |
with gr.Column():
|
| 78 |
prompt = gr.Textbox(label="Prompt", lines=4, placeholder="Describe the image you want to create")
|
| 79 |
negative_prompt = gr.Textbox(label="Negative prompt", lines=2)
|
| 80 |
-
style = gr.Dropdown(choices=list(STYLES), value=
|
| 81 |
model = gr.Dropdown(choices=MODEL_CHOICES, value=RAGNAROK if RAGNAROK in PIPELINES else SDXL_BASE, label="Model")
|
| 82 |
model_status = gr.Markdown()
|
| 83 |
with gr.Row():
|
|
|
|
| 77 |
with gr.Column():
|
| 78 |
prompt = gr.Textbox(label="Prompt", lines=4, placeholder="Describe the image you want to create")
|
| 79 |
negative_prompt = gr.Textbox(label="Negative prompt", lines=2)
|
| 80 |
+
style = gr.Dropdown(choices=list(STYLES), value=[], multiselect=True, label="Style Selection")
|
| 81 |
model = gr.Dropdown(choices=MODEL_CHOICES, value=RAGNAROK if RAGNAROK in PIPELINES else SDXL_BASE, label="Model")
|
| 82 |
model_status = gr.Markdown()
|
| 83 |
with gr.Row():
|
hf_space.py
CHANGED
|
@@ -55,11 +55,17 @@ def prepare_prompts(prompt, negative_prompt, style, seed, styles):
|
|
| 55 |
prompt = str(prompt).strip()
|
| 56 |
if not prompt:
|
| 57 |
raise ValueError("Enter a prompt before generating.")
|
| 58 |
-
if style
|
| 59 |
-
|
|
|
|
|
|
|
| 60 |
rng = random.Random(seed)
|
| 61 |
prompt = expand_wildcards(prompt, rng)
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
return styled_prompt, ", ".join(negatives)
|
|
|
|
| 55 |
prompt = str(prompt).strip()
|
| 56 |
if not prompt:
|
| 57 |
raise ValueError("Enter a prompt before generating.")
|
| 58 |
+
selected_styles = [style] if isinstance(style, str) else list(style or [])
|
| 59 |
+
for selected_style in selected_styles:
|
| 60 |
+
if selected_style not in styles:
|
| 61 |
+
raise ValueError(f"Unknown style: {selected_style}")
|
| 62 |
rng = random.Random(seed)
|
| 63 |
prompt = expand_wildcards(prompt, rng)
|
| 64 |
+
styled_prompt = prompt
|
| 65 |
+
negatives = [negative_prompt.strip()] if negative_prompt and negative_prompt.strip() else []
|
| 66 |
+
for selected_style in selected_styles:
|
| 67 |
+
template, style_negative = styles[selected_style]
|
| 68 |
+
styled_prompt = template.replace("{prompt}", styled_prompt)
|
| 69 |
+
if style_negative and style_negative.strip():
|
| 70 |
+
negatives.append(style_negative.strip())
|
| 71 |
return styled_prompt, ", ".join(negatives)
|
tests/test_hf_space.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import unittest
|
| 2 |
+
|
| 3 |
+
from hf_space import prepare_prompts
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class PromptStylesTests(unittest.TestCase):
|
| 7 |
+
def test_combines_selected_styles_and_negative_prompts(self):
|
| 8 |
+
styles = {
|
| 9 |
+
"one": ("oil painting of {prompt}", "blurry"),
|
| 10 |
+
"two": ("dramatic {prompt}", "low contrast"),
|
| 11 |
+
}
|
| 12 |
+
positive, negative = prepare_prompts("a fox", "grainy", ["one", "two"], 42, styles)
|
| 13 |
+
self.assertEqual(positive, "dramatic oil painting of a fox")
|
| 14 |
+
self.assertEqual(negative, "grainy, blurry, low contrast")
|
| 15 |
+
|
| 16 |
+
def test_preserves_single_style_calls(self):
|
| 17 |
+
self.assertEqual(
|
| 18 |
+
prepare_prompts("a fox", "", "one", 42, {"one": ("{prompt} in snow", "")}),
|
| 19 |
+
("a fox in snow", ""),
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
if __name__ == "__main__":
|
| 24 |
+
unittest.main()
|