Ajay D commited on
Commit
910d183
Β·
verified Β·
1 Parent(s): c6bff56
Files changed (1) hide show
  1. app.py +73 -66
app.py CHANGED
@@ -1,86 +1,88 @@
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
 
@@ -89,47 +91,52 @@ def generate_plan(width, height, entrance):
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,
 
1
  import torch
2
  import gradio as gr
3
+ from diffusers import AutoPipelineForText2Image
4
 
5
 
6
+ # =========================
7
  # DEVICE
8
+ # =========================
9
+
10
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
11
 
12
 
13
+ # =========================
14
+ # LOAD FAST MODEL (SD-TURBO)
15
+ # =========================
16
+
17
+ print("Loading SD-Turbo Model...")
18
 
19
+ pipe = AutoPipelineForText2Image.from_pretrained(
20
+ "stabilityai/sd-turbo",
21
+ torch_dtype=torch.float16
22
+ ).to(DEVICE)
23
 
24
+ pipe.enable_xformers_memory_efficient_attention()
25
 
26
+ print("Model Loaded βœ…")
 
 
 
27
 
 
28
 
29
+ # =========================
30
+ # VASTU RULES
31
+ # =========================
32
 
33
+ VASTU = {
34
+ "bedroom": "South-West",
35
+ "kitchen": "South-East",
36
+ "pooja": "North-East",
37
+ "hall": "Center",
38
+ "toilet": "North-West",
39
+ "stairs": "South"
40
+ }
41
 
42
 
43
+ # =========================
44
  # PROMPT BUILDER
45
+ # =========================
46
 
47
  def build_prompt(width, height, entrance):
48
 
49
+ return f"""
 
 
 
 
 
 
 
 
 
50
  professional architectural blueprint,
51
+ clean 2D house floor plan,
52
  black and white CAD drawing,
53
+ technical line art,
54
+ top view layout,
 
 
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
+ pooja in {VASTU['pooja']},
63
+ living hall in {VASTU['hall']},
64
+ toilet in {VASTU['toilet']},
65
+ stairs in {VASTU['stairs']},
66
+
67
+ walls doors windows,
68
+ dimension lines,
69
+ north arrow,
70
+ printable plan
71
  """
72
 
 
 
73
 
74
  NEGATIVE_PROMPT = """
75
  3d, color, colorful, painting, sketch,
76
+ render, realistic, photo,
77
+ shadow, shading, texture,
78
+ blur, messy, low quality,
79
+ cartoon, anime
80
  """
81
 
82
 
83
+ # =========================
84
  # GENERATE FUNCTION
85
+ # =========================
86
 
87
  def generate_plan(width, height, entrance):
88
 
 
91
  image = pipe(
92
  prompt=prompt,
93
  negative_prompt=NEGATIVE_PROMPT,
94
+ num_inference_steps=12, # FAST
95
+ guidance_scale=7.5,
96
+ height=512,
97
+ width=512
98
  ).images[0]
99
 
100
  return image
101
 
102
 
103
+ # =========================
104
  # GRADIO UI
105
+ # =========================
106
 
107
+ with gr.Blocks(title="Vastu AI Floor Plan Generator") as demo:
108
 
109
+ gr.Markdown(
110
+ """
111
+ # 🏠 Vastu 2D Floor Plan Generator
112
+ Generate clean blueprint style house plans using AI
113
+ """
114
+ )
115
 
116
  with gr.Row():
117
 
118
+ width = gr.Number(
119
  label="Plot Width (feet)",
120
+ value=40
121
  )
122
 
123
+ height = gr.Number(
124
  label="Plot Height (feet)",
125
+ value=60
126
  )
127
 
128
  entrance = gr.Dropdown(
129
  ["North", "South", "East", "West"],
130
+ value="East",
131
+ label="Entrance Direction"
132
  )
133
 
134
+ generate_btn = gr.Button("Generate Plan πŸš€", variant="primary")
135
 
136
+ output = gr.Image(
137
+ label="Generated Plan",
138
+ type="pil"
139
+ )
140
 
141
  generate_btn.click(
142
  fn=generate_plan,