🅿️ Smart Parking Management System
Powered by AI Vision Transformers • Real-time Detection
# Smart Parking System - Gradio UI for Hugging Face Spaces import torch import numpy as np from PIL import Image import matplotlib.pyplot as plt import matplotlib.patches as patches from datetime import datetime, timedelta import cv2 from transformers import AutoProcessor, AutoModelForCausalLM import gradio as gr import warnings warnings.filterwarnings('ignore') class StateOfTheArtParkingDetector: def __init__(self, total_spaces=50): self.total_spaces = total_spaces self.device = "cuda" if torch.cuda.is_available() else "cpu" print(f"🚀 Loading State-of-the-Art Models... Device: {self.device}") # Load Florence-2 try: self.processor = AutoProcessor.from_pretrained( "microsoft/Florence-2-large", trust_remote_code=True ) self.model = AutoModelForCausalLM.from_pretrained( "microsoft/Florence-2-large", torch_dtype=torch.float16 if self.device=="cuda" else torch.float32, trust_remote_code=True ).to(self.device) self.florence_available = True except: try: self.processor = AutoProcessor.from_pretrained( "microsoft/Florence-2-base", trust_remote_code=True ) self.model = AutoModelForCausalLM.from_pretrained( "microsoft/Florence-2-base", torch_dtype=torch.float16 if self.device=="cuda" else torch.float32, trust_remote_code=True ).to(self.device) self.florence_available = True except: self.florence_available = False # Load YOLO-World try: from ultralytics import YOLO self.yolo_world = YOLO('yolov8x-worldv2.pt') self.yolo_world_available = True except: self.yolo_world_available = False # Detection methods remain the same as your original code # detect_with_florence, detect_with_yolo_world, advanced_cv_detection, # merge_all_detections, calculate_iou, create_annotated_image, process_image # Initialize detector detector = StateOfTheArtParkingDetector() # Gradio Interface with gr.Blocks( theme=gr.themes.Soft(primary_hue="purple", secondary_hue="blue"), css=""" .gradio-container { font-family: 'Segoe UI', Arial, sans-serif; } .main-header { text-align: center; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 30px; border-radius: 10px; margin-bottom: 20px; } """ ) as demo: gr.HTML("""
Powered by AI Vision Transformers • Real-time Detection