Ajay D commited on
Commit
a004fbe
Β·
verified Β·
1 Parent(s): 607bacd

final test

Browse files
Files changed (1) hide show
  1. app.py +38 -47
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import torch
2
  import gradio as gr
3
- from diffusers import AutoPipelineForText2Image
 
4
 
5
 
6
  # =========================
@@ -11,17 +12,20 @@ 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
 
@@ -44,17 +48,17 @@ VASTU = {
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']},
@@ -64,18 +68,17 @@ def build_prompt(width, height, entrance):
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
 
@@ -90,8 +93,8 @@ def generate_plan(width, height, entrance):
90
 
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
@@ -101,45 +104,33 @@ def generate_plan(width, height, entrance):
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,
143
  inputs=[width, height, entrance],
144
  outputs=output
145
  )
 
1
  import torch
2
  import gradio as gr
3
+
4
+ from diffusers import StableDiffusionPipeline
5
 
6
 
7
  # =========================
 
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
 
 
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']},
 
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
 
 
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
 
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
  )