import cv2 import gradio as gr import os import datetime import pandas as pd from PIL import Image from pathlib import Path import torch # πŸ”§ Setup os.makedirs("logs", exist_ok=True) # 🧠 Load YOLOv5 Model model = torch.hub.load('ultralytics/yolov5', 'yolov5s', trust_repo=True) # πŸ“ Fake GPS Location def get_fake_gps_location(): return "28.6139Β° N, 77.2090Β° E" # Delhi (demo) # πŸ”Š Simulated Voice Alert (just returns text) def voice_alert(text): print(f"[VOICE ALERT] {text}") return f"πŸ”Š Voice: {text}" # 🎯 Detection Function def detect_luggage(image_path, status_label): image = Image.open(image_path) results = model(image) annotated_image = results.render()[0] annotated_pil = Image.fromarray(annotated_image) # πŸ—ΊοΈ Fake GPS gps = get_fake_gps_location() # πŸ”Š Voice Message alert_text = f"Luggage {status_label} at {gps}" voice = voice_alert(alert_text) # πŸ“ Logging time_now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") log_path = "luggage_log.csv" entry = {"timestamp": time_now, "status": status_label, "gps": gps} df = pd.DataFrame([entry]) if not os.path.exists(log_path): df.to_csv(log_path, index=False) else: df.to_csv(log_path, mode='a', header=False, index=False) # πŸ’Ύ Save Image img_name = f"{status_label}_{datetime.datetime.now().strftime('%Y%m%d_%H%M%S')}.jpg" annotated_pil.save(f"logs/{img_name}") return annotated_pil, f"{voice} | πŸ“ Location: {gps}" # πŸ€– Demo Function def run_demo(status_label): test_image_path = "assets/test_luggage.jpg" return detect_luggage(test_image_path, status_label) # 🎨 Gradio UI demo = gr.Interface( fn=run_demo, inputs=gr.Radio(["Loaded", "Dispatched"], label="Select Luggage Status", value="Loaded"), outputs=[ gr.Image(label="Detected Luggage"), gr.Text(label="Detection Report") ], title="πŸŽ’ Luggage Tracking with Voice + GPS", description="YOLO-based luggage detection with simulated GPS & voice alerts. Ready for Hugging Face!" ) if __name__ == "__main__": demo.launch()