Ajay D commited on
Commit
b21190a
ยท
verified ยท
1 Parent(s): 8480c87

Final working vastu AI ap

Browse files
Files changed (1) hide show
  1. app.py +74 -57
app.py CHANGED
@@ -1,91 +1,92 @@
1
  import torch
2
  import gradio as gr
3
-
4
  from diffusers import StableDiffusionPipeline
5
 
6
 
7
- # =========================
8
- # DEVICE
9
- # =========================
 
 
10
 
11
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
12
 
 
13
 
14
- # =========================
15
- # LOAD MODEL (STABLE)
16
- # =========================
17
 
18
- print("Loading Stable Diffusion...")
 
 
19
 
20
  pipe = StableDiffusionPipeline.from_pretrained(
21
- "runwayml/stable-diffusion-v1-5",
22
- torch_dtype=torch.float16,
23
  safety_checker=None
24
  )
25
 
26
  pipe = pipe.to(DEVICE)
27
 
28
- pipe.enable_attention_slicing()
29
-
30
- print("Model Loaded โœ…")
31
 
32
 
33
- # =========================
34
  # VASTU RULES
35
- # =========================
36
 
37
  VASTU = {
38
  "bedroom": "South-West",
39
  "kitchen": "South-East",
40
- "pooja": "North-East",
41
  "hall": "Center",
42
  "toilet": "North-West",
43
  "stairs": "South"
44
  }
45
 
46
 
47
- # =========================
48
  # PROMPT BUILDER
49
- # =========================
50
 
51
- def build_prompt(w, h, entrance):
52
 
53
  return f"""
54
  professional architectural blueprint,
55
  clean 2D floor plan,
56
  black and white CAD drawing,
57
- technical line art,
58
  top view,
 
 
 
 
59
  labeled rooms,
60
 
61
- plot size {w} x {h} feet,
62
  entrance facing {entrance},
63
 
64
  bedroom in {VASTU['bedroom']},
65
  kitchen in {VASTU['kitchen']},
66
- pooja in {VASTU['pooja']},
67
  living hall in {VASTU['hall']},
68
  toilet in {VASTU['toilet']},
69
  stairs in {VASTU['stairs']},
70
 
71
- walls, doors, windows,
72
- north arrow,
73
- dimension lines,
74
- printable drawing
75
  """
76
 
77
 
78
- NEGATIVE = """
79
- 3d, color, colorful, painting,
80
- photo, realistic, shadow,
81
- shading, blur, messy,
82
- cartoon, anime
83
  """
84
 
85
 
86
- # =========================
87
- # GENERATE FUNCTION
88
- # =========================
89
 
90
  def generate_plan(width, height, entrance):
91
 
@@ -93,47 +94,63 @@ def generate_plan(width, height, entrance):
93
 
94
  image = pipe(
95
  prompt=prompt,
96
- negative_prompt=NEGATIVE,
97
- num_inference_steps=20,
98
- guidance_scale=7.5,
99
- height=512,
100
- width=512
101
  ).images[0]
102
 
103
  return image
104
 
105
 
106
- # =========================
107
- # UI
108
- # =========================
109
 
110
- with gr.Blocks() as demo:
111
 
112
- gr.Markdown("""
113
- # ๐Ÿ  Vastu 2D Floor Plan Generator
114
- Generate clean blueprint style house plans
115
- """)
 
 
116
 
117
  with gr.Row():
118
 
119
- width = gr.Number(label="Plot Width (feet)", value=40)
120
- height = gr.Number(label="Plot Height (feet)", value=60)
 
 
121
 
122
- entrance = gr.Dropdown(
123
- ["North", "South", "East", "West"],
124
- value="East",
125
- label="Entrance"
126
  )
127
 
128
- btn = gr.Button("Generate Plan ๐Ÿš€", variant="primary")
 
 
 
 
 
 
129
 
130
- output = gr.Image(label="Generated Plan")
 
 
 
131
 
132
  btn.click(
133
- generate_plan,
134
  inputs=[width, height, entrance],
135
  outputs=output
136
  )
137
 
138
 
139
- demo.launch()
 
 
 
 
 
1
  import torch
2
  import gradio as gr
 
3
  from diffusers import StableDiffusionPipeline
4
 
5
 
6
+ # ===============================
7
+ # CONFIG
8
+ # ===============================
9
+
10
+ MODEL_ID = "runwayml/stable-diffusion-v1-5"
11
 
12
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
13
 
14
+ print("Loading Model... Please wait...")
15
 
 
 
 
16
 
17
+ # ===============================
18
+ # LOAD MODEL
19
+ # ===============================
20
 
21
  pipe = StableDiffusionPipeline.from_pretrained(
22
+ MODEL_ID,
23
+ torch_dtype=torch.float32,
24
  safety_checker=None
25
  )
26
 
27
  pipe = pipe.to(DEVICE)
28
 
29
+ print("Model Loaded Successfully")
 
 
30
 
31
 
32
+ # ===============================
33
  # VASTU RULES
34
+ # ===============================
35
 
36
  VASTU = {
37
  "bedroom": "South-West",
38
  "kitchen": "South-East",
39
+ "puja": "North-East",
40
  "hall": "Center",
41
  "toilet": "North-West",
42
  "stairs": "South"
43
  }
44
 
45
 
46
+ # ===============================
47
  # PROMPT BUILDER
48
+ # ===============================
49
 
50
+ def build_prompt(width, height, entrance):
51
 
52
  return f"""
53
  professional architectural blueprint,
54
  clean 2D floor plan,
55
  black and white CAD drawing,
 
56
  top view,
57
+ technical drafting,
58
+ thin lines,
59
+ no color,
60
+ no shading,
61
  labeled rooms,
62
 
63
+ plot size {width} x {height} feet,
64
  entrance facing {entrance},
65
 
66
  bedroom in {VASTU['bedroom']},
67
  kitchen in {VASTU['kitchen']},
68
+ puja room in {VASTU['puja']},
69
  living hall in {VASTU['hall']},
70
  toilet in {VASTU['toilet']},
71
  stairs in {VASTU['stairs']},
72
 
73
+ engineering drawing,
74
+ printable layout,
75
+ scale plan
 
76
  """
77
 
78
 
79
+ NEGATIVE_PROMPT = """
80
+ 3d, color, colorful, painting, sketch,
81
+ art, render, realistic, photo,
82
+ shadow, shading, texture,
83
+ cartoon, blurry, messy
84
  """
85
 
86
 
87
+ # ===============================
88
+ # GENERATOR FUNCTION
89
+ # ===============================
90
 
91
  def generate_plan(width, height, entrance):
92
 
 
94
 
95
  image = pipe(
96
  prompt=prompt,
97
+ negative_prompt=NEGATIVE_PROMPT,
98
+ num_inference_steps=30,
99
+ guidance_scale=8.5,
100
+ height=768,
101
+ width=768
102
  ).images[0]
103
 
104
  return image
105
 
106
 
107
+ # ===============================
108
+ # GRADIO UI
109
+ # ===============================
110
 
111
+ with gr.Blocks(title="๐Ÿ  Vastu 2D Plan Generator") as app:
112
 
113
+ gr.Markdown(
114
+ """
115
+ # ๐Ÿ  Vastu 2D Floor Plan Generator
116
+ Generate clean blueprint style house plans using AI
117
+ """
118
+ )
119
 
120
  with gr.Row():
121
 
122
+ width = gr.Textbox(
123
+ label="Plot Width (feet)",
124
+ placeholder="Example: 40"
125
+ )
126
 
127
+ height = gr.Textbox(
128
+ label="Plot Height (feet)",
129
+ placeholder="Example: 60"
 
130
  )
131
 
132
+ entrance = gr.Dropdown(
133
+ ["North", "South", "East", "West"],
134
+ label="Entrance Direction",
135
+ value="East"
136
+ )
137
+
138
+ btn = gr.Button("Generate Plan ๐Ÿš€")
139
 
140
+ output = gr.Image(
141
+ label="Generated Plan",
142
+ type="pil"
143
+ )
144
 
145
  btn.click(
146
+ fn=generate_plan,
147
  inputs=[width, height, entrance],
148
  outputs=output
149
  )
150
 
151
 
152
+ # ===============================
153
+ # LAUNCH
154
+ # ===============================
155
+
156
+ app.launch()