Spaces:
Sleeping
Sleeping
File size: 2,964 Bytes
7d8ec5e 4bdf8dd 49702ec f469f03 c4e3ea5 3dfd15f f469f03 c4e3ea5 f469f03 49702ec 4e27730 f41a948 4e27730 c4fefad 74a72c4 f469f03 74a72c4 f469f03 ef4e447 f469f03 ef4e447 49702ec f469f03 f41a948 49702ec f41a948 4bdf8dd 49702ec 74a72c4 f41a948 49702ec f469f03 cc1155e c4e3ea5 4bdf8dd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
from PIL import Image
import gradio as gr
import torch
from datetime import datetime
from ultralytics import YOLO
torch.serialization.add_safe_globals([torch.nn.Module, 'ultralytics.nn.tasks.DetectionModel'])
# Load YOLOv8 model (trained on construction dataset)
model = YOLO('yolov8n.pt') # Path to pre-trained model on construction dataset
# Function to generate DPR text based on detections
def generate_dpr(files):
dpr_text = []
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# Add header to the DPR
dpr_text.append(f"Daily Progress Report\nGenerated on: {current_time}\n")
# Process each uploaded file (image)
for file in files:
# Open the image from file path
image = Image.open(file.name)
# Perform object detection with YOLOv8
results = model(image) # Perform detection
# Parse detections (activities, materials, etc.)
detected_objects = results.names # Object names detected by the model
detections = results.pandas().xywh # Get the dataframe with detection results
detected_activities = []
detected_materials = []
# Define construction activity and material categories
construction_activities = ['scaffolding', 'concrete pouring', 'welding', 'excavation']
construction_materials = ['concrete', 'steel', 'bricks', 'cement', 'sand']
# Check the detected objects and categorize them
for obj in detected_objects:
if obj.lower() in construction_activities:
detected_activities.append(obj)
elif obj.lower() in construction_materials:
detected_materials.append(obj)
# Build a detailed report for this image
dpr_section = f"\nImage: {file.name}\n"
if detected_activities:
dpr_section += f"Detected Activities: {', '.join(detected_activities)}\n"
else:
dpr_section += "No construction activities detected.\n"
if detected_materials:
dpr_section += f"Detected Materials: {', '.join(detected_materials)}\n"
else:
dpr_section += "No materials detected.\n"
dpr_text.append(dpr_section)
# Return the generated DPR as a text output
return "\n".join(dpr_text)
# Gradio interface for uploading multiple files and displaying the text-based DPR
iface = gr.Interface(
fn=generate_dpr,
inputs=gr.Files(type="filepath", label="Upload Site Photos"), # Handle batch upload of images
outputs="text", # Display the DPR as text in the output section
title="Daily Progress Report Generator",
description="Upload up to 10 site photos. The AI model will detect construction activities, materials, and progress and generate a text-based Daily Progress Report (DPR).",
allow_flagging="never" # Optional: Disable flagging
)
iface.launch()
|