Spaces:
Running
on
Zero
Running
on
Zero
Upload app.py
Browse files
app.py
CHANGED
|
@@ -1874,9 +1874,44 @@ with gr.Blocks(theme=args.theme, elem_id="main", fill_width=True, fill_height=Fa
|
|
| 1874 |
copy_prompt_btn.click(gradio_copy_prompt, inputs=[output_text], outputs=[prompt_gui])
|
| 1875 |
copy_prompt_btn_pony.click(gradio_copy_prompt, inputs=[output_text_pony], outputs=[prompt_gui])
|
| 1876 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1877 |
gr.LoginButton()
|
| 1878 |
gr.DuplicateButton(value="Duplicate Space for private use (This demo does not work on CPU. Requires GPU Space)")
|
| 1879 |
|
|
|
|
| 1880 |
if __name__ == "__main__":
|
| 1881 |
app.queue()
|
| 1882 |
app.launch(
|
|
|
|
| 1874 |
copy_prompt_btn.click(gradio_copy_prompt, inputs=[output_text], outputs=[prompt_gui])
|
| 1875 |
copy_prompt_btn_pony.click(gradio_copy_prompt, inputs=[output_text_pony], outputs=[prompt_gui])
|
| 1876 |
|
| 1877 |
+
# Stable programmatic endpoint
|
| 1878 |
+
from typing import Any, Dict, List, Union, Generator
|
| 1879 |
+
Payload = Union[List[Any], Dict[str, Any]]
|
| 1880 |
+
|
| 1881 |
+
def generate_minimal(payload: Payload) -> Generator[Any, None, None]:
|
| 1882 |
+
# One-call wrapper: optionally preload a model, then delegate to the original generator.
|
| 1883 |
+
# Accepts EITHER:
|
| 1884 |
+
# - dict: {"args":[...full positional array...], "model_name":..., "vae_model":..., "task":..., "controlnet_model":...}
|
| 1885 |
+
# - list: [...full positional array...] (legacy, forwarded as-is)
|
| 1886 |
+
# Normalize input
|
| 1887 |
+
if isinstance(payload, dict):
|
| 1888 |
+
args = payload.get("args") or payload.get("data") or []
|
| 1889 |
+
m = payload.get("model_name")
|
| 1890 |
+
v = payload.get("vae_model")
|
| 1891 |
+
t = payload.get("task")
|
| 1892 |
+
c = payload.get("controlnet_model")
|
| 1893 |
+
# Optional preload if all four fields are present
|
| 1894 |
+
if all(x is not None for x in (m, v, t, c)):
|
| 1895 |
+
for _ in sd_gen.load_new_model(m, v, t, c):
|
| 1896 |
+
# If you want to stream loader status, you could `yield {"status": _}`
|
| 1897 |
+
pass
|
| 1898 |
+
else:
|
| 1899 |
+
# Legacy: payload is the full positional array already
|
| 1900 |
+
args = payload
|
| 1901 |
+
# Delegate to the existing streaming generator; preserves SSE behavior
|
| 1902 |
+
yield from sd_gen_generate_pipeline(*args)
|
| 1903 |
+
|
| 1904 |
+
gr.api(
|
| 1905 |
+
generate_minimal,
|
| 1906 |
+
api_name="generate",
|
| 1907 |
+
api_description="Accepts a list (positional) or a dict with {'args': [...]} + optional loader fields.",
|
| 1908 |
+
queue=True,
|
| 1909 |
+
)
|
| 1910 |
+
|
| 1911 |
gr.LoginButton()
|
| 1912 |
gr.DuplicateButton(value="Duplicate Space for private use (This demo does not work on CPU. Requires GPU Space)")
|
| 1913 |
|
| 1914 |
+
|
| 1915 |
if __name__ == "__main__":
|
| 1916 |
app.queue()
|
| 1917 |
app.launch(
|