Files changed (1) hide show
  1. app.py +97 -92
app.py CHANGED
@@ -1,136 +1,141 @@
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()
 
 
1
  import torch
2
+ import gradio as gr
3
  from diffusers import StableDiffusionPipeline
4
 
5
 
6
+ # ==========================
7
+ # DEVICE
8
+ # ==========================
 
 
9
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
10
 
 
11
 
12
+ # ==========================
 
13
  # LOAD MODEL
14
+ # ==========================
15
+
16
+ print("Loading Stable Diffusion Model...")
17
+
18
+ model_id = "runwayml/stable-diffusion-v1-5"
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
 
27
+ pipe.enable_attention_slicing()
28
 
29
+ print("Model Loaded Successfully")
 
 
 
 
 
 
 
 
 
 
 
30
 
31
 
32
+ # ==========================
33
  # PROMPT BUILDER
34
+ # ==========================
35
+
36
+ def build_prompt(width, height, entrance):
37
+
38
+ vastu = {
39
+ "bedroom": "South-West",
40
+ "kitchen": "South-East",
41
+ "puja": "North-East",
42
+ "hall": "Center",
43
+ "toilet": "North-West",
44
+ "stairs": "South"
45
+ }
46
+
47
+ prompt = f"""
48
+ professional architectural blueprint,
49
+ clean 2D floor plan,
50
+ black and white CAD drawing,
51
+ top view technical plan,
52
+ thin lines,
53
+ no colors,
54
+ no shading,
55
+ labeled rooms,
56
+
57
+ plot size {width} x {height} feet,
58
+ entrance facing {entrance},
59
+
60
+ bedroom in {vastu['bedroom']},
61
+ kitchen in {vastu['kitchen']},
62
+ puja room in {vastu['puja']},
63
+ living hall in {vastu['hall']},
64
+ toilet in {vastu['toilet']},
65
+ staircase in {vastu['stairs']},
66
+
67
+ printable house plan
68
+ """
69
+
70
+ return prompt
71
+
72
+
73
+ NEGATIVE_PROMPT = """
74
+ 3d, color, colorful, painting, sketch,
75
+ cartoon, fantasy, render, realistic,
76
+ photo, texture, shadow, blur,
77
+ low quality, messy
78
  """
79
 
80
 
81
+ # ==========================
82
+ # GENERATE FUNCTION
83
+ # ==========================
 
 
 
 
 
 
 
84
 
85
  def generate_plan(width, height, entrance):
86
 
87
  prompt = build_prompt(width, height, entrance)
88
 
89
  image = pipe(
90
+ prompt=prompt,
91
+ negative_prompt=NEGATIVE_PROMPT,
92
  num_inference_steps=30,
93
+ guidance_scale=9,
94
+ height=768,
95
+ width=768
96
  ).images[0]
97
 
98
  return image
99
 
100
 
101
+ # ==========================
102
+ # GRADIO UI
103
+ # ==========================
104
 
105
+ with gr.Blocks(title="Vastu 2D Plan Generator") as demo:
106
 
107
+ gr.Markdown("""
108
+ # 🏠 Vastu 2D Floor Plan Generator
109
+ Generate clean blueprint style house plans using AI
110
+ """)
111
 
112
+ with gr.Row():
113
+
114
+ width = gr.Textbox(
115
+ label="Plot Width (feet)",
116
+ placeholder="Example: 40"
 
 
117
  )
 
118
 
119
+ height = gr.Textbox(
120
+ label="Plot Height (feet)",
121
+ placeholder="Example: 60"
122
+ )
123
 
124
+ entrance = gr.Dropdown(
125
+ ["North", "South", "East", "West"],
126
+ label="Entrance Direction",
127
+ value="East"
128
+ )
129
 
130
+ generate_btn = gr.Button("Generate Plan 🚀")
 
 
 
131
 
132
+ output = gr.Image(label="Generated Plan")
 
133
 
134
+ generate_btn.click(
135
+ fn=generate_plan,
136
+ inputs=[width, height, entrance],
137
+ outputs=output
138
+ )
139
 
 
 
 
140
 
141
+ demo.launch()