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|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Running on Modal + Image Rendering Guide
|
| 2 |
+
|
| 3 |
+
## 1. Running Training on Modal
|
| 4 |
+
|
| 5 |
+
### Setup
|
| 6 |
+
|
| 7 |
+
```bash
|
| 8 |
+
pip install modal
|
| 9 |
+
modal setup # Authenticate with your Modal token
|
| 10 |
+
```
|
| 11 |
+
|
| 12 |
+
### Create a Modal Secret for HuggingFace
|
| 13 |
+
|
| 14 |
+
```bash
|
| 15 |
+
modal secret create huggingface-token HF_TOKEN=your_hf_token_here
|
| 16 |
+
```
|
| 17 |
+
|
| 18 |
+
### Deploy & Run
|
| 19 |
+
|
| 20 |
+
The repo includes `modal_train.py`. Simply:
|
| 21 |
+
|
| 22 |
+
```bash
|
| 23 |
+
cd parametric-floorplan-generator
|
| 24 |
+
modal run modal_train.py
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
This will:
|
| 28 |
+
1. Spin up a CPU container to generate the 5,000-example synthetic dataset (saved to a Modal Volume)
|
| 29 |
+
2. Spin up an **A10G GPU** container to fine-tune Qwen2.5-1.5B-Instruct with LoRA
|
| 30 |
+
3. Push the trained model to HuggingFace Hub
|
| 31 |
+
|
| 32 |
+
### Customize GPU
|
| 33 |
+
|
| 34 |
+
Edit `modal_train.py` and change the GPU:
|
| 35 |
+
|
| 36 |
+
```python
|
| 37 |
+
@app.function(gpu="A100-40GB", ...) # or "T4", "H100"
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
### Check Progress
|
| 41 |
+
|
| 42 |
+
```bash
|
| 43 |
+
modal app logs floorplan-trainer
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
---
|
| 47 |
+
|
| 48 |
+
## 2. Generating Floorplan Images
|
| 49 |
+
|
| 50 |
+
The model outputs **JSON** with room polygons. To convert to visual plans:
|
| 51 |
+
|
| 52 |
+
### Option A: SVG (Vector, best for CAD/printing)
|
| 53 |
+
|
| 54 |
+
```bash
|
| 55 |
+
# Generate a floorplan first
|
| 56 |
+
python generate.py \
|
| 57 |
+
--plot_length 15 --plot_width 12 \
|
| 58 |
+
--setback_front 1.5 --setback_rear 1.0 \
|
| 59 |
+
--setback_left 1.0 --setback_right 1.0 \
|
| 60 |
+
--road_side N --num_bedrooms 3 --toilets 3 \
|
| 61 |
+
--parking --has_pooja --has_balcony \
|
| 62 |
+
--num_floors 2 --city Delhi > myhouse.json
|
| 63 |
+
|
| 64 |
+
# Render to SVG
|
| 65 |
+
python render_floorplan.py --input myhouse.json --output myhouse.svg
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
The SVG includes:
|
| 69 |
+
- **Plot boundary** (thick black line)
|
| 70 |
+
- **Buildable boundary** (dashed gray)
|
| 71 |
+
- **Rooms** color-coded by type (living=blue, bedroom=orange, kitchen=purple, etc.)
|
| 72 |
+
- **Door openings** (green lines)
|
| 73 |
+
- **Windows** (blue dashed lines)
|
| 74 |
+
- **Room labels** with names and areas
|
| 75 |
+
- **Dimension annotations**
|
| 76 |
+
- **North arrow**
|
| 77 |
+
- **Legend**
|
| 78 |
+
|
| 79 |
+
### Option B: PNG (Raster, best for web/presentations)
|
| 80 |
+
|
| 81 |
+
```bash
|
| 82 |
+
pip install cairosvg
|
| 83 |
+
python render_floorplan.py --input myhouse.json --output myhouse.png
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
### Option C: Interactive Web Viewer (Gradio)
|
| 87 |
+
|
| 88 |
+
Deploy as a HuggingFace Space:
|
| 89 |
+
|
| 90 |
+
```python
|
| 91 |
+
import gradio as gr
|
| 92 |
+
import json
|
| 93 |
+
from render_floorplan import render_floorplan_svg
|
| 94 |
+
|
| 95 |
+
def generate_and_render(params_json):
|
| 96 |
+
floorplan = json.loads(model_output)
|
| 97 |
+
svg = render_floorplan_svg(floorplan, width=1200)
|
| 98 |
+
return svg
|
| 99 |
+
|
| 100 |
+
gr.Interface(
|
| 101 |
+
fn=generate_and_render,
|
| 102 |
+
inputs=gr.JSON(label="Project Parameters"),
|
| 103 |
+
outputs=gr.HTML(label="Floorplan SVG"),
|
| 104 |
+
title="Parametric Floorplan Generator"
|
| 105 |
+
).launch()
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
### Option D: CAD Export (DXF)
|
| 109 |
+
|
| 110 |
+
For professional CAD output, extend `render_floorplan.py` to write DXF using `ezdxf`:
|
| 111 |
+
|
| 112 |
+
```bash
|
| 113 |
+
pip install ezdxf
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
Then iterate over the JSON polygons and write them as DXF polylines.
|
| 117 |
+
|
| 118 |
+
---
|
| 119 |
+
|
| 120 |
+
## 3. Complete Pipeline on Modal
|
| 121 |
+
|
| 122 |
+
You can also run inference + rendering as a Modal endpoint:
|
| 123 |
+
|
| 124 |
+
```python
|
| 125 |
+
import modal
|
| 126 |
+
|
| 127 |
+
app = modal.App("floorplan-api")
|
| 128 |
+
|
| 129 |
+
@app.function(gpu="T4", image=modal.Image.debian_slim().pip_install("transformers", "torch", "accelerate", "cairosvg"))
|
| 130 |
+
@modal.web_endpoint(method="POST")
|
| 131 |
+
def generate(params: dict):
|
| 132 |
+
# 1. Run model inference
|
| 133 |
+
# 2. Render SVG
|
| 134 |
+
# 3. Convert to PNG
|
| 135 |
+
# 4. Return image
|
| 136 |
+
pass
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
+
This gives you an HTTP API that takes your ProjectCreate JSON and returns a PNG floorplan.
|
| 140 |
+
|
| 141 |
+
---
|
| 142 |
+
|
| 143 |
+
## 4. Summary of Commands
|
| 144 |
+
|
| 145 |
+
```bash
|
| 146 |
+
# Clone repo
|
| 147 |
+
git clone https://huggingface.co/Karthik8nitt/parametric-floorplan-generator
|
| 148 |
+
cd parametric-floorplan-generator
|
| 149 |
+
|
| 150 |
+
# Install locally
|
| 151 |
+
pip install transformers trl torch datasets peft accelerate trackio
|
| 152 |
+
pip install cairosvg # for PNG rendering
|
| 153 |
+
|
| 154 |
+
# Train on Modal
|
| 155 |
+
modal run modal_train.py
|
| 156 |
+
|
| 157 |
+
# Generate floorplan
|
| 158 |
+
python generate.py --plot_length 15 --plot_width 12 ... > plan.json
|
| 159 |
+
|
| 160 |
+
# Render
|
| 161 |
+
python render_floorplan.py --input plan.json --output plan.svg
|
| 162 |
+
python render_floorplan.py --input plan.json --output plan.png
|
| 163 |
+
```
|