LaMaison / floorplan /README.md
valcore's picture
feat: two-step image gen, Dockerfile builds floorplan whl at deploy time
64dfdfb
# `gradio_floorplan`
<img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0.1%20-%20orange">
A Gradio custom component for interactive SVG floor plan editing
## Installation
```bash
pip install gradio_floorplan
```
## Usage
```python
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
<table>
<thead>
<tr>
<th align="left">name</th>
<th align="left" style="width: 25%;">type</th>
<th align="left">default</th>
<th align="left">description</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left"><code>value</code></td>
<td align="left" style="width: 25%;">
```python
dict | None
```
</td>
<td align="left"><code>value = None</code></td>
<td align="left">None</td>
</tr>
<tr>
<td align="left"><code>label</code></td>
<td align="left" style="width: 25%;">
```python
str | None
```
</td>
<td align="left"><code>value = None</code></td>
<td align="left">None</td>
</tr>
<tr>
<td align="left"><code>info</code></td>
<td align="left" style="width: 25%;">
```python
str | None
```
</td>
<td align="left"><code>value = None</code></td>
<td align="left">None</td>
</tr>
<tr>
<td align="left"><code>every</code></td>
<td align="left" style="width: 25%;">
```python
'Timer | float | None'
```
</td>
<td align="left"><code>value = None</code></td>
<td align="left">None</td>
</tr>
<tr>
<td align="left"><code>show_label</code></td>
<td align="left" style="width: 25%;">
```python
bool | None
```
</td>
<td align="left"><code>value = None</code></td>
<td align="left">None</td>
</tr>
<tr>
<td align="left"><code>container</code></td>
<td align="left" style="width: 25%;">
```python
bool
```
</td>
<td align="left"><code>value = True</code></td>
<td align="left">None</td>
</tr>
<tr>
<td align="left"><code>scale</code></td>
<td align="left" style="width: 25%;">
```python
int | None
```
</td>
<td align="left"><code>value = None</code></td>
<td align="left">None</td>
</tr>
<tr>
<td align="left"><code>min_width</code></td>
<td align="left" style="width: 25%;">
```python
int
```
</td>
<td align="left"><code>value = 160</code></td>
<td align="left">None</td>
</tr>
<tr>
<td align="left"><code>interactive</code></td>
<td align="left" style="width: 25%;">
```python
bool | None
```
</td>
<td align="left"><code>value = None</code></td>
<td align="left">None</td>
</tr>
<tr>
<td align="left"><code>visible</code></td>
<td align="left" style="width: 25%;">
```python
bool
```
</td>
<td align="left"><code>value = True</code></td>
<td align="left">None</td>
</tr>
<tr>
<td align="left"><code>elem_id</code></td>
<td align="left" style="width: 25%;">
```python
str | None
```
</td>
<td align="left"><code>value = None</code></td>
<td align="left">None</td>
</tr>
<tr>
<td align="left"><code>elem_classes</code></td>
<td align="left" style="width: 25%;">
```python
list[str] | str | None
```
</td>
<td align="left"><code>value = None</code></td>
<td align="left">None</td>
</tr>
<tr>
<td align="left"><code>render</code></td>
<td align="left" style="width: 25%;">
```python
bool
```
</td>
<td align="left"><code>value = True</code></td>
<td align="left">None</td>
</tr>
</tbody></table>
### 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.
```python
def predict(
value: dict| None
) -> dict| None:
return value
```