Spaces:
Sleeping
Sleeping
Ajay D commited on
app.py
CHANGED
|
@@ -13,7 +13,7 @@ print("Using device:", device)
|
|
| 13 |
|
| 14 |
|
| 15 |
# ===============================
|
| 16 |
-
# LOAD MODEL
|
| 17 |
# ===============================
|
| 18 |
|
| 19 |
print("Loading Stable Diffusion Model...")
|
|
@@ -22,12 +22,15 @@ model_id = "runwayml/stable-diffusion-v1-5"
|
|
| 22 |
|
| 23 |
pipe = StableDiffusionPipeline.from_pretrained(
|
| 24 |
model_id,
|
| 25 |
-
torch_dtype=torch.float16 if device == "cuda" else torch.float32
|
|
|
|
| 26 |
)
|
| 27 |
|
| 28 |
pipe = pipe.to(device)
|
| 29 |
|
|
|
|
| 30 |
pipe.enable_attention_slicing()
|
|
|
|
| 31 |
|
| 32 |
print("Model Loaded Successfully")
|
| 33 |
|
|
@@ -38,7 +41,7 @@ print("Model Loaded Successfully")
|
|
| 38 |
|
| 39 |
def build_prompt(width, height, entrance):
|
| 40 |
|
| 41 |
-
|
| 42 |
professional architectural blueprint,
|
| 43 |
clean 2D house floor plan,
|
| 44 |
black and white,
|
|
@@ -60,18 +63,17 @@ def build_prompt(width, height, entrance):
|
|
| 60 |
toilet in north west,
|
| 61 |
staircase in south,
|
| 62 |
|
| 63 |
-
printable house plan
|
|
|
|
| 64 |
"""
|
| 65 |
|
| 66 |
-
return prompt
|
| 67 |
-
|
| 68 |
|
| 69 |
negative_prompt = """
|
| 70 |
3d, color, colorful, render, painting,
|
| 71 |
sketch, cartoon, anime, fantasy,
|
| 72 |
photo, realistic, texture,
|
| 73 |
shadow, shading, blur, messy,
|
| 74 |
-
low quality, watermark
|
| 75 |
"""
|
| 76 |
|
| 77 |
|
|
@@ -82,26 +84,28 @@ low quality, watermark
|
|
| 82 |
def generate_plan(width, height, entrance):
|
| 83 |
|
| 84 |
if not width or not height:
|
| 85 |
-
return None, "❌
|
| 86 |
|
| 87 |
prompt = build_prompt(width, height, entrance)
|
| 88 |
|
| 89 |
print("Prompt:", prompt)
|
| 90 |
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
|
|
|
|
|
|
| 99 |
|
| 100 |
return image, "✅ Plan Generated Successfully"
|
| 101 |
|
| 102 |
|
| 103 |
# ===============================
|
| 104 |
-
# UI
|
| 105 |
# ===============================
|
| 106 |
|
| 107 |
with gr.Blocks(title="Vastu AI Floor Plan Generator") as demo:
|
|
@@ -148,7 +152,7 @@ with gr.Blocks(title="Vastu AI Floor Plan Generator") as demo:
|
|
| 148 |
|
| 149 |
|
| 150 |
# ===============================
|
| 151 |
-
#
|
| 152 |
# ===============================
|
| 153 |
|
| 154 |
demo.launch()
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
# ===============================
|
| 16 |
+
# LOAD MODEL
|
| 17 |
# ===============================
|
| 18 |
|
| 19 |
print("Loading Stable Diffusion Model...")
|
|
|
|
| 22 |
|
| 23 |
pipe = StableDiffusionPipeline.from_pretrained(
|
| 24 |
model_id,
|
| 25 |
+
torch_dtype=torch.float16 if device == "cuda" else torch.float32,
|
| 26 |
+
safety_checker=None
|
| 27 |
)
|
| 28 |
|
| 29 |
pipe = pipe.to(device)
|
| 30 |
|
| 31 |
+
# Reduce memory usage (VERY IMPORTANT on HF)
|
| 32 |
pipe.enable_attention_slicing()
|
| 33 |
+
pipe.enable_model_cpu_offload()
|
| 34 |
|
| 35 |
print("Model Loaded Successfully")
|
| 36 |
|
|
|
|
| 41 |
|
| 42 |
def build_prompt(width, height, entrance):
|
| 43 |
|
| 44 |
+
return f"""
|
| 45 |
professional architectural blueprint,
|
| 46 |
clean 2D house floor plan,
|
| 47 |
black and white,
|
|
|
|
| 63 |
toilet in north west,
|
| 64 |
staircase in south,
|
| 65 |
|
| 66 |
+
printable house plan,
|
| 67 |
+
civil engineering drawing
|
| 68 |
"""
|
| 69 |
|
|
|
|
|
|
|
| 70 |
|
| 71 |
negative_prompt = """
|
| 72 |
3d, color, colorful, render, painting,
|
| 73 |
sketch, cartoon, anime, fantasy,
|
| 74 |
photo, realistic, texture,
|
| 75 |
shadow, shading, blur, messy,
|
| 76 |
+
low quality, watermark, logo, text
|
| 77 |
"""
|
| 78 |
|
| 79 |
|
|
|
|
| 84 |
def generate_plan(width, height, entrance):
|
| 85 |
|
| 86 |
if not width or not height:
|
| 87 |
+
return None, "❌ Please enter plot size"
|
| 88 |
|
| 89 |
prompt = build_prompt(width, height, entrance)
|
| 90 |
|
| 91 |
print("Prompt:", prompt)
|
| 92 |
|
| 93 |
+
with torch.no_grad():
|
| 94 |
+
|
| 95 |
+
image = pipe(
|
| 96 |
+
prompt=prompt,
|
| 97 |
+
negative_prompt=negative_prompt,
|
| 98 |
+
num_inference_steps=25,
|
| 99 |
+
guidance_scale=8.5,
|
| 100 |
+
height=768,
|
| 101 |
+
width=768
|
| 102 |
+
).images[0]
|
| 103 |
|
| 104 |
return image, "✅ Plan Generated Successfully"
|
| 105 |
|
| 106 |
|
| 107 |
# ===============================
|
| 108 |
+
# UI
|
| 109 |
# ===============================
|
| 110 |
|
| 111 |
with gr.Blocks(title="Vastu AI Floor Plan Generator") as demo:
|
|
|
|
| 152 |
|
| 153 |
|
| 154 |
# ===============================
|
| 155 |
+
# RUN
|
| 156 |
# ===============================
|
| 157 |
|
| 158 |
demo.launch()
|