Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,9 +19,19 @@ import io
|
|
| 19 |
detector = RoadsideDetector()
|
| 20 |
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
def process_image(image, use_gps=True):
|
| 23 |
if image is None:
|
| 24 |
-
return None, "❌ Please upload an image!", None, "📊 No statistics yet"
|
| 25 |
|
| 26 |
# Run YOLO detection
|
| 27 |
detections = detector.detect_items(image)
|
|
@@ -32,14 +42,12 @@ def process_image(image, use_gps=True):
|
|
| 32 |
gps_data = {"coords": None, "address": None}
|
| 33 |
if use_gps:
|
| 34 |
try:
|
| 35 |
-
|
| 36 |
-
if hasattr(image, "name"):
|
| 37 |
gps_data = extract_gps_from_image(image.name)
|
| 38 |
-
else:
|
| 39 |
gps_data = extract_gps_from_image(image)
|
| 40 |
except Exception as e:
|
| 41 |
-
|
| 42 |
-
gps_data = {"coords": None, "address": None}
|
| 43 |
|
| 44 |
# ---------------- Save Detection ----------------
|
| 45 |
detection_data = {
|
|
@@ -53,7 +61,6 @@ def process_image(image, use_gps=True):
|
|
| 53 |
|
| 54 |
# ---------------- Summary ----------------
|
| 55 |
summary = f"🔍 Severity: {severity}\n📦 Items: {len(detections)}"
|
| 56 |
-
|
| 57 |
if gps_data["coords"]:
|
| 58 |
lat, lon = gps_data["coords"]
|
| 59 |
summary += f"\n📍 Location: {lat:.6f}, {lon:.6f}"
|
|
@@ -67,7 +74,11 @@ def process_image(image, use_gps=True):
|
|
| 67 |
map_html = create_detection_map(history)
|
| 68 |
stats = format_statistics_text(generate_statistics())
|
| 69 |
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
|
| 73 |
|
|
|
|
| 19 |
detector = RoadsideDetector()
|
| 20 |
|
| 21 |
|
| 22 |
+
from utils import (
|
| 23 |
+
extract_gps_from_image,
|
| 24 |
+
save_detection_to_history,
|
| 25 |
+
load_detection_history,
|
| 26 |
+
create_detection_map,
|
| 27 |
+
generate_statistics,
|
| 28 |
+
format_statistics_text,
|
| 29 |
+
get_debug_messages, # ✅ make sure this is imported
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
def process_image(image, use_gps=True):
|
| 33 |
if image is None:
|
| 34 |
+
return None, "❌ Please upload an image!", None, "📊 No statistics yet", ""
|
| 35 |
|
| 36 |
# Run YOLO detection
|
| 37 |
detections = detector.detect_items(image)
|
|
|
|
| 42 |
gps_data = {"coords": None, "address": None}
|
| 43 |
if use_gps:
|
| 44 |
try:
|
| 45 |
+
if hasattr(image, "name"): # file path
|
|
|
|
| 46 |
gps_data = extract_gps_from_image(image.name)
|
| 47 |
+
else: # fallback: pass the PIL image
|
| 48 |
gps_data = extract_gps_from_image(image)
|
| 49 |
except Exception as e:
|
| 50 |
+
add_debug(f"❌ GPS extraction failed: {e}")
|
|
|
|
| 51 |
|
| 52 |
# ---------------- Save Detection ----------------
|
| 53 |
detection_data = {
|
|
|
|
| 61 |
|
| 62 |
# ---------------- Summary ----------------
|
| 63 |
summary = f"🔍 Severity: {severity}\n📦 Items: {len(detections)}"
|
|
|
|
| 64 |
if gps_data["coords"]:
|
| 65 |
lat, lon = gps_data["coords"]
|
| 66 |
summary += f"\n📍 Location: {lat:.6f}, {lon:.6f}"
|
|
|
|
| 74 |
map_html = create_detection_map(history)
|
| 75 |
stats = format_statistics_text(generate_statistics())
|
| 76 |
|
| 77 |
+
# ---------------- Debug Logs ----------------
|
| 78 |
+
debug_output = get_debug_messages()
|
| 79 |
+
|
| 80 |
+
return annotated, summary, map_html, stats, debug_output # ✅ now returns 5 values
|
| 81 |
+
|
| 82 |
|
| 83 |
|
| 84 |
|