JuanMa360 commited on
Commit
8fc2390
·
1 Parent(s): aea1ab7

bugfix: generals

Browse files
Files changed (1) hide show
  1. app.py +35 -37
app.py CHANGED
@@ -41,18 +41,18 @@ weights = {
41
  "Does the image show protective materials?": 0.05
42
  }
43
 
44
- #luminosity_classes = [
45
- # 'A well-lit room with abundant natural light, showcasing windows or a balcony through which sunlight passes unobstructed.',
46
- # 'A room depicted in darkness, where there is minimal or no visible light source.',
47
- # 'A room illuminated by artificial light sources such as lamps or ceiling lights.'
48
- #]
49
-
50
  luminosity_classes = [
51
- "A room filled with natural daylight.",
52
- "A room lit by artificial lights.",
53
- "A dark room with no lights."
54
  ]
55
 
 
 
 
 
 
 
56
  luminosity_labels = ['natural_light', 'no_light', 'artificial_light']
57
 
58
  view_questions = [
@@ -145,22 +145,18 @@ def calculate_is_render(processed_image):
145
  def generate_answer(image):
146
 
147
  processed_image = image
148
- processed_image = processed_image.resize((256, 256))
149
 
150
  image_data = {
151
  "image_context": None,
 
152
  "equipment_score": None,
153
- "luminosity_score": {"score": None,
154
- "has_window": {
155
- "score": None,
156
- "answer": None
157
- }},
158
  "view_type": {"views": None, "certainty_score": None}
159
  }
160
 
161
  space_type_score = calculate_space_type(processed_image)
162
  max_space_type = max(space_type_score, key=space_type_score.get)
163
- if space_type_score[max_space_type] >= threshold:
164
  space_type = max_space_type.lower()
165
  if space_type == "patio":
166
  space_type = "terrace"
@@ -168,27 +164,29 @@ def generate_answer(image):
168
 
169
  image_results = {}
170
  if max_space_type == "terrace":
171
- for question in equipment_questions:
172
- result = vqa_pipeline(processed_image, question, top_k=1)
173
- answer = result[0]['answer'].lower() == "yes"
174
- image_results[question] = answer
175
- equipment_score = calculate_equipment_score(image_results, weights)
176
- image_data["equipment_score"] = equipment_score
177
-
178
- if max_space_type in ["bedroom", "living room", "kitchen"]:
179
- luminosity_score = calculate_luminosity_score(processed_image)
180
- image_data["luminosity_score"]['score'] = luminosity_score['natural_light']
181
-
182
- result = vqa_pipeline(processed_image, "Is there a real window?", top_k=1)
183
- has_window = result[0]
184
- image_data["luminosity_score"]["has_window"] = has_window
185
-
186
- view = views(processed_image)
187
- image_data["view_type"]["views"] = view
188
-
189
- certainty_score = certainty(processed_image)
190
- certainty_score = list(certainty_score.values())[0]
191
- image_data["view_type"]["certainty_score"] = certainty_score
 
 
192
 
193
  #is_render = calculate_is_render(processed_image)
194
  #image_data["is_render"] = is_render
 
41
  "Does the image show protective materials?": 0.05
42
  }
43
 
 
 
 
 
 
 
44
  luminosity_classes = [
45
+ 'A well-lit room with abundant natural light, showcasing windows or a balcony through which sunlight passes unobstructed.',
46
+ 'A room depicted in darkness, where there is minimal or no visible light source.',
47
+ 'A room illuminated by artificial light sources such as lamps or ceiling lights.'
48
  ]
49
 
50
+ #luminosity_classes = [
51
+ # "A room filled with natural daylight.",
52
+ # "A room lit by artificial lights.",
53
+ # "A dark room with no lights."
54
+ #]
55
+
56
  luminosity_labels = ['natural_light', 'no_light', 'artificial_light']
57
 
58
  view_questions = [
 
145
  def generate_answer(image):
146
 
147
  processed_image = image
 
148
 
149
  image_data = {
150
  "image_context": None,
151
+ "validation": None,
152
  "equipment_score": None,
153
+ "luminosity_score": {"score": None},
 
 
 
 
154
  "view_type": {"views": None, "certainty_score": None}
155
  }
156
 
157
  space_type_score = calculate_space_type(processed_image)
158
  max_space_type = max(space_type_score, key=space_type_score.get)
159
+ if space_type_score[max_space_type] >= 0:
160
  space_type = max_space_type.lower()
161
  if space_type == "patio":
162
  space_type = "terrace"
 
164
 
165
  image_results = {}
166
  if max_space_type == "terrace":
167
+ for question in equipment_questions:
168
+ result = vqa_pipeline(processed_image, question, top_k=1)
169
+ answer = result[0]['answer'].lower() == "yes"
170
+ image_results[question] = answer
171
+ equipment_score = calculate_equipment_score(image_results, weights)
172
+ image_data["equipment_score"] = equipment_score
173
+
174
+ result = vqa_pipeline(processed_image, "Is there a real window?", top_k=1)
175
+ has_window = result[0]
176
+ image_data["validation"] = "pass validation" if has_window['score'] > 0.9 else "No candidate"
177
+
178
+ window_exists = has_window["answer"].lower() == "yes" and has_window["score"] > 0.9
179
+
180
+ if window_exists:
181
+ luminosity_score = calculate_luminosity_score(processed_image)
182
+ image_data["luminosity_score"]['score'] = luminosity_score['natural_light']
183
+
184
+ view = views(processed_image)
185
+ image_data["view_type"]["views"] = view
186
+
187
+ certainty_score = certainty(processed_image)
188
+ certainty_score = list(certainty_score.values())[0]
189
+ image_data["view_type"]["certainty_score"] = certainty_score
190
 
191
  #is_render = calculate_is_render(processed_image)
192
  #image_data["is_render"] = is_render