A newer version of the Gradio SDK is available: 6.11.0
gradio_floorplan
A Gradio custom component for interactive SVG floor plan editing
Installation
pip install gradio_floorplan
Usage
import gradio as gr
from gradio_floorplan import FloorPlan
DEFAULT_VALUE = {
"corners": [[50, 50], [550, 50], [550, 450], [50, 450]],
"furnitures": [
{
"object": "Sofa",
"localisation": [150, 100, 250, 300],
"description": "3-seat sofa",
},
{
"object": "Table",
"localisation": [300, 200, 380, 400],
"description": "Coffee table",
},
],
}
def on_furniture_moved(value):
"""Receives updated floor plan after user moves a furniture item."""
return value
with gr.Blocks() as demo:
gr.Markdown("## LaMaison — Floor Plan")
floor_plan = FloorPlan(value=DEFAULT_VALUE, label="Floor Plan", interactive=True)
output = gr.JSON(label="Updated positions")
floor_plan.change(on_furniture_moved, inputs=floor_plan, outputs=output)
if __name__ == "__main__":
demo.launch()
FloorPlan
Initialization
| name | type | default | description |
|---|---|---|---|
value |
|
value = None |
None |
label |
|
value = None |
None |
info |
|
value = None |
None |
every |
|
value = None |
None |
show_label |
|
value = None |
None |
container |
|
value = True |
None |
scale |
|
value = None |
None |
min_width |
|
value = 160 |
None |
interactive |
|
value = None |
None |
visible |
|
value = True |
None |
elem_id |
|
value = None |
None |
elem_classes |
|
value = None |
None |
render |
|
value = True |
None |
Events
| name | description |
|---|---|
change |
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.
def predict(
value: dict| None
) -> dict| None:
return value