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()"""