Spaces:
Sleeping
Sleeping
Ajay D commited on
sss
Browse files
app.py
CHANGED
|
@@ -26,6 +26,8 @@ pipe = StableDiffusionPipeline.from_pretrained(
|
|
| 26 |
|
| 27 |
pipe = pipe.to(DEVICE)
|
| 28 |
|
|
|
|
|
|
|
| 29 |
print("Model Loaded Successfully")
|
| 30 |
|
| 31 |
|
|
@@ -44,17 +46,17 @@ VASTU = {
|
|
| 44 |
|
| 45 |
|
| 46 |
# ===============================
|
| 47 |
-
# PROMPT
|
| 48 |
# ===============================
|
| 49 |
|
| 50 |
def build_prompt(width, height, entrance):
|
| 51 |
|
| 52 |
return f"""
|
| 53 |
professional architectural blueprint,
|
| 54 |
-
clean 2D floor plan,
|
| 55 |
black and white CAD drawing,
|
| 56 |
-
top view,
|
| 57 |
technical drafting,
|
|
|
|
| 58 |
thin lines,
|
| 59 |
no color,
|
| 60 |
no shading,
|
|
@@ -71,32 +73,32 @@ def build_prompt(width, height, entrance):
|
|
| 71 |
stairs in {VASTU['stairs']},
|
| 72 |
|
| 73 |
engineering drawing,
|
| 74 |
-
printable
|
| 75 |
scale plan
|
| 76 |
"""
|
| 77 |
|
| 78 |
|
| 79 |
-
|
| 80 |
-
3d, color,
|
| 81 |
-
|
| 82 |
shadow, shading, texture,
|
| 83 |
cartoon, blurry, messy
|
| 84 |
"""
|
| 85 |
|
| 86 |
|
| 87 |
# ===============================
|
| 88 |
-
#
|
| 89 |
# ===============================
|
| 90 |
|
| 91 |
-
def
|
| 92 |
|
| 93 |
prompt = build_prompt(width, height, entrance)
|
| 94 |
|
| 95 |
image = pipe(
|
| 96 |
prompt=prompt,
|
| 97 |
-
negative_prompt=
|
| 98 |
-
num_inference_steps=
|
| 99 |
-
guidance_scale=8.
|
| 100 |
height=768,
|
| 101 |
width=768
|
| 102 |
).images[0]
|
|
@@ -105,10 +107,10 @@ def generate_plan(width, height, entrance):
|
|
| 105 |
|
| 106 |
|
| 107 |
# ===============================
|
| 108 |
-
#
|
| 109 |
# ===============================
|
| 110 |
|
| 111 |
-
with gr.Blocks(
|
| 112 |
|
| 113 |
gr.Markdown(
|
| 114 |
"""
|
|
@@ -119,17 +121,10 @@ with gr.Blocks(title="π Vastu 2D Plan Generator") as app:
|
|
| 119 |
|
| 120 |
with gr.Row():
|
| 121 |
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
placeholder="Example: 40"
|
| 125 |
-
)
|
| 126 |
-
|
| 127 |
-
height = gr.Textbox(
|
| 128 |
-
label="Plot Height (feet)",
|
| 129 |
-
placeholder="Example: 60"
|
| 130 |
-
)
|
| 131 |
|
| 132 |
-
|
| 133 |
["North", "South", "East", "West"],
|
| 134 |
label="Entrance Direction",
|
| 135 |
value="East"
|
|
@@ -137,20 +132,9 @@ with gr.Blocks(title="π Vastu 2D Plan Generator") as app:
|
|
| 137 |
|
| 138 |
btn = gr.Button("Generate Plan π")
|
| 139 |
|
| 140 |
-
|
| 141 |
-
label="Generated Plan",
|
| 142 |
-
type="pil"
|
| 143 |
-
)
|
| 144 |
|
| 145 |
-
btn.click(
|
| 146 |
-
fn=generate_plan,
|
| 147 |
-
inputs=[width, height, entrance],
|
| 148 |
-
outputs=output
|
| 149 |
-
)
|
| 150 |
|
| 151 |
|
| 152 |
-
|
| 153 |
-
# LAUNCH
|
| 154 |
-
# ===============================
|
| 155 |
-
|
| 156 |
-
app.launch()
|
|
|
|
| 26 |
|
| 27 |
pipe = pipe.to(DEVICE)
|
| 28 |
|
| 29 |
+
pipe.enable_attention_slicing()
|
| 30 |
+
|
| 31 |
print("Model Loaded Successfully")
|
| 32 |
|
| 33 |
|
|
|
|
| 46 |
|
| 47 |
|
| 48 |
# ===============================
|
| 49 |
+
# PROMPT
|
| 50 |
# ===============================
|
| 51 |
|
| 52 |
def build_prompt(width, height, entrance):
|
| 53 |
|
| 54 |
return f"""
|
| 55 |
professional architectural blueprint,
|
| 56 |
+
ultra clean 2D floor plan,
|
| 57 |
black and white CAD drawing,
|
|
|
|
| 58 |
technical drafting,
|
| 59 |
+
top view layout,
|
| 60 |
thin lines,
|
| 61 |
no color,
|
| 62 |
no shading,
|
|
|
|
| 73 |
stairs in {VASTU['stairs']},
|
| 74 |
|
| 75 |
engineering drawing,
|
| 76 |
+
printable blueprint,
|
| 77 |
scale plan
|
| 78 |
"""
|
| 79 |
|
| 80 |
|
| 81 |
+
NEGATIVE = """
|
| 82 |
+
3d, color, painting, sketch,
|
| 83 |
+
render, realistic, photo,
|
| 84 |
shadow, shading, texture,
|
| 85 |
cartoon, blurry, messy
|
| 86 |
"""
|
| 87 |
|
| 88 |
|
| 89 |
# ===============================
|
| 90 |
+
# GENERATE
|
| 91 |
# ===============================
|
| 92 |
|
| 93 |
+
def generate(width, height, entrance):
|
| 94 |
|
| 95 |
prompt = build_prompt(width, height, entrance)
|
| 96 |
|
| 97 |
image = pipe(
|
| 98 |
prompt=prompt,
|
| 99 |
+
negative_prompt=NEGATIVE,
|
| 100 |
+
num_inference_steps=28,
|
| 101 |
+
guidance_scale=8.0,
|
| 102 |
height=768,
|
| 103 |
width=768
|
| 104 |
).images[0]
|
|
|
|
| 107 |
|
| 108 |
|
| 109 |
# ===============================
|
| 110 |
+
# UI
|
| 111 |
# ===============================
|
| 112 |
|
| 113 |
+
with gr.Blocks() as demo:
|
| 114 |
|
| 115 |
gr.Markdown(
|
| 116 |
"""
|
|
|
|
| 121 |
|
| 122 |
with gr.Row():
|
| 123 |
|
| 124 |
+
w = gr.Textbox(label="Plot Width (feet)", placeholder="40")
|
| 125 |
+
h = gr.Textbox(label="Plot Height (feet)", placeholder="60")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
+
e = gr.Dropdown(
|
| 128 |
["North", "South", "East", "West"],
|
| 129 |
label="Entrance Direction",
|
| 130 |
value="East"
|
|
|
|
| 132 |
|
| 133 |
btn = gr.Button("Generate Plan π")
|
| 134 |
|
| 135 |
+
out = gr.Image(label="Generated Plan", type="pil")
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
+
btn.click(generate, [w, h, e], out)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
|
| 140 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|