-
Notifications
You must be signed in to change notification settings - Fork 693
feat: add cog playground browser UI #3086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
anish-sahoo
wants to merge
10
commits into
main
Choose a base branch
from
interactive-ui
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9b9b7f8
add initial code
anish-sahoo 89292d8
Add working version of playground
anish-sahoo fd3433c
fix: playground optional-field input controls
anish-sahoo 3fa01b9
feat: playground sticky action bar + Ace JSON editors
anish-sahoo 3c85d94
docs: document cog playground in CLI architecture
anish-sahoo a1924d4
refactor: rename playground-ui asset dir to playground
anish-sahoo ef17f6d
docs: add playground page and nav entry
anish-sahoo 40d18de
fix: address PR review — SSE data framing + CLI doc tree
anish-sahoo f661702
feat: auto-scroll playground output editor to the tail while streaming
anish-sahoo a78b917
feat: restyle playground with Kumo design tokens
anish-sahoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # Playground | ||
|
|
||
| `cog playground` opens a browser UI for talking to a running Cog model — a Postman-like tool that reflects your model's inputs and outputs from its OpenAPI schema and lets you run predictions interactively. | ||
|
|
||
| It doesn't build an image or run your model. Point it at a model API you're already running — typically [`cog serve`](cli.md#cog-serve) — and it proxies requests to that API. | ||
|
|
||
| ## Quick start | ||
|
|
||
| Start your model's HTTP server in one terminal: | ||
|
|
||
| ```sh | ||
| cog serve -p 8393 | ||
| ``` | ||
|
|
||
| Open the playground in another: | ||
|
|
||
| ```sh | ||
| cog playground --target http://localhost:8393 | ||
| ``` | ||
|
|
||
| This serves the UI on a local port and opens it in your browser. You can change the target API from the UI at any time. | ||
|
|
||
| ## What you can do | ||
|
|
||
| - **Schema-driven form.** Inputs render from the model's `/openapi.json` as the appropriate widgets (text, number, boolean, enum, list, file, secret). Optional fields without a default start unchecked so they're omitted. | ||
| - **Form or JSON.** Toggle between the generated form and a JSON editor; the two stay in sync. | ||
| - **Files by upload or URL.** File inputs accept an uploaded file (sent as a data URI) or a URL, with an inline preview for images, audio, and video. | ||
| - **Sync, streaming, or async.** Run modes appear based on what the model supports — streaming (SSE) when the predictor uses `@cog.streaming`, and async via webhooks. | ||
| - **Rendered or raw output.** View the rendered result (media, text, JSON) or switch to **Raw** to see exactly what arrived over the wire. A Copy button grabs the whole payload. | ||
|
|
||
| ## Options | ||
|
|
||
| | Flag | Description | | ||
| | ---------------- | ---------------------------------------------------------------------------------------------- | | ||
| | `--target` | Default model API URL (also changeable in the UI). Defaults to `http://localhost:8393`. | | ||
| | `-p, --port` | Port to listen on. `0` (default) picks a free port. | | ||
| | `--host` | Address to bind. Use `0.0.0.0` to receive webhooks from a containerized model. | | ||
| | `--webhook-host` | Hostname the model uses to reach the playground for webhooks (default `host.docker.internal`). | | ||
| | `--no-open` | Don't open the browser automatically. | | ||
|
|
||
| ## CORS and webhooks | ||
|
|
||
| Requests are reverse-proxied through the playground, so the model API doesn't need to send any CORS headers. | ||
|
|
||
| [Async predictions](http.md#webhooks) are observed via webhooks (there's no status-polling endpoint), so the playground hosts a webhook sink and relays events to the browser. For this to work against a model running in a container, the playground must be reachable from inside the container: | ||
|
|
||
| ```sh | ||
| cog playground --host 0.0.0.0 --webhook-host host.docker.internal | ||
| ``` | ||
|
|
||
| > [!NOTE] | ||
| > Sync and streaming predictions work without any of this — the webhook setup is only needed for async runs. | ||
|
|
||
| ## Remote models | ||
|
|
||
| If your model runs on another machine, forward its port over SSH and point the playground at it: | ||
|
|
||
| ```sh | ||
| ssh -L 8393:localhost:5000 user@remote | ||
| cog playground --target http://localhost:8393 | ||
| ``` | ||
|
|
||
| Sync and streaming work over the tunnel. For async/webhooks, run the playground next to the model on the remote and forward only the UI port instead. | ||
|
|
||
| See the [CLI reference](cli.md#cog-playground) for the full list of flags. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| torch==2.12.0 | ||
| torch==2.8.0 | ||
| transformers==5.0.0rc3 | ||
| accelerate==1.6.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.