Spaces:
Sleeping
Sleeping
test
#2
by ajayduraisamy - opened
app.py
CHANGED
|
@@ -1,136 +1,141 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
import torch
|
|
|
|
| 3 |
from diffusers import StableDiffusionPipeline
|
| 4 |
|
| 5 |
|
| 6 |
-
# ==========================
|
| 7 |
-
#
|
| 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 |
-
|
| 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(
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
"""
|
| 74 |
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 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=
|
| 94 |
num_inference_steps=30,
|
| 95 |
-
guidance_scale=
|
|
|
|
|
|
|
| 96 |
).images[0]
|
| 97 |
|
| 98 |
return image
|
| 99 |
|
| 100 |
|
| 101 |
-
# ==========================
|
| 102 |
-
# UI
|
| 103 |
-
# ==========================
|
| 104 |
|
| 105 |
-
|
| 106 |
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
gr.
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
label="Entrance Direction",
|
| 115 |
-
value="North"
|
| 116 |
)
|
| 117 |
-
],
|
| 118 |
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
-
|
| 124 |
-
Generate clean black & white 2D Vastu floor plans using AI.
|
| 125 |
-
Perfect for architects and builders.
|
| 126 |
-
""",
|
| 127 |
|
| 128 |
-
|
| 129 |
-
)
|
| 130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
-
# =============================
|
| 133 |
-
# RUN
|
| 134 |
-
# =============================
|
| 135 |
|
| 136 |
-
|
|
|
|
|
|
|
| 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()
|