Rekham1110 commited on
Commit
8636fe5
·
verified ·
1 Parent(s): 7710a5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -33
app.py CHANGED
@@ -7,7 +7,7 @@ from datetime import datetime
7
  import shutil
8
  import base64
9
  import pytz
10
- import hashlib # Added missing import
11
 
12
  # Load environment variables
13
  load_dotenv()
@@ -43,20 +43,22 @@ def analyze_image_with_hf(image_path):
43
  img = Image.open(image_path)
44
  detected_elements = []
45
 
46
- # Mock detection based on image content (simplified)
 
47
  img_data = img.tobytes()
48
- img_hash = int(hashlib.sha256(img_data).hexdigest(), 16) # Now works with hashlib imported
49
- if any(keyword in os.path.basename(image_path).lower() for keyword in ["interior", "inside"]):
50
- if any(keyword in os.path.basename(image_path).lower() for keyword in ["electrical", "wiring", "plumbing", "pipes"]):
51
- detected_elements.extend(["electrical_wiring", "plumbing_pipes"])
52
- if any(keyword in os.path.basename(image_path).lower() for keyword in ["flooring", "painting", "fixtures"]):
53
- detected_elements.extend(["flooring", "painting", "fixtures"])
54
- elif "foundation" in os.path.basename(image_path).lower():
55
  detected_elements.append("foundation")
56
- elif any(keyword in os.path.basename(image_path).lower() for keyword in ["wall", "column", "beam"]):
57
- detected_elements.extend(["columns", "beams", "walls"])
58
- elif any(keyword in os.path.basename(image_path).lower() for keyword in ["roof", "window", "door", "cladding"]):
59
- detected_elements.extend(["roof", "windows", "doors", "cladding"])
 
 
60
 
61
  return detected_elements
62
 
@@ -155,35 +157,35 @@ def process_image(images, project_name):
155
  ]
156
  }
157
 
158
- # Map detected elements to tasks
159
- if any(elem in ["columns", "beams", "walls"] for elem in detected_elements_all):
160
- completed_tasks.extend(all_tasks["Walls Erected"])
161
- if any(elem in ["foundation"] for elem in detected_elements_all):
 
 
162
  completed_tasks.extend(all_tasks["Foundation"])
163
- if all(elem in ["roof", "windows", "doors", "cladding"] for elem in ["roof", "windows", "doors", "cladding"] if elem in detected_elements_all):
164
- completed_tasks.extend(all_tasks["Completed"])
165
- if all(elem in ["electrical_wiring", "plumbing_pipes", "flooring", "painting", "fixtures"] for elem in ["electrical_wiring", "plumbing_pipes", "flooring", "painting", "fixtures"] if elem in detected_elements_all):
166
- completed_tasks.extend(all_tasks["Interior Furnishing"])
167
-
168
- # Add remaining tasks as not completed
169
- all_possible_tasks = [task for sublist in all_tasks.values() for task in sublist]
170
- not_completed_tasks = [task for task in all_possible_tasks if task not in completed_tasks]
171
-
172
- # Determine milestone based on detected progress
173
- final_milestone = "Planning"
174
- percent_complete = 10
175
- if any(elem in ["foundation"] for elem in detected_elements_all):
176
  final_milestone = "Foundation"
177
  percent_complete = 30
178
- if any(elem in ["columns", "beams", "walls"] for elem in detected_elements_all):
 
179
  final_milestone = "Walls Erected"
180
  percent_complete = 50
181
- if all(elem in ["electrical_wiring", "plumbing_pipes"] for elem in ["electrical_wiring", "plumbing_pipes"] if elem in detected_elements_all):
 
182
  final_milestone = "Interior Furnishing"
183
  percent_complete = 80
184
- if all(elem in ["roof", "windows", "doors", "cladding", "electrical_wiring", "plumbing_pipes", "flooring", "painting", "fixtures"] for elem in ["roof", "windows", "doors", "cladding", "electrical_wiring", "plumbing_pipes", "flooring", "painting", "fixtures"] if elem in detected_elements_all):
 
