Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import yolov5
|
| 3 |
+
import torch
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
# Carga del modelo preentrenado
|
| 8 |
+
model = yolov5.load('keremberke/yolov5n-license-plate')
|
| 9 |
+
model.conf = 0.25
|
| 10 |
+
model.iou = 0.45
|
| 11 |
+
|
| 12 |
+
# Función de detección
|
| 13 |
+
def detect_license_plate(img):
|
| 14 |
+
results = model(img, size=640)
|
| 15 |
+
results.render()
|
| 16 |
+
# Convertir de array a imagen PIL
|
| 17 |
+
rendered_img = Image.fromarray(results.ims[0])
|
| 18 |
+
return rendered_img
|
| 19 |
+
|
| 20 |
+
# Interfaz
|
| 21 |
+
demo = gr.Interface(
|
| 22 |
+
fn=detect_license_plate,
|
| 23 |
+
inputs=gr.Image(type="pil"),
|
| 24 |
+
outputs=gr.Image(type="pil"),
|
| 25 |
+
title="Detector de Matrículas",
|
| 26 |
+
description="Sube una imagen de un vehículo para detectar la matrícula usando YOLOv5n"
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
demo.launch()
|