Spaces:
Running on Zero
Add PR description
Browse files# MOSS-Image as a Gradio Workflow app
Rebuilds this Space on **`gr.Workflow`** (the node-canvas pipeline builder in gradio 6.30.0) while keeping the demo's full feature set, and restyles the auto-generated App view after the MOSS-Image landing page. Developed and tested at [akhaliq/moss-image-workflow](https://huggingface.co/spaces/akhaliq/moss-image-workflow).
## What changes
- **`app.py`** β new entry point. Both checkpoints (Base + SFT) load once at module scope with the same hash-matched sharing of text encoder / tokenizer / VAE as the current demo (packing drops from ~54 GB to ~37 GB, which is what fits a ZeroGPU worker). A single `generate` function node exposes every sampling parameter of the original `GenerationConfig` and runs under `@spaces.GPU(duration=80)`.
- **`workflow.json`** (new) β the graph: 16 reference nodes (prompt, negative, model, width/height, steps, CFG, shift, seed, image count, max text length, and the full SLG / skip-layer suite) β `MOSS-Image Generate` β gallery + status subjects. Reference literals are keyed under the output port (`data.out`), which is the field the canvas reads. The form is prefilled with showcase example 007 (photorealistic Kazusa, seed fixed) so visitors can hit Run immediately.
- **`requirements.txt`** β adds `gradio_client` (media serialization helpers).
- **`README.md`** β parity table, design notes, and `hf_oauth: true` with `inference-api` + `write-repos` scopes (required for canvas editing and per-visitor ZeroGPU quota; visitors will be re-prompted to authorize).
## Feature parity
Everything generation-related from the current demo is in: model choice, prompts, dimensions, steps/CFG/shift/seed (`-1` = random, resolved seed reported in the status output), images-per-prompt gallery, max text length, negative-branch skipping (`22`) and Standard SLG controls β with the same defaults and validation. The example gallery is ported as a strip of the 20 showcase thumbnails (hot-linked from `assets/`); clicking one restores all of its settings, including the v1βv2 record-schema translation.
Deliberately not ported: showcase add/delete with live refresh (needs a hand-built Blocks UI), AOT compilation (eager backend, as with `MOSS_AOTI=0`), and per-run `parameters.json` records.
## Two gradio 6.30.0 workarounds worth knowing about
Both are small, documented patches in `app.py`, isolated to this app:
1. **Gallery subjects in the App view** β `workflow_api._from_output` unwraps file dicts at the top level but not inside lists, and `gr.Gallery` only accepts path strings. Patched to unwrap list items too.
2. **Long fn calls from the canvas** β `/gradio_api/component_server` is a plain POST with no heartbeats, so a ~45β130 s generation gets its idle connection dropped by the proxy chain ('Connection errored out'). The route is wrapped to stream whitespace keep-alive bytes (legal JSON leading whitespace) until the result is ready.
## Notes for review
- `gradio_app.py`, `aoti.py`, `gradio_presets.py`, `inference_runtime.py` become dead code β left in place for the author to remove.
- `pipeline_moss_image.py` is used verbatim, unchanged.
- `assets/` must stay: the UI hot-links the lockups and showcase images from it.
- The old UI's resolution/aspect preset widgets are replaced by direct width/height fields; the status line (seed, settings, elapsed) is preserved as a second output.