Rekham1110 commited on
Commit
25656fd
·
verified ·
1 Parent(s): 8636fe5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -43,21 +43,22 @@ def analyze_image_with_hf(image_path):
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
@@ -170,7 +171,7 @@ def process_image(images, project_name):
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
 
43
  img = Image.open(image_path)
44
  detected_elements = []
45
 
46
+ # Enhanced mock detection based on image size and pixel data (simulating content analysis)
47
+ width, height = img.size
48
+ img_data = list(img.getdata())
49
+ gray_pixels = sum(1 for pixel in img_data if sum(pixel[:3]) / 3 < 128) / len(img_data) # Proportion of dark pixels
50
+ total_pixels = width * height
51
 
52
+ # Heuristic detection based on image characteristics
53
+ if total_pixels < 500000: # Small image size, assume early planning stage
54
  detected_elements.append("planning")
55
+ elif gray_pixels > 0.6 and width > 1000: # High proportion of dark pixels, assume concrete/foundation
56
  detected_elements.append("foundation")
57
+ elif gray_pixels > 0.4 and width > 1000 and height > 1000: # Larger structure with columns, assume walls erected
58
  detected_elements.append("walls")
59
+ elif any(keyword in os.path.basename(image_path).lower() for keyword in ["interior", "plumbing", "electrical", "ceiling"]) or (gray_pixels < 0.3 and total_pixels > 800000): # Interior work or bright finished interior
60
+ detected_elements.extend(["interior", "electrical_wiring", "plumbing_pipes"])
61
+ else: # Assume completed if no other clear indicators
62
  detected_elements.extend(["roof", "windows", "doors", "cladding", "finished"])
63
 
64
  return detected_elements
 
171
  completed_tasks.extend(all_tasks["Walls Erected"])
172
  final_milestone = "Walls Erected"
173
  percent_complete = 50
174
+ elif any(elem in ["interior", "electrical_wiring", "plumbing_pipes"] for elem in detected_elements_all):
175
  completed_tasks.extend(all_tasks["Interior Furnishing"])
176
  final_milestone = "Interior Furnishing"
177
  percent_complete = 80