Skip to main content

tags: [gradio-custom-component, HTML, Motion Canvas, Animation, Player, custom-component-track] title: gradio_motioncanvasplayer short_description: Motion Canvas Player to render Motion Canvas projects colorFrom: blue colorTo: yellow sdk: gradio pinned: false app_file: space.py

gradio_motioncanvasplayer

PyPI - Version Static Badge Static Badge

This custom component for Gradio displays Motion Canvas projects in the browser. Motion Canvas is a library for generating animations, videos, or presentations via the Canvas API. All animations are defined by code - an excellent playground for AI agents. An exemplary demo for this component is available in this Huggingface Space: https://huggingface.co/spaces/prathje/gradio_motioncanvasplayer. The source code for the included project can be found at: https://github.com/prathje/gradio-motion-canvas-example.

Installation

pip install gradio_motioncanvasplayer

Usage

import gradio as gr
import os

from gradio_motioncanvasplayer import MotionCanvasPlayer

gr.set_static_paths(paths=[os.path.join(os.path.dirname(__file__), "public")])
project_local_path = os.path.join(os.path.dirname(__file__), "public/project-3.17.2.js")
project_api_path = "/gradio_api/file=" + project_local_path


demo = gr.Interface(
    lambda x:x,
    None,  # interactive version of your component, not relevant for this demo
    MotionCanvasPlayer(project_api_path, auto=True, quality=0.5, width=1920, height=1080, variables="{}"),  # static version of your component
    clear_btn=None

)

if __name__ == '__main__':
    demo.launch(server_name="0.0.0.0", server_port=7860)

MotionCanvasPlayer

Initialization

name type default description
value
str | Callable | None
None The MotionCanvasPlayer content to display. Only static MotionCanvasPlayer is rendered (e.g. no JavaScript. To render JavaScript, use the `js` or `head` parameters in the `Blocks` constructor). If a function is provided, the function will be called each time the app loads to set the initial value of this component.
label
str | I18nData | None
None The label for this component. Is used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component is assigned to.
every
Timer | float | None
None Continously calls `value` to recalculate it if `value` is a function (has no effect otherwise). Can provide a Timer whose tick resets `value`, or a float that provides the regular interval for the reset Timer.
inputs
Component | Sequence[Component] | set[Component] | None
None Components that are used as inputs to calculate `value` if `value` is a function (has no effect otherwise). `value` is recalculated any time the inputs change.
show_label
bool
False If True, the label will be displayed. If False, the label will be hidden.
visible
bool
True If False, component will be hidden.
elem_id
str | None
None An optional string that is assigned as the id of this component in the MotionCanvasPlayer DOM. Can be used for targeting CSS styles.
elem_classes
list[str] | str | None
None An optional list of strings that are assigned as the classes of this component in the MotionCanvasPlayer DOM. Can be used for targeting CSS styles.
render
bool
True If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.
key
int | str | tuple[int | str, ...] | None
None in a gr.render, Components with the same key across re-renders are treated as the same component, not a new component. Properties set in 'preserved_by_key' are not reset across a re-render.
preserved_by_key
list[str] | str | None
"value" A list of parameters from this component's constructor. Inside a gr.render() function, if a component is re-rendered with the same key, these (and only these) parameters will be preserved in the UI (if they have been changed by the user or an event listener) instead of re-rendered based on the values provided during constructor.
min_height
int | None
None The minimum height of the component, specified in pixels if a number is passed, or in CSS units if a string is passed. If MotionCanvasPlayer content exceeds the height, the component will expand to fit the content.
max_height
int | None
None The maximum height of the component, specified in pixels if a number is passed, or in CSS units if a string is passed. If content exceeds the height, the component will scroll.
container
bool
False If True, the MotionCanvasPlayer component will be displayed in a container. Default is False.
padding
bool
True If True, the MotionCanvasPlayer component will have a certain padding (set by the `--block-padding` CSS variable) in all directions. Default is True.
auto
bool | None
False If True, the MotionCanvasPlayer component will automatically play the animation. Default is False.
quality
number | None
None The quality of the MotionCanvasPlayer component. Default is None which uses the project's default settings.
width
int | None
None The width of the MotionCanvasPlayer component. Default is None which uses the project's default settings.
height
int | None
None The height of the MotionCanvasPlayer component. Default is None which uses the project's default settings.
variables
str | None
None The variables of the MotionCanvasPlayer component as a JSON string. Default is None.

Events

name description
change Triggered when the value of the MotionCanvasPlayer changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See .input() for a listener that is only triggered by user input.
click Triggered when the MotionCanvasPlayer is clicked.

User function

The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).

  • When used as an Input, the component only impacts the input signature of the user function.
  • When used as an output, the component only impacts the return signature of the user function.

The code snippet below is accurate in cases where the component is used as both an input and an output.

  • As output: Is passed, (Rarely used) passes the MotionCanvasPlayer as a str.
  • As input: Should return, expects a str consisting of valid MotionCanvasPlayer.
def predict(
    value: str | None
) -> str | None:
    return value

Metadata

Release files for gradio-motioncanvasplayer 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gradio-motioncanvasplayer 0.0.2
File Size Uploaded Provenance Actions
gradio_motioncanvasplayer-0.0.2.tar.gz 1.2 MB Without provenance Details for gradio_motioncanvasplayer-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gradio-motioncanvasplayer 0.0.2
File Interpreter ABI Platform Actions
gradio_motioncanvasplayer-0.0.2-py3-none-any.whl Python 3 none any Details for gradio_motioncanvasplayer-0.0.2-py3-none-any.whl

Total release size: 2.4 MB

Release files / gradio_motioncanvasplayer-0.0.2.tar.gz

Download URL gradio_motioncanvasplayer-0.0.2.tar.gz
Size 1.2 MB
Tags Source
SHA-256 checksum
How to use checksums
384251b3e4ceca438ab72948bc79350c620635c951ed0e5699db361e895f6fa4
BLAKE2b-256 checksum
How to use checksums
b4da46a1c76612ca7cfb5eb6c5a5427ab82844d7a25e5704994359936ed7f3a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.17

Release files / gradio_motioncanvasplayer-0.0.2-py3-none-any.whl

Download URL gradio_motioncanvasplayer-0.0.2-py3-none-any.whl
Size 1.1 MB
Tags Python 3
SHA-256 checksum
How to use checksums
4ab3f44763a9cb0e65399e55ec5974d664e2a8f0842ea387f6275276392a85d4
BLAKE2b-256 checksum
How to use checksums
ebdef135874d43f2d9ead4bae9303e0f433c563eae63766557306c5b55542f4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.17

Security for gradio-motioncanvasplayer 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page