facadelighting commited on
Commit
9e9c4f0
·
verified ·
1 Parent(s): a8f397e

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +12 -28
index.html CHANGED
@@ -1,20 +1,3 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1">
6
- <title>Building Facade Lighting</title>
7
-
8
- <script type="module" crossorigin src="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.js"></script>
9
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.css" />
10
-
11
- <style>
12
- html, body { margin:0; padding:0; height:100%; }
13
- </style>
14
- </head>
15
- <body>
16
- <gradio-lite>
17
- <gradio-file name="app.py" entrypoint>
18
  import gradio as gr
19
  from PIL import Image, ImageEnhance, ImageDraw
20
  import cv2
@@ -43,9 +26,10 @@ def parse_colors(text):
43
  def detect_building_mask(pil_image):
44
  img = np.array(pil_image)
45
  gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
46
- edges = cv2.Canny(gray, 100, 200)
47
- kernel = np.ones((5,5), np.uint8)
48
- mask = cv2.dilate(edges, kernel, iterations=2)
 
49
  return mask # mask = 255 where building edges/windows exist
50
 
51
  def draw_lights_on_mask(pil_image, mask, colors):
@@ -54,8 +38,9 @@ def draw_lights_on_mask(pil_image, mask, colors):
54
  mask_img = Image.fromarray(mask)
55
  mask_pixels = mask_img.load()
56
 
57
- step_x = max(width//60,1)
58
- step_y = max(height//60,1)
 
59
 
60
  for x in range(0, width, step_x):
61
  for y in range(0, height, step_y):
@@ -69,17 +54,16 @@ def facade_lighting(image, prompt):
69
  if not isinstance(image, Image.Image):
70
  image = Image.fromarray(image)
71
 
72
- # Darken the building (simulate night)
73
- enhancer = ImageEnhance.Brightness(image)
74
- dark_image = enhancer.enhance(0.3)
75
 
76
- # Get colors from text prompt
77
  colors = parse_colors(prompt)
78
 
79
  # Detect building structure
80
  mask = detect_building_mask(dark_image)
81
 
82
- # Draw lights only on building
83
  output_image = draw_lights_on_mask(dark_image, mask, colors)
84
  return output_image
85
 
@@ -93,4 +77,4 @@ demo = gr.Interface(
93
  examples=[["building.jpg", "orange and purple lights"]]
94
  )
95
 
96
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  from PIL import Image, ImageEnhance, ImageDraw
3
  import cv2
 
26
  def detect_building_mask(pil_image):
27
  img = np.array(pil_image)
28
  gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
29
+ # Detect edges
30
+ edges = cv2.Canny(gray, 50, 150)
31
+ # Dilate edges to cover full building area
32
+ mask = cv2.dilate(edges, np.ones((15,15),np.uint8), iterations=3)
33
  return mask # mask = 255 where building edges/windows exist
34
 
35
  def draw_lights_on_mask(pil_image, mask, colors):
 
38
  mask_img = Image.fromarray(mask)
39
  mask_pixels = mask_img.load()
40
 
41
+ # Step size smaller → lights cover full building
42
+ step_x = max(width // 40, 5)
43
+ step_y = max(height // 40, 5)
44
 
45
  for x in range(0, width, step_x):
46
  for y in range(0, height, step_y):
 
54
  if not isinstance(image, Image.Image):
55
  image = Image.fromarray(image)
56
 
57
+ # Darken building first
58
+ dark_image = ImageEnhance.Brightness(image).enhance(0.3)
 
59
 
60
+ # Parse colors from text
61
  colors = parse_colors(prompt)
62
 
63
  # Detect building structure
64
  mask = detect_building_mask(dark_image)
65
 
66
+ # Draw facade lights on dark building
67
  output_image = draw_lights_on_mask(dark_image, mask, colors)
68
  return output_image
69
 
 
77
  examples=[["building.jpg", "orange and purple lights"]]
78
  )
79
 
80
+ demo.launch()