mushafdev commited on
Commit
27fc781
·
verified ·
1 Parent(s): 2344487

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -34
app.py CHANGED
@@ -5,20 +5,22 @@ 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.
@@ -38,31 +40,25 @@ interior photography, high detail.
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,
@@ -75,7 +71,6 @@ with gr.Blocks(title="Room Redesign AI") as demo:
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],
 
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.
 
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,
 
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],