Ajay D commited on
Commit
d327347
·
verified ·
1 Parent(s): edd40f4

Add Vastu AI generator

Browse files
Files changed (1) hide show
  1. app.py +136 -0
app.py ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from diffusers import StableDiffusionPipeline
4
+
5
+
6
+ # =============================
7
+ # CONFIG
8
+ # =============================
9
+
10
+ MODEL_ID = "runwayml/stable-diffusion-v1-5"
11
+ DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
12
+
13
+ print("Loading Model...")
14
+
15
+
16
+ # =============================
17
+ # LOAD MODEL
18
+ # =============================
19
+
20
+ pipe = StableDiffusionPipeline.from_pretrained(
21
+ MODEL_ID,
22
+ torch_dtype=torch.float16 if DEVICE=="cuda" else torch.float32
23
+ )
24
+
25
+ pipe = pipe.to(DEVICE)
26
+ pipe.enable_attention_slicing()
27
+
28
+ print("Model Ready")
29
+
30
+
31
+ # =============================
32
+ # VASTU
33
+ # =============================
34
+
35
+ VASTU = {
36
+ "bedroom": "south west",
37
+ "kitchen": "south east",
38
+ "puja": "north east",
39
+ "hall": "center",
40
+ "toilet": "north west",
41
+ "stairs": "south"
42
+ }
43
+
44
+
45
+ # =============================
46
+ # PROMPT BUILDER
47
+ # =============================
48
+
49
+ def build_prompt(w, h, entrance):
50
+
51
+ return f"""
52
+ clean professional 2D house floor plan,
53
+ black and white blueprint,
54
+ CAD technical drawing,
55
+ top view,
56
+ thin lines,
57
+ no color,
58
+ no shading,
59
+ clear room labels,
60
+
61
+ plot size {w} x {h} feet,
62
+ entrance facing {entrance},
63
+
64
+ bedroom in {VASTU['bedroom']},
65
+ kitchen in {VASTU['kitchen']},
66
+ puja room in {VASTU['puja']},
67
+ hall in {VASTU['hall']},
68
+ toilet in {VASTU['toilet']},
69
+ stairs in {VASTU['stairs']},
70
+
71
+ engineering drawing,
72
+ printable layout
73
+ """
74
+
75
+
76
+ NEGATIVE = """
77
+ 3d, color, painting, render,
78
+ photo, realistic, shadow,
79
+ blurry, messy, cartoon
80
+ """
81
+
82
+
83
+ # =============================
84
+ # GENERATE
85
+ # =============================
86
+
87
+ def generate_plan(width, height, entrance):
88
+
89
+ prompt = build_prompt(width, height, entrance)
90
+
91
+ image = pipe(
92
+ prompt,
93
+ negative_prompt=NEGATIVE,
94
+ num_inference_steps=30,
95
+ guidance_scale=8
96
+ ).images[0]
97
+
98
+ return image
99
+
100
+
101
+ # =============================
102
+ # UI
103
+ # =============================
104
+
105
+ app = gr.Interface(
106
+
107
+ fn=generate_plan,
108
+
109
+ inputs=[
110
+ gr.Text(label="Plot Width (feet)", value="40"),
111
+ gr.Text(label="Plot Height (feet)", value="60"),
112
+ gr.Dropdown(
113
+ ["North","South","East","West"],
114
+ label="Entrance Direction",
115
+ value="North"
116
+ )
117
+ ],
118
+
119
+ outputs=gr.Image(type="pil"),
120
+
121
+ title="🏠 Vastu 2D Floor Plan Generator",
122
+
123
+ description="""
124
+ Generate clean black & white 2D Vastu floor plans using AI.
125
+ Perfect for architects and builders.
126
+ """,
127
+
128
+ allow_flagging="never"
129
+ )
130
+
131
+
132
+ # =============================
133
+ # RUN
134
+ # =============================
135
+
136
+ app.launch()