feat: add FloorPlan demo app with default floor plan and 2 furnitures
Browse files- floorplan/demo/app.py +24 -8
floorplan/demo/app.py
CHANGED
|
@@ -1,17 +1,33 @@
|
|
| 1 |
-
|
| 2 |
import gradio as gr
|
| 3 |
from gradio_floorplan import FloorPlan
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
demo = gr.Interface(
|
| 9 |
-
lambda x:x,
|
| 10 |
-
FloorPlan(), # interactive version of your component
|
| 11 |
-
FloorPlan(), # static version of your component
|
| 12 |
-
# examples=[[example]], # uncomment this line to view the "example version" of your component
|
| 13 |
-
)
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
if __name__ == "__main__":
|
| 17 |
demo.launch()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from gradio_floorplan import FloorPlan
|
| 3 |
|
| 4 |
+
DEFAULT_VALUE = {
|
| 5 |
+
"corners": [[50, 50], [550, 50], [550, 450], [50, 450]],
|
| 6 |
+
"furnitures": [
|
| 7 |
+
{
|
| 8 |
+
"object": "Sofa",
|
| 9 |
+
"localisation": [150, 100, 250, 300],
|
| 10 |
+
"description": "3-seat sofa",
|
| 11 |
+
},
|
| 12 |
+
{
|
| 13 |
+
"object": "Table",
|
| 14 |
+
"localisation": [300, 200, 380, 400],
|
| 15 |
+
"description": "Coffee table",
|
| 16 |
+
},
|
| 17 |
+
],
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
|
| 21 |
+
def on_furniture_moved(value):
|
| 22 |
+
"""Receives updated floor plan after user moves a furniture item."""
|
| 23 |
+
return value
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
with gr.Blocks() as demo:
|
| 27 |
+
gr.Markdown("## LaMaison — Floor Plan")
|
| 28 |
+
floor_plan = FloorPlan(value=DEFAULT_VALUE, label="Floor Plan", interactive=True)
|
| 29 |
+
output = gr.JSON(label="Updated positions")
|
| 30 |
+
floor_plan.change(on_furniture_moved, inputs=floor_plan, outputs=output)
|
| 31 |
|
| 32 |
if __name__ == "__main__":
|
| 33 |
demo.launch()
|