Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from diffusers import StableDiffusionImg2ImgPipeline
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
MODEL_ID = "runwayml/stable-diffusion-v1-5"
|
| 7 |
+
|
| 8 |
+
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
|
| 9 |
+
MODEL_ID,
|
| 10 |
+
torch_dtype=torch.float16
|
| 11 |
+
).to("cuda")
|
| 12 |
+
|
| 13 |
+
pipe.safety_checker = None # optional, speeds things up
|
| 14 |
+
|
| 15 |
+
def redesign_room(
|
| 16 |
+
image,
|
| 17 |
+
style,
|
| 18 |
+
colors,
|
| 19 |
+
lighting,
|
| 20 |
+
strength
|
| 21 |
+
):
|
| 22 |
+
prompt = f"""
|
| 23 |
+
Redesign the interior of this room while keeping the same layout,
|
| 24 |
+
walls, windows, doors, and camera angle.
|
| 25 |
+
|
| 26 |
+
Interior style: {style}
|
| 27 |
+
Color palette: {colors}
|
| 28 |
+
Lighting: {lighting}
|
| 29 |
+
|
| 30 |
+
Photorealistic interior design, realistic shadows,
|
| 31 |
+
interior photography, high detail.
|
| 32 |
+
"""
|
| 33 |
+
|
| 34 |
+
image = image.convert("RGB").resize((512, 512))
|
| 35 |
+
|
| 36 |
+
result = pipe(
|
| 37 |
+
prompt=prompt,
|
| 38 |
+
image=image,
|
| 39 |
+
strength=strength,
|
| 40 |
+
guidance_scale=7.5,
|
| 41 |
+
num_inference_steps=30
|
| 42 |
+
).images[0]
|
| 43 |
+
|
| 44 |
+
return result
|
| 45 |
+
|
| 46 |
+
with gr.Blocks(title="Room Redesign AI") as demo:
|
| 47 |
+
gr.Markdown("## 🏠 AI Room Redesign (Image-to-Image)")
|
| 48 |
+
|
| 49 |
+
with gr.Row():
|
| 50 |
+
image_input = gr.Image(label="Upload Room Image", type="pil")
|
| 51 |
+
|
| 52 |
+
with gr.Row():
|
| 53 |
+
style = gr.Dropdown(
|
| 54 |
+
["Modern", "Luxury", "Scandinavian", "Minimal", "Japanese"],
|
| 55 |
+
value="Modern",
|
| 56 |
+
label="Interior Style"
|
| 57 |
+
)
|
| 58 |
+
colors = gr.Textbox(
|
| 59 |
+
value="white, beige, wood",
|
| 60 |
+
label="Color Palette"
|
| 61 |
+
)
|
| 62 |
+
lighting = gr.Textbox(
|
| 63 |
+
value="warm ambient lighting",
|
| 64 |
+
label="Lighting"
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
strength = gr.Slider(
|
| 68 |
+
minimum=0.2,
|
| 69 |
+
maximum=0.6,
|
| 70 |
+
value=0.35,
|
| 71 |
+
step=0.05,
|
| 72 |
+
label="Redesign Strength (lower = preserve structure)"
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
output = gr.Image(label="Redesigned Room")
|
| 76 |
+
|
| 77 |
+
btn = gr.Button("Redesign Room")
|
| 78 |
+
|
| 79 |
+
btn.click(
|
| 80 |
+
redesign_room,
|
| 81 |
+
inputs=[image_input, style, colors, lighting, strength],
|
| 82 |
+
outputs=output
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
demo.launch()
|