File size: 2,870 Bytes
c8f9024
d728c4f
 
8cdb55f
d728c4f
8cdb55f
d728c4f
 
 
 
27fc781
 
d728c4f
 
cf8213e
d728c4f
 
8cdb55f
d728c4f
 
 
8cdb55f
d728c4f
 
27fc781
 
d728c4f
8cdb55f
 
d728c4f
 
 
 
 
 
 
 
 
c8f9024
61ba428
c8f9024
61ba428
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c8f9024
61ba428
 
 
 
 
 
 
c8f9024
61ba428
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c8f9024
61ba428
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import gradio as gr
import os
from huggingface_hub import InferenceClient
from PIL import Image
import tempfile

# Create HF client
client = InferenceClient(
    model="stabilityai/stable-diffusion-xl-base-1.0",
    token=os.environ["HF_TOKEN"]
)

def redesign_room(image, prompt):
    # Save uploaded image temporarily
    with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as tmp:
        image.save(tmp.name)
        image_path = tmp.name

    # Call HF API (NO local inference)
    output_image = client.image_to_image(
        image=image_path,
        prompt=prompt,
        guidance_scale=7,
        num_inference_steps=30
    )

    return output_image


gr.Interface(
    fn=redesign_room,
    inputs=[
        gr.Image(type="pil", label="Upload Room Image"),
        gr.Textbox(label="Design Prompt", placeholder="Modern Scandinavian interior, warm lighting...")
    ],
    outputs=gr.Image(label="Redesigned Room"),
    title="AI Room Redesign (No Local Model)",
    description="Upload a room image and redesign it using prompts"
).launch()

""""import gradio as gr
from PIL import Image
from diffusers import StableDiffusionImg2ImgPipeline
import torch

# CPU pipeline
device = "cpu"
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    torch_dtype=torch.float32
).to(device)
pipe.safety_checker = lambda images, **kwargs: (images, [False]*len(images))

def redesign_room(image, style, colors, lighting, strength):
    # Resize for CPU
    image = image.convert("RGB").resize((512, 512))

    prompt = f"
Redesign this room with photorealistic style. 
Preserve all existing walls, windows, doors, and furniture layout. 
Interior style: {style}
Color palette: {colors}
Lighting: {lighting}
No distortions, no extra windows, no unrealistic objects.
High-quality render with realistic shadows.
"

    negative_prompt = "change room layout, move furniture, add windows, distort walls, cartoon"

    result = pipe(
        prompt=prompt,
        image=image,
        strength=strength,
        guidance_scale=7.5,
        num_inference_steps=20,
        negative_prompt=negative_prompt
    ).images[0]

    return result

with gr.Blocks() as demo:
    gr.Markdown("## 🏠 AI Room Redesign (CPU-friendly)")

    image_input = gr.Image(label="Upload Room Image", type="pil")
    style = gr.Dropdown(["Modern","Luxury","Minimal","Scandinavian"], value="Modern", label="Style")
    colors = gr.Textbox(value="white, beige, wood", label="Color Palette")
    lighting = gr.Textbox(value="warm ambient lighting", label="Lighting")
    strength = gr.Slider(0.2, 0.35, 0.25, step=0.05, label="Strength (low = keep layout)")

    output = gr.Image(label="Redesigned Room")
    btn = gr.Button("Redesign Room")
    btn.click(redesign_room, [image_input, style, colors, lighting, strength], output)

demo.launch()"""