Rammohan0504 commited on
Commit
cfcd8f7
·
verified ·
1 Parent(s): 064969a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -3
app.py CHANGED
@@ -37,12 +37,16 @@ def infer_activity_and_phrase(obj, box, img_height):
37
  Dynamically infer a construction activity and generate a descriptive phrase based on the detected object,
38
  using object name, bounding box size, and position.
39
  Args:
40
- obj (str): Detected COCO object (e.g., 'truck', 'crane').
41
  box (list): Bounding box [x1, y1, x2, y2, conf, cls].
42
  img_height (int): Image height for position analysis.
43
  Returns:
44
  tuple: (activity, phrase) or (None, None) if unmapped.
45
  """
 
 
 
 
46
  # Normalize object name
47
  obj_lower = obj.lower().replace('_', ' ')
48
 
@@ -50,6 +54,19 @@ def infer_activity_and_phrase(obj, box, img_height):
50
  if len(obj_lower) <= 4 or any(suffix in obj_lower for suffix in ['cat', 'dog', 'bird', 'fish']):
51
  return None, None
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  # Extract bounding box info
54
  x1, y1, x2, y2, conf = box[:5]
55
  box_area = (x2 - x1) * (y2 - y1) # Area of bounding box
@@ -63,7 +80,7 @@ def infer_activity_and_phrase(obj, box, img_height):
63
  base_name = obj_lower.title()
64
 
65
  # Synonym lists for activity variation (added more activities)
66
- action_terms = ['Operation', 'Handling', 'Setup', 'Installation', 'Preparation', 'Transport', 'Lifting', 'Surveying', 'Piling', 'Concrete Work', 'Flooring', 'Finishing']
67
  location_terms = ['site area', 'work zone', 'structural zone', 'foundation level', 'elevated area', 'safety zone', 'concrete pouring zone', 'flooring zone']
68
 
69
  # Categorize based on size and position
@@ -285,7 +302,7 @@ iface = gr.Interface(
285
  gr.File(label="Download PDF")
286
  ],
287
  title="Daily Progress Report Generator",
288
- description="Upload up to 10 site photos. The AI model dynamically detects objects using YOLOv8 and infers construction activities like concrete work, flooring, piling, and finishing based on object names, sizes, and positions. The DPR is saved as a PDF and uploaded to Salesforce.",
289
  allow_flagging="never"
290
  )
291
 
 
37
  Dynamically infer a construction activity and generate a descriptive phrase based on the detected object,
38
  using object name, bounding box size, and position.
39
  Args:
40
+ obj (str): Detected COCO object (e.g., 'truck', 'crane', 'person').
41
  box (list): Bounding box [x1, y1, x2, y2, conf, cls].
42
  img_height (int): Image height for position analysis.
43
  Returns:
44
  tuple: (activity, phrase) or (None, None) if unmapped.
45
  """
46
+ # If the object is a person, label it as a worker
47
+ if obj.lower() == 'person':
48
+ obj = 'worker' # Change label from person to worker
49
+
50
  # Normalize object name
51
  obj_lower = obj.lower().replace('_', ' ')
52
 
 
54
  if len(obj_lower) <= 4 or any(suffix in obj_lower for suffix in ['cat', 'dog', 'bird', 'fish']):
55
  return None, None
56
 
57
+ # Define common construction materials
58
+ materials = ['cement', 'concrete', 'bricks', 'iron', 'steel', 'sand', 'mortar', 'wood', 'plaster']
59
+
60
+ # If object is a material, adjust activity accordingly
61
+ if any(material in obj_lower for material in materials):
62
+ base_name = obj_lower.title()
63
+ activity = f"{base_name} pouring"
64
+ location = "work zone" # You can be more specific based on detection
65
+ verb = random.choice(["observed", "detected", "noted"])
66
+ level = "ground level" # Adjust the level based on detection position
67
+ phrase = f"{activity} {verb} at the {level}."
68
+ return activity, phrase
69
+
70
  # Extract bounding box info
71
  x1, y1, x2, y2, conf = box[:5]
72
  box_area = (x2 - x1) * (y2 - y1) # Area of bounding box
 
80
  base_name = obj_lower.title()
81
 
82
  # Synonym lists for activity variation (added more activities)
83
+ action_terms = ['Operation', 'Handling', 'Setup', 'Installation', 'Preparation', 'Transport', 'Lifting', 'Surveying', 'Piling', 'Concrete Work', 'Flooring', 'Finishing', 'Marking', 'Surveying']
84
  location_terms = ['site area', 'work zone', 'structural zone', 'foundation level', 'elevated area', 'safety zone', 'concrete pouring zone', 'flooring zone']
85
 
86
  # Categorize based on size and position
 
302
  gr.File(label="Download PDF")
303
  ],
304
  title="Daily Progress Report Generator",
305
+ description="Upload up to 10 site photos. The AI model dynamically detects objects using YOLOv8 and infers construction activities like concrete work, flooring, piling, finishing, and more based on object names, sizes, and positions. The DPR is saved as a PDF and uploaded to Salesforce.",
306
  allow_flagging="never"
307
  )
308