Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
import os
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
from PIL import Image
|
|
@@ -36,4 +36,60 @@ gr.Interface(
|
|
| 36 |
outputs=gr.Image(label="Redesigned Room"),
|
| 37 |
title="AI Room Redesign (No Local Model)",
|
| 38 |
description="Upload a room image and redesign it using prompts"
|
| 39 |
-
).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""import gradio as gr
|
| 2 |
import os
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
from PIL import Image
|
|
|
|
| 36 |
outputs=gr.Image(label="Redesigned Room"),
|
| 37 |
title="AI Room Redesign (No Local Model)",
|
| 38 |
description="Upload a room image and redesign it using prompts"
|
| 39 |
+
).launch()"""
|
| 40 |
+
|
| 41 |
+
import gradio as gr
|
| 42 |
+
from PIL import Image
|
| 43 |
+
from diffusers import StableDiffusionImg2ImgPipeline
|
| 44 |
+
import torch
|
| 45 |
+
|
| 46 |
+
# CPU pipeline
|
| 47 |
+
device = "cpu"
|
| 48 |
+
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
|
| 49 |
+
"runwayml/stable-diffusion-v1-5",
|
| 50 |
+
torch_dtype=torch.float32
|
| 51 |
+
).to(device)
|
| 52 |
+
pipe.safety_checker = lambda images, **kwargs: (images, [False]*len(images))
|
| 53 |
+
|
| 54 |
+
def redesign_room(image, style, colors, lighting, strength):
|
| 55 |
+
# Resize for CPU
|
| 56 |
+
image = image.convert("RGB").resize((512, 512))
|
| 57 |
+
|
| 58 |
+
prompt = f"""
|
| 59 |
+
Redesign this room with photorealistic style.
|
| 60 |
+
Preserve all existing walls, windows, doors, and furniture layout.
|
| 61 |
+
Interior style: {style}
|
| 62 |
+
Color palette: {colors}
|
| 63 |
+
Lighting: {lighting}
|
| 64 |
+
No distortions, no extra windows, no unrealistic objects.
|
| 65 |
+
High-quality render with realistic shadows.
|
| 66 |
+
"""
|
| 67 |
+
|
| 68 |
+
negative_prompt = "change room layout, move furniture, add windows, distort walls, cartoon"
|
| 69 |
+
|
| 70 |
+
result = pipe(
|
| 71 |
+
prompt=prompt,
|
| 72 |
+
image=image,
|
| 73 |
+
strength=strength,
|
| 74 |
+
guidance_scale=7.5,
|
| 75 |
+
num_inference_steps=20,
|
| 76 |
+
negative_prompt=negative_prompt
|
| 77 |
+
).images[0]
|
| 78 |
+
|
| 79 |
+
return result
|
| 80 |
+
|
| 81 |
+
with gr.Blocks() as demo:
|
| 82 |
+
gr.Markdown("## 🏠 AI Room Redesign (CPU-friendly)")
|
| 83 |
+
|
| 84 |
+
image_input = gr.Image(label="Upload Room Image", type="pil")
|
| 85 |
+
style = gr.Dropdown(["Modern","Luxury","Minimal","Scandinavian"], value="Modern", label="Style")
|
| 86 |
+
colors = gr.Textbox(value="white, beige, wood", label="Color Palette")
|
| 87 |
+
lighting = gr.Textbox(value="warm ambient lighting", label="Lighting")
|
| 88 |
+
strength = gr.Slider(0.2, 0.35, 0.25, step=0.05, label="Strength (low = keep layout)")
|
| 89 |
+
|
| 90 |
+
output = gr.Image(label="Redesigned Room")
|
| 91 |
+
btn = gr.Button("Redesign Room")
|
| 92 |
+
btn.click(redesign_room, [image_input, style, colors, lighting, strength], output)
|
| 93 |
+
|
| 94 |
+
demo.launch()
|
| 95 |
+
|