mushafdev commited on
Commit
d728c4f
·
verified ·
1 Parent(s): 95d67c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -69
app.py CHANGED
@@ -1,80 +1,39 @@
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
- # ✅ FORCE CPU
9
- device = "cpu"
10
- dtype = torch.float32
11
-
12
- pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
13
- MODEL_ID,
14
- torch_dtype=dtype
15
  )
16
 
17
- pipe = pipe.to(device)
18
-
19
- # Disable safety checker safely
20
- pipe.safety_checker = lambda images, **kwargs: (images, [False] * len(images))
21
-
22
-
23
- def redesign_room(image, style, colors, lighting, strength):
24
- prompt = f"""
25
- Redesign the interior of this room while keeping the same layout,
26
- walls, windows, doors, and camera angle.
27
 
28
- Interior style: {style}
29
- Color palette: {colors}
30
- Lighting: {lighting}
31
-
32
- Photorealistic interior design, realistic shadows,
33
- interior photography, high detail.
34
- """
35
-
36
- image = image.convert("RGB").resize((512, 512))
37
-
38
- result = pipe(
39
  prompt=prompt,
40
- image=image,
41
- strength=strength,
42
- guidance_scale=7.5,
43
- num_inference_steps=25
44
- ).images[0]
45
-
46
- return result
47
-
48
-
49
- with gr.Blocks(title="Room Redesign AI (CPU)") as demo:
50
- gr.Markdown("## 🏠 AI Room Redesign (CPU Mode)")
51
-
52
- image_input = gr.Image(label="Upload Room Image", type="pil")
53
-
54
- style = gr.Dropdown(
55
- ["Modern", "Luxury", "Scandinavian", "Minimal", "Japanese"],
56
- value="Modern",
57
- label="Interior Style"
58
  )
59
 
60
- colors = gr.Textbox(value="white, beige, wood", label="Color Palette")
61
- lighting = gr.Textbox(value="warm ambient lighting", label="Lighting")
62
 
63
- strength = gr.Slider(
64
- minimum=0.2,
65
- maximum=0.6,
66
- value=0.35,
67
- step=0.05,
68
- label="Redesign Strength (lower = preserve structure)"
69
- )
70
-
71
- output = gr.Image(label="Redesigned Room")
72
-
73
- btn = gr.Button("Redesign Room")
74
- btn.click(
75
- redesign_room,
76
- inputs=[image_input, style, colors, lighting, strength],
77
- outputs=output
78
- )
79
 
80
- demo.launch()
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import os
3
+ from huggingface_hub import InferenceClient
4
  from PIL import Image
5
+ import tempfile
6
 
7
+ # Create HF client
8
+ client = InferenceClient(
9
+ model="stabilityai/stable-diffusion-xl-base-1.0",
10
+ token=os.environ["HF_TOKEN"]
 
 
 
 
 
11
  )
12
 
13
+ def redesign_room(image, prompt):
14
+ # Save uploaded image temporarily
15
+ with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmp:
16
+ image.save(tmp.name)
17
+ image_path = tmp.name
 
 
 
 
 
18
 
19
+ # Call HF API (NO local inference)
20
+ output_image = client.image_to_image(
21
+ image=image_path,
 
 
 
 
 
 
 
 
22
  prompt=prompt,
23
+ guidance_scale=7,
24
+ num_inference_steps=30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  )
26
 
27
+ return output_image
 
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
+ gr.Interface(
31
+ fn=redesign_room,
32
+ inputs=[
33
+ gr.Image(type="pil", label="Upload Room Image"),
34
+ gr.Textbox(label="Design Prompt", placeholder="Modern Scandinavian interior, warm lighting...")
35
+ ],
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()