mustafa2ak commited on
Commit
55cf4c8
ยท
verified ยท
1 Parent(s): e9869ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -9
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, # โœ… make sure this is imported
 
30
  )
31
 
32
- from PIL import Image
33
 
34
- def process_image(image_path, use_gps=True): # Now we get a filepath, not a PIL image
35
  if not image_path:
36
  return None, "โŒ Please upload an image!", None, "๐Ÿ“Š No statistics yet", ""
37
 
38
- # Load image for YOLO detection
39
  image = Image.open(image_path)
40
 
41
- # Run YOLO detection
42
  detections = detector.detect_items(image)
43
  annotated = detector.draw_boxes(image, detections)
44
  severity = detector.calculate_severity(detections)
45
 
46
- # GPS extraction from original file
47
  gps_data = {"coords": None, "address": None}
48
  if use_gps:
49
  try:
50
- gps_data = extract_gps_from_image(image_path) # โœ… pass file path
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
- # Build map + stats
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 annotated, f"๐Ÿ” Severity: {severity}\n๐Ÿ“ฆ Items: {len(detections)}", map_html, stats_text, debug_log
 
 
 
 
 
 
 
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