Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,57 +1,23 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
-
from diffusers import StableDiffusionPipeline
|
| 4 |
|
| 5 |
-
# Load
|
| 6 |
-
model_id = "runwayml/stable-diffusion-v1-5"
|
| 7 |
pipe = StableDiffusionPipeline.from_pretrained(
|
| 8 |
-
|
| 9 |
torch_dtype=torch.float16,
|
|
|
|
| 10 |
safety_checker=None
|
| 11 |
)
|
| 12 |
-
pipe.
|
| 13 |
-
pipe.enable_attention_slicing()
|
| 14 |
|
| 15 |
-
#
|
| 16 |
-
pipe
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
pipe.load_lora_weights(
|
| 20 |
-
"ejazhabibdar/sd-FloorPlan-model",
|
| 21 |
-
weight_name="pytorch_lora_weights.safetensors"
|
| 22 |
-
)
|
| 23 |
-
|
| 24 |
-
# Prompt generation logic
|
| 25 |
def generate_floorplan(bedrooms, bathrooms, floors, plot_size):
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
size_map = {"small": "small", "medium": "", "large": "big"}
|
| 29 |
-
size_word = size_map.get(plot_size.lower(), "")
|
| 30 |
-
if size_word:
|
| 31 |
-
prompt_parts.append(f"{size_word} house")
|
| 32 |
-
else:
|
| 33 |
-
prompt_parts.append("house")
|
| 34 |
-
|
| 35 |
-
if bedrooms <= 2:
|
| 36 |
-
prompt_parts.append("few rooms")
|
| 37 |
-
elif bedrooms >= 5:
|
| 38 |
-
prompt_parts.append("many rooms")
|
| 39 |
-
else:
|
| 40 |
-
prompt_parts.append(f"{bedrooms} rooms")
|
| 41 |
-
|
| 42 |
-
if bathrooms == 1:
|
| 43 |
-
prompt_parts.append("one bathroom")
|
| 44 |
-
else:
|
| 45 |
-
prompt_parts.append(f"{bathrooms} bathrooms")
|
| 46 |
-
|
| 47 |
-
if floors == 1:
|
| 48 |
-
prompt_parts.append("one floor")
|
| 49 |
-
else:
|
| 50 |
-
prompt_parts.append(f"{floors} floors")
|
| 51 |
-
|
| 52 |
-
prompt = "Floor plan of a " + ", ".join(prompt_parts) + "."
|
| 53 |
-
|
| 54 |
-
image = pipe(prompt, num_inference_steps=25, guidance_scale=7.5).images[0]
|
| 55 |
return image
|
| 56 |
|
| 57 |
# Gradio UI
|
|
@@ -63,9 +29,8 @@ with gr.Blocks() as demo:
|
|
| 63 |
with gr.Row():
|
| 64 |
floors = gr.Slider(label="Floors", minimum=1, maximum=3, value=1)
|
| 65 |
plot_size = gr.Dropdown(label="Plot Size", choices=["Small", "Medium", "Large"], value="Medium")
|
| 66 |
-
|
| 67 |
-
generate_btn = gr.Button("Generate Floor Plan")
|
| 68 |
output_image = gr.Image(label="Generated Floor Plan", type="pil")
|
|
|
|
| 69 |
|
| 70 |
generate_btn.click(
|
| 71 |
fn=generate_floorplan,
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
+
from diffusers import StableDiffusionPipeline
|
| 4 |
|
| 5 |
+
# Load base Stable Diffusion model
|
|
|
|
| 6 |
pipe = StableDiffusionPipeline.from_pretrained(
|
| 7 |
+
"runwayml/stable-diffusion-v1-5",
|
| 8 |
torch_dtype=torch.float16,
|
| 9 |
+
revision="fp16",
|
| 10 |
safety_checker=None
|
| 11 |
)
|
| 12 |
+
pipe.to("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
|
| 13 |
|
| 14 |
+
# Load the FloorPlan LoRA weights
|
| 15 |
+
pipe.load_lora_weights("ejazhabibdar/sd-FloorPlan-model", weight_name="pytorch_lora_weights.safetensors")
|
| 16 |
|
| 17 |
+
# Prompt builder
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
def generate_floorplan(bedrooms, bathrooms, floors, plot_size):
|
| 19 |
+
prompt = f"Floor plan of a {plot_size.lower()} house with {bedrooms} bedrooms, {bathrooms} bathrooms, {floors} floors."
|
| 20 |
+
image = pipe(prompt, num_inference_steps=30, guidance_scale=7.5).images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
return image
|
| 22 |
|
| 23 |
# Gradio UI
|
|
|
|
| 29 |
with gr.Row():
|
| 30 |
floors = gr.Slider(label="Floors", minimum=1, maximum=3, value=1)
|
| 31 |
plot_size = gr.Dropdown(label="Plot Size", choices=["Small", "Medium", "Large"], value="Medium")
|
|
|
|
|
|
|
| 32 |
output_image = gr.Image(label="Generated Floor Plan", type="pil")
|
| 33 |
+
generate_btn = gr.Button("Generate Floor Plan")
|
| 34 |
|
| 35 |
generate_btn.click(
|
| 36 |
fn=generate_floorplan,
|