185
  final_milestone = "Completed"
186
  percent_complete = 100
 
 
 
 
 
 
 
 
187
 
188
  completed_html = "".join([f'<li style="color: green;">✔ {task}</li>' for task in completed_tasks])
189
  not_completed_html = "".join([f'<li style="color: red;">✘ {task}</li>' for task in not_completed_tasks])
 
7
  import shutil
8
  import base64
9
  import pytz
10
+ import hashlib
11
 
12
  # Load environment variables
13
  load_dotenv()
 
43
  img = Image.open(image_path)
44
  detected_elements = []
45
 
46
+ # Enhanced mock detection based on filename keywords and simple content inference
47
+ filename = os.path.basename(image_path).lower()
48
  img_data = img.tobytes()
49
+ img_hash = int(hashlib.sha256(img_data).hexdigest(), 16)
50
+
51
+ # Heuristic detection based on filename or content
52
+ if any(keyword in filename for keyword in ["plan", "design", "blueprint"]):
53
+ detected_elements.append("planning")
54
+ elif any(keyword in filename for keyword in ["foundation", "excavation", "slab"]):
 
55
  detected_elements.append("foundation")
56
+ elif any(keyword in filename for keyword in ["wall", "column", "beam", "structure"]):
57
+ detected_elements.append("walls")
58
+ elif any(keyword in filename for keyword in ["interior", "electrical", "plumbing", "flooring"]):
59
+ detected_elements.extend(["interior", "electrical_wiring", "plumbing_pipes", "flooring"])
60
+ elif any(keyword in filename for keyword in ["roof", "window", "door", "cladding", "finished"]):
61
+ detected_elements.extend(["roof", "windows", "doors", "cladding", "finished"])
62
 
63
  return detected_elements
64
 
 
157
  ]
158
  }
159
 
160
+ # Map detected elements to tasks and determine milestone
161
+ if any(elem == "planning" for elem in detected_elements_all):
162
+ completed_tasks.extend(all_tasks["Planning"])
163
+ final_milestone = "Planning"
164
+ percent_complete = 10
165
+ elif any(elem == "foundation" for elem in detected_elements_all):
166
  completed_tasks.extend(all_tasks["Foundation"])
 
 
 
 
 
 
 
 
 
 
 
 
 
167
  final_milestone = "Foundation"
168
  percent_complete = 30
169
+ elif any(elem == "walls" for elem in detected_elements_all):
170
+ completed_tasks.extend(all_tasks["Walls Erected"])
171
  final_milestone = "Walls Erected"
172
  percent_complete = 50
173
+ elif all(elem in ["interior", "electrical_wiring", "plumbing_pipes", "flooring"] for elem in detected_elements_all if elem in ["interior", "electrical_wiring", "plumbing_pipes", "flooring"]):
174
+ completed_tasks.extend(all_tasks["Interior Furnishing"])
175
  final_milestone = "Interior Furnishing"
176
  percent_complete = 80
177
+ elif all(elem in ["roof", "windows", "doors", "cladding", "finished"] for elem in detected_elements_all if elem in ["roof", "windows", "doors", "cladding", "finished"]):
178
+ completed_tasks.extend(all_tasks["Completed"])
179
  final_milestone = "Completed"
180
  percent_complete = 100
181
+ else:
182
+ completed_tasks.extend(all_tasks["Planning"]) # Default to Planning if no specific stage detected
183
+ final_milestone = "Planning"
184
+ percent_complete = 10
185
+
186
+ # Add remaining tasks as not completed
187
+ all_possible_tasks = [task for sublist in all_tasks.values() for task in sublist]
188
+ not_completed_tasks = [task for task in all_possible_tasks if task not in completed_tasks]
189
 
190
  completed_html = "".join([f'<li style="color: green;">✔ {task}</li>' for task in completed_tasks])
191
  not_completed_html = "".join([f'<li style="color: red;">✘ {task}</li>' for task in not_completed_tasks])