import torch import gradio as gr from diffusers import StableDiffusionPipeline # ========================== # DEVICE # ========================== DEVICE = "cuda" if torch.cuda.is_available() else "cpu" # ========================== # LOAD MODEL # ========================== print("Loading Stable Diffusion Model...") model_id = "runwayml/stable-diffusion-v1-5" pipe = StableDiffusionPipeline.from_pretrained( model_id, torch_dtype=torch.float16 if DEVICE == "cuda" else torch.float32 ) pipe = pipe.to(DEVICE) pipe.enable_attention_slicing() print("Model Loaded Successfully") # ========================== # PROMPT BUILDER # ========================== def build_prompt(width, height, entrance): vastu = { "bedroom": "South-West", "kitchen": "South-East", "puja": "North-East", "hall": "Center", "toilet": "North-West", "stairs": "South" } prompt = f""" professional architectural blueprint, clean 2D floor plan, black and white CAD drawing, top view technical plan, thin lines, no colors, no shading, labeled rooms, plot size {width} x {height} feet, entrance facing {entrance}, bedroom in {vastu['bedroom']}, kitchen in {vastu['kitchen']}, puja room in {vastu['puja']}, living hall in {vastu['hall']}, toilet in {vastu['toilet']}, staircase in {vastu['stairs']}, printable house plan """ return prompt NEGATIVE_PROMPT = """ 3d, color, colorful, painting, sketch, cartoon, fantasy, render, realistic, photo, texture, shadow, blur, low quality, messy """ # ========================== # GENERATE FUNCTION # ========================== def generate_plan(width, height, entrance): prompt = build_prompt(width, height, entrance) image = pipe( prompt=prompt, negative_prompt=NEGATIVE_PROMPT, num_inference_steps=30, guidance_scale=9, height=768, width=768 ).images[0] return image # ========================== # GRADIO UI # ========================== with gr.Blocks(title="Vastu 2D Plan Generator") as demo: gr.Markdown(""" # 🏠 Vastu 2D Floor Plan Generator Generate clean blueprint style house plans using AI """) with gr.Row(): width = gr.Textbox( label="Plot Width (feet)", placeholder="Example: 40" ) height = gr.Textbox( label="Plot Height (feet)", placeholder="Example: 60" ) entrance = gr.Dropdown( ["North", "South", "East", "West"], label="Entrance Direction", value="East" ) generate_btn = gr.Button("Generate Plan 🚀") output = gr.Image(label="Generated Plan") generate_btn.click( fn=generate_plan, inputs=[width, height, entrance], outputs=output ) demo.launch()