Spaces:
Sleeping
Sleeping
Ajay D commited on
final test
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import torch
|
| 2 |
import gradio as gr
|
| 3 |
-
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
# =========================
|
|
@@ -11,17 +12,20 @@ DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
|
| 11 |
|
| 12 |
|
| 13 |
# =========================
|
| 14 |
-
# LOAD
|
| 15 |
# =========================
|
| 16 |
|
| 17 |
-
print("Loading
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
pipe =
|
| 20 |
-
"stabilityai/sd-turbo",
|
| 21 |
-
torch_dtype=torch.float16
|
| 22 |
-
).to(DEVICE)
|
| 23 |
|
| 24 |
-
pipe.
|
| 25 |
|
| 26 |
print("Model Loaded β
")
|
| 27 |
|
|
@@ -44,17 +48,17 @@ VASTU = {
|
|
| 44 |
# PROMPT BUILDER
|
| 45 |
# =========================
|
| 46 |
|
| 47 |
-
def build_prompt(
|
| 48 |
|
| 49 |
return f"""
|
| 50 |
professional architectural blueprint,
|
| 51 |
-
clean 2D
|
| 52 |
black and white CAD drawing,
|
| 53 |
technical line art,
|
| 54 |
-
top view
|
| 55 |
labeled rooms,
|
| 56 |
|
| 57 |
-
plot size {
|
| 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 |
-
|
|
|
|
| 71 |
"""
|
| 72 |
|
| 73 |
|
| 74 |
-
|
| 75 |
-
3d, color, colorful, painting,
|
| 76 |
-
|
| 77 |
-
|
| 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=
|
| 94 |
-
num_inference_steps=
|
| 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 |
-
#
|
| 105 |
# =========================
|
| 106 |
|
| 107 |
-
with gr.Blocks(
|
| 108 |
|
| 109 |
-
gr.Markdown(
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
"""
|
| 114 |
-
)
|
| 115 |
|
| 116 |
with gr.Row():
|
| 117 |
|
| 118 |
-
width = gr.Number(
|
| 119 |
-
|
| 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
|
| 132 |
)
|
| 133 |
|
| 134 |
-
|
| 135 |
|
| 136 |
-
output = gr.Image(
|
| 137 |
-
label="Generated Plan",
|
| 138 |
-
type="pil"
|
| 139 |
-
)
|
| 140 |
|
| 141 |
-
|
| 142 |
-
|
| 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 |
)
|