Spaces:
Sleeping
Sleeping
function
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ processor = CLIPProcessor.from_pretrained("tokenizer")
|
|
9 |
vqa_pipeline = pipeline("visual-question-answering",model="vqa")
|
10 |
|
11 |
space_type_labels = ["living room", "bedroom", "kitchen", "terrace", "closet","bathroom", "dining room", "office", "garage", "garden",
|
12 |
-
"balcony", "attic", "hallway",
|
13 |
|
14 |
equipment_questions = [
|
15 |
"Does the image show outdoor furniture?",
|
@@ -41,30 +41,45 @@ weights = {
|
|
41 |
"Does the image show protective materials?": 0.05
|
42 |
}
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
luminosity_classes = [
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
]
|
49 |
|
50 |
luminosity_labels = ['natural_light', 'no_light', 'artificial_light']
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
view_questions = [
|
53 |
-
"
|
54 |
-
"
|
55 |
-
"
|
56 |
-
"
|
57 |
-
"
|
58 |
-
"Is this an exterior view of a building?"
|
59 |
]
|
|
|
60 |
view_labels = ['panoramic', 'city', 'greenery', 'mountain', 'sea','indoor view','building view']
|
61 |
|
62 |
certainty_classes = [
|
63 |
-
'Windows, balconies, or terraces with an unobstructed outward view',
|
64 |
-
'exterior view of a building or appearance of a house or apartment',
|
65 |
-
'Artificial or fake view of any city or sea',
|
66 |
-
'View obstructed by objects such as buildings, trees, or other structures',
|
67 |
-
'Hallway or interior view with no outdoor visibility'
|
68 |
]
|
69 |
|
70 |
#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']
|
@@ -136,36 +151,45 @@ def generate_answer(image):
|
|
136 |
image_data = {
|
137 |
"image_context": None,
|
138 |
"equipment_score": None,
|
139 |
-
"luminosity_score": None,
|
|
|
|
|
|
|
|
|
140 |
"view_type": {"views": None, "certainty_score": None}
|
141 |
}
|
142 |
|
|
|
143 |
space_type_score = calculate_space_type(processed_image)
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
# space_type = "terrace"
|
149 |
image_data["image_context"] = space_type_score
|
150 |
|
151 |
image_results = {}
|
152 |
-
if
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
|
|
|
|
|
|
|
|
|
|
169 |
|
170 |
is_render = calculate_is_render(processed_image)
|
171 |
image_data["is_render"] = is_render
|
|
|
9 |
vqa_pipeline = pipeline("visual-question-answering",model="vqa")
|
10 |
|
11 |
space_type_labels = ["living room", "bedroom", "kitchen", "terrace", "closet","bathroom", "dining room", "office", "garage", "garden",
|
12 |
+
"balcony", "attic", "hallway","gym", "playroom", "storage room", "studio","is_exterior","swimming pool","others"]
|
13 |
|
14 |
equipment_questions = [
|
15 |
"Does the image show outdoor furniture?",
|
|
|
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 = [
|
59 |
+
# "Is this a panoramic view?",
|
60 |
+
# "Is this a city view?",
|
61 |
+
# "Is this a view of greenery?",
|
62 |
+
# "Is this a mountain view?",
|
63 |
+
# "Is this a view of the sea?",
|
64 |
+
# "Is this an exterior view of a building?"
|
65 |
+
#]
|
66 |
+
|
67 |
view_questions = [
|
68 |
+
"This is a panoramic view, showing a wide expanse of the surroundings.",
|
69 |
+
"This is a city view, showing buildings, streets, and urban areas.",
|
70 |
+
"This is a view of greenery, including trees, parks, or gardens.",
|
71 |
+
"This is a mountain view, showing mountains and hilly landscapes.",
|
72 |
+
"This is a view of the sea, including oceans, beaches, or large bodies of water."
|
|
|
73 |
]
|
74 |
+
|
75 |
view_labels = ['panoramic', 'city', 'greenery', 'mountain', 'sea','indoor view','building view']
|
76 |
|
77 |
certainty_classes = [
|
78 |
+
'Windows, balconies, or terraces with an unobstructed outward view',
|
79 |
+
'exterior view of a building or appearance of a house or apartment',
|
80 |
+
'Artificial or fake view of any city or sea',
|
81 |
+
'View obstructed by objects such as buildings, trees, or other structures',
|
82 |
+
'Hallway or interior view with no outdoor visibility'
|
83 |
]
|
84 |
|
85 |
#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']
|
|
|
151 |
image_data = {
|
152 |
"image_context": None,
|
153 |
"equipment_score": None,
|
154 |
+
"luminosity_score": {"score": None,
|
155 |
+
"has_window": {
|
156 |
+
"score": None,
|
157 |
+
"answer": None
|
158 |
+
}},
|
159 |
"view_type": {"views": None, "certainty_score": None}
|
160 |
}
|
161 |
|
162 |
+
max_space_type = max(space_type_score, key=space_type_score.get)
|
163 |
space_type_score = calculate_space_type(processed_image)
|
164 |
+
if space_type_score[max_space_type] >= threshold:
|
165 |
+
space_type = max_space_type.lower()
|
166 |
+
if space_type == "patio":
|
167 |
+
space_type = "terrace"
|
|
|
168 |
image_data["image_context"] = space_type_score
|
169 |
|
170 |
image_results = {}
|
171 |
+
if max_space_type == "terrace":
|
172 |
+
for question in equipment_questions:
|
173 |
+
result = vqa_pipeline(processed_image, question, top_k=1)
|
174 |
+
answer = result[0]['answer'].lower() == "yes"
|
175 |
+
image_results[question] = answer
|
176 |
+
equipment_score = calculate_equipment_score(image_results, weights)
|
177 |
+
image_data["equipment_score"] = equipment_score
|
178 |
+
|
179 |
+
if max_space_type in ["bedroom", "living room", "kitchen"]:
|
180 |
+
luminosity_score = calculate_luminosity_score(processed_image)
|
181 |
+
image_data["luminosity_score"]['score'] = luminosity_score['natural_light']
|
182 |
+
|
183 |
+
result = vqa_pipeline(processed_image, "Is there a real window?", top_k=1)
|
184 |
+
has_window = result[0]
|
185 |
+
image_data["luminosity_score"]["has_window"] = has_window
|
186 |
+
|
187 |
+
view = views(processed_image)
|
188 |
+
image_data["view_type"]["views"] = view
|
189 |
+
|
190 |
+
certainty_score = certainty(processed_image)
|
191 |
+
certainty_score = list(certainty_score.values())[0]
|
192 |
+
image_data["view_type"]["certainty_score"] = certainty_score
|
193 |
|
194 |
is_render = calculate_is_render(processed_image)
|
195 |
image_data["is_render"] = is_render
|