Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,13 +4,25 @@ from transformers import DetrImageProcessor, DetrForObjectDetection, TrOCRProces
|
|
| 4 |
from PIL import Image
|
| 5 |
from datetime import datetime
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
# Load the DETR model for object detection (license plate detection)
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# Load the TrOCR model for OCR (license plate text recognition)
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
def detect_license_plate(frame):
|
| 16 |
# Convert the frame to a PIL image
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
from datetime import datetime
|
| 6 |
|
| 7 |
+
# Ensure all required libraries are installed
|
| 8 |
+
try:
|
| 9 |
+
import timm # Required by DETR
|
| 10 |
+
except ImportError:
|
| 11 |
+
raise ImportError("The 'timm' library is required but not installed. Install it using 'pip install timm'.")
|
| 12 |
+
|
| 13 |
# Load the DETR model for object detection (license plate detection)
|
| 14 |
+
try:
|
| 15 |
+
detr_processor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-50")
|
| 16 |
+
detr_model = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-50")
|
| 17 |
+
except Exception as e:
|
| 18 |
+
raise RuntimeError(f"Error initializing DETR model: {e}")
|
| 19 |
|
| 20 |
# Load the TrOCR model for OCR (license plate text recognition)
|
| 21 |
+
try:
|
| 22 |
+
trocr_processor = TrOCRProcessor.from_pretrained("microsoft/trocr-base-handwritten")
|
| 23 |
+
trocr_model = VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-base-handwritten")
|
| 24 |
+
except Exception as e:
|
| 25 |
+
raise RuntimeError(f"Error initializing TrOCR model: {e}")
|
| 26 |
|
| 27 |
def detect_license_plate(frame):
|
| 28 |
# Convert the frame to a PIL image
|