Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,6 +19,9 @@ import io
|
|
| 19 |
detector = RoadsideDetector()
|
| 20 |
|
| 21 |
|
|
|
|
|
|
|
|
|
|
| 22 |
from utils import (
|
| 23 |
extract_gps_from_image,
|
| 24 |
save_detection_to_history,
|
|
@@ -26,28 +29,29 @@ from utils import (
|
|
| 26 |
create_detection_map,
|
| 27 |
generate_statistics,
|
| 28 |
format_statistics_text,
|
| 29 |
-
get_debug_messages,
|
|
|
|
| 30 |
)
|
| 31 |
|
| 32 |
-
|
| 33 |
|
| 34 |
-
def process_image(image_path, use_gps=True):
|
| 35 |
if not image_path:
|
| 36 |
return None, "โ Please upload an image!", None, "๐ No statistics yet", ""
|
| 37 |
|
| 38 |
-
# Load image for YOLO
|
| 39 |
image = Image.open(image_path)
|
| 40 |
|
| 41 |
-
#
|
| 42 |
detections = detector.detect_items(image)
|
| 43 |
annotated = detector.draw_boxes(image, detections)
|
| 44 |
severity = detector.calculate_severity(detections)
|
| 45 |
|
| 46 |
-
# GPS extraction
|
| 47 |
gps_data = {"coords": None, "address": None}
|
| 48 |
if use_gps:
|
| 49 |
try:
|
| 50 |
-
gps_data = extract_gps_from_image(image_path) # โ
pass
|
| 51 |
except Exception as e:
|
| 52 |
add_debug(f"โ GPS extraction failed: {e}")
|
| 53 |
|
|
@@ -60,14 +64,21 @@ def process_image(image_path, use_gps=True): # Now we get a filepath, not a PIL
|
|
| 60 |
}
|
| 61 |
save_detection_to_history(detection_entry)
|
| 62 |
|
| 63 |
-
#
|
| 64 |
history = load_detection_history()
|
| 65 |
map_html = create_detection_map(history)
|
| 66 |
stats = generate_statistics()
|
| 67 |
stats_text = format_statistics_text(stats)
|
| 68 |
debug_log = get_debug_messages()
|
| 69 |
|
| 70 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
|
| 73 |
|
|
|
|
| 19 |
detector = RoadsideDetector()
|
| 20 |
|
| 21 |
|
| 22 |
+
from PIL import Image
|
| 23 |
+
from datetime import datetime
|
| 24 |
+
from detector import RoadsideDetector
|
| 25 |
from utils import (
|
| 26 |
extract_gps_from_image,
|
| 27 |
save_detection_to_history,
|
|
|
|
| 29 |
create_detection_map,
|
| 30 |
generate_statistics,
|
| 31 |
format_statistics_text,
|
| 32 |
+
get_debug_messages,
|
| 33 |
+
add_debug, # โ
include this
|
| 34 |
)
|
| 35 |
|
| 36 |
+
detector = RoadsideDetector()
|
| 37 |
|
| 38 |
+
def process_image(image_path, use_gps=True):
|
| 39 |
if not image_path:
|
| 40 |
return None, "โ Please upload an image!", None, "๐ No statistics yet", ""
|
| 41 |
|
| 42 |
+
# Load image for YOLO
|
| 43 |
image = Image.open(image_path)
|
| 44 |
|
| 45 |
+
# YOLO detection
|
| 46 |
detections = detector.detect_items(image)
|
| 47 |
annotated = detector.draw_boxes(image, detections)
|
| 48 |
severity = detector.calculate_severity(detections)
|
| 49 |
|
| 50 |
+
# GPS extraction
|
| 51 |
gps_data = {"coords": None, "address": None}
|
| 52 |
if use_gps:
|
| 53 |
try:
|
| 54 |
+
gps_data = extract_gps_from_image(image_path) # โ
pass path
|
| 55 |
except Exception as e:
|
| 56 |
add_debug(f"โ GPS extraction failed: {e}")
|
| 57 |
|
|
|
|
| 64 |
}
|
| 65 |
save_detection_to_history(detection_entry)
|
| 66 |
|
| 67 |
+
# Map + stats
|
| 68 |
history = load_detection_history()
|
| 69 |
map_html = create_detection_map(history)
|
| 70 |
stats = generate_statistics()
|
| 71 |
stats_text = format_statistics_text(stats)
|
| 72 |
debug_log = get_debug_messages()
|
| 73 |
|
| 74 |
+
return (
|
| 75 |
+
annotated,
|
| 76 |
+
f"๐ Severity: {severity}\n๐ฆ Items: {len(detections)}"
|
| 77 |
+
+ (f"\n๐ GPS: {gps_data['coords']}" if gps_data.get("coords") else "\n๐ No GPS/location data available"),
|
| 78 |
+
map_html,
|
| 79 |
+
stats_text,
|
| 80 |
+
debug_log
|
| 81 |
+
)
|
| 82 |
|
| 83 |
|
| 84 |
|