File size: 2,911 Bytes
d327347
1e24c7c
d327347
 
 
1e24c7c
 
 
d327347
 
 
1e24c7c
d327347
1e24c7c
 
 
 
 
d327347
 
1e24c7c
 
d327347
 
 
 
1e24c7c
d327347
1e24c7c
d327347
 
1e24c7c
d327347
1e24c7c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d327347
 
 
1e24c7c
 
 
d327347
 
 
 
 
 
1e24c7c
 
d327347
1e24c7c
 
 
d327347
 
 
 
 
1e24c7c
 
 
d327347
1e24c7c
d327347
1e24c7c
 
 
 
d327347
1e24c7c
 
 
 
 
d327347
 
1e24c7c
 
 
 
d327347
1e24c7c
 
 
 
 
d327347
1e24c7c
d327347
1e24c7c
d327347
1e24c7c
 
 
 
 
d327347
 
1e24c7c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import torch
import gradio as gr
from diffusers import StableDiffusionPipeline


# ==========================
# DEVICE
# ==========================
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"


# ==========================
# LOAD MODEL
# ==========================

print("Loading Stable Diffusion Model...")

model_id = "runwayml/stable-diffusion-v1-5"

pipe = StableDiffusionPipeline.from_pretrained(
    model_id,
    torch_dtype=torch.float16 if DEVICE == "cuda" else torch.float32
)

pipe = pipe.to(DEVICE)

pipe.enable_attention_slicing()

print("Model Loaded Successfully")


# ==========================
# PROMPT BUILDER
# ==========================

def build_prompt(width, height, entrance):

    vastu = {
        "bedroom": "South-West",
        "kitchen": "South-East",
        "puja": "North-East",
        "hall": "Center",
        "toilet": "North-West",
        "stairs": "South"
    }

    prompt = f"""
    professional architectural blueprint,
    clean 2D floor plan,
    black and white CAD drawing,
    top view technical plan,
    thin lines,
    no colors,
    no shading,
    labeled rooms,

    plot size {width} x {height} feet,
    entrance facing {entrance},

    bedroom in {vastu['bedroom']},
    kitchen in {vastu['kitchen']},
    puja room in {vastu['puja']},
    living hall in {vastu['hall']},
    toilet in {vastu['toilet']},
    staircase in {vastu['stairs']},

    printable house plan
    """

    return prompt


NEGATIVE_PROMPT = """
3d, color, colorful, painting, sketch,
cartoon, fantasy, render, realistic,
photo, texture, shadow, blur,
low quality, messy
"""


# ==========================
# GENERATE FUNCTION
# ==========================

def generate_plan(width, height, entrance):

    prompt = build_prompt(width, height, entrance)

    image = pipe(
        prompt=prompt,
        negative_prompt=NEGATIVE_PROMPT,
        num_inference_steps=30,
        guidance_scale=9,
        height=768,
        width=768
    ).images[0]

    return image


# ==========================
# GRADIO UI
# ==========================

with gr.Blocks(title="Vastu 2D Plan Generator") as demo:

    gr.Markdown("""
    # 🏠 Vastu 2D Floor Plan Generator
    Generate clean blueprint style house plans using AI
    """)

    with gr.Row():

        width = gr.Textbox(
            label="Plot Width (feet)",
            placeholder="Example: 40"
        )

        height = gr.Textbox(
            label="Plot Height (feet)",
            placeholder="Example: 60"
        )

        entrance = gr.Dropdown(
            ["North", "South", "East", "West"],
            label="Entrance Direction",
            value="East"
        )

    generate_btn = gr.Button("Generate Plan 🚀")

    output = gr.Image(label="Generated Plan")

    generate_btn.click(
        fn=generate_plan,
        inputs=[width, height, entrance],
        outputs=output
    )


demo.launch()