JuanMa360 commited on
Commit
991ef04
·
1 Parent(s): 352b9c8

refactor: response

Browse files
Files changed (1) hide show
  1. app.py +30 -15
app.py CHANGED
@@ -8,7 +8,7 @@ processor = CLIPProcessor.from_pretrained("tokenizer")
8
  vqa_pipeline = pipeline("visual-question-answering")
9
 
10
  space_type_labels = ["living room", "bedroom", "kitchen", "terrace", "closet","bathroom", "dining room", "office", "garage", "garden",
11
- "balcony", "attic", "hallway", "laundry room","home gym", "playroom", "storage room", "studio","is_exterior","empty_interior_room","others"]
12
 
13
  equipment_questions = [
14
  "Does the image show outdoor furniture?",
@@ -41,10 +41,11 @@ weights = {
41
  }
42
 
43
  luminosity_classes = [
44
- 'A picture of a room filled with abundant natural light with a lot or few windows or a great balcony regardless of whether it is night, without objects that prevent the light from passing through.',
45
- 'a picture of room in the dark',
46
- 'A picture of a room with Artificial lights like lamps or headlamps'
47
  ]
 
48
  luminosity_labels = ['natural_light', 'no_light', 'artificial_light']
49
 
50
  view_questions = [
@@ -52,13 +53,27 @@ view_questions = [
52
  "Is this a city view?",
53
  "Is this a view of greenery?",
54
  "Is this a mountain view?",
55
- "Is this a view of the sea?"
 
 
 
 
 
 
 
 
 
 
56
  ]
57
- view_labels = ['panoramic', 'city', 'greenery', 'mountain', 'sea']
58
 
59
- certainty_classes = ['windows, balcony or terrace with a view outwards','Exterior appearance of a house or apartment','unreal image or fake of any view','view outwards with not clear view outside']
60
 
61
- render_classes = ['is_unrealistic_image_render', 'is_image_real','empty_interior_room']
 
 
 
 
 
62
 
63
  threshold = 0
64
 
@@ -109,7 +124,7 @@ def calculate_is_render(processed_image):
109
  render_probs = render_logits.softmax(dim=1)
110
  render_probabilities_list = render_probs.squeeze().tolist()
111
  render_score = {class_name: probability for class_name, probability in zip(render_classes, render_probabilities_list)}
112
- is_render_prob = render_score['is_unrealistic_image_render']
113
  return is_render_prob
114
 
115
  def generate_answer(image):
@@ -124,12 +139,12 @@ def generate_answer(image):
124
  }
125
 
126
  space_type_score = calculate_space_type(processed_image)
127
- max_space_type = max(space_type_score, key=space_type_score.get)
128
- if space_type_score[max_space_type] >= threshold:
129
- space_type = max_space_type.lower()
130
- if space_type == "patio":
131
- space_type = "terrace"
132
- image_data["image_context"] = space_type
133
 
134
  image_results = {}
135
  if image_data["image_context"] == "terrace":
 
8
  vqa_pipeline = pipeline("visual-question-answering")
9
 
10
  space_type_labels = ["living room", "bedroom", "kitchen", "terrace", "closet","bathroom", "dining room", "office", "garage", "garden",
11
+ "balcony", "attic", "hallway", "laundry room","gym", "playroom", "storage room", "studio","is_exterior","empty_interior_room","others"]
12
 
13
  equipment_questions = [
14
  "Does the image show outdoor furniture?",
 
41
  }
42
 
43
  luminosity_classes = [
44
+ 'A well-lit room with abundant natural light, showcasing windows or a balcony through which sunlight passes unobstructed.',
45
+ 'A room depicted in darkness, where there is minimal or no visible light source.',
46
+ 'A room illuminated by artificial light sources such as lamps or ceiling lights.'
47
  ]
48
+
49
  luminosity_labels = ['natural_light', 'no_light', 'artificial_light']
50
 
51
  view_questions = [
 
53
  "Is this a city view?",
54
  "Is this a view of greenery?",
55
  "Is this a mountain view?",
56
+ "Is this a view of the sea?",
57
+ "Is this an exterior view of a building?"
58
+ ]
59
+ view_labels = ['panoramic', 'city', 'greenery', 'mountain', 'sea','indoor view','building view']
60
+
61
+ certainty_classes = [
62
+ 'Windows, balconies, or terraces with an unobstructed outward view',
63
+ 'exterior view of a building or appearance of a house or apartment',
64
+ 'Artificial or fake view of any city or sea',
65
+ 'View obstructed by objects such as buildings, trees, or other structures',
66
+ 'Hallway or interior view with no outdoor visibility'
67
  ]
 
68
 
69
+ #certainty_classes = ['Windows, balconies, or terraces with an unobstructed outward view','Exterior view appearance of a house or apartment','unreal picture or fake of any city or sea view','view unfree from any obstructive objects such as buildings, trees, or other structures, and ideally seen through windows, balconies, or terraces','hallway']
70
 
71
+ render_classes = [
72
+ "This is a realistic photo of an interior.",
73
+ "This is a computer-generated render of an interior.",
74
+ "This is a realistic photo of an exterior.",
75
+ "This is a computer-generated render of an exterior."
76
+ ]
77
 
78
  threshold = 0
79
 
 
124
  render_probs = render_logits.softmax(dim=1)
125
  render_probabilities_list = render_probs.squeeze().tolist()
126
  render_score = {class_name: probability for class_name, probability in zip(render_classes, render_probabilities_list)}
127
+ is_render_prob = render_score["This is a realistic photo of an interior."]+render_score["This is a realistic photo of an exterior."]
128
  return is_render_prob
129
 
130
  def generate_answer(image):
 
139
  }
140
 
141
  space_type_score = calculate_space_type(processed_image)
142
+ #max_space_type = max(space_type_score, key=space_type_score.get)
143
+ #if space_type_score[max_space_type] >= threshold:
144
+ # space_type = max_space_type.lower()
145
+ # if space_type == "patio":
146
+ # space_type = "terrace"
147
+ image_data["image_context"] = space_type_score
148
 
149
  image_results = {}
150
  if image_data["image_context"] == "terrace":