Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,44 +1,31 @@
|
|
| 1 |
-
import
|
| 2 |
from PIL import Image
|
| 3 |
import numpy as np
|
| 4 |
import yolov5
|
| 5 |
|
| 6 |
-
@
|
| 7 |
def load_model():
|
| 8 |
model = yolov5.load('keremberke/yolov5n-license-plate')
|
| 9 |
model.conf = 0.25
|
| 10 |
model.iou = 0.45
|
| 11 |
return model
|
| 12 |
|
| 13 |
-
def
|
| 14 |
-
|
| 15 |
-
st.write("Sube una imagen para detectar matrículas.")
|
| 16 |
-
|
| 17 |
-
img_file = st.file_uploader("Selecciona una imagen", type=["jpg", "jpeg", "png"])
|
| 18 |
-
if img_file is None:
|
| 19 |
-
st.info("Por favor sube una imagen.")
|
| 20 |
-
return
|
| 21 |
-
|
| 22 |
-
image = Image.open(img_file).convert("RGB")
|
| 23 |
-
st.image(image, caption="Imagen original", use_column_width=True)
|
| 24 |
-
|
| 25 |
model = load_model()
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
st.success(f"Se detectaron {len(detections)} matrícula(s):")
|
| 40 |
-
for *box, conf, cls in detections.cpu().numpy():
|
| 41 |
-
st.write(f"📍 Confianza: {conf:.2f}")
|
| 42 |
|
| 43 |
if __name__ == "__main__":
|
| 44 |
-
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
import numpy as np
|
| 4 |
import yolov5
|
| 5 |
|
| 6 |
+
@gr.cache(allow_output_mutation=True)
|
| 7 |
def load_model():
|
| 8 |
model = yolov5.load('keremberke/yolov5n-license-plate')
|
| 9 |
model.conf = 0.25
|
| 10 |
model.iou = 0.45
|
| 11 |
return model
|
| 12 |
|
| 13 |
+
def detect(img: Image.Image):
|
| 14 |
+
img = img.convert("RGB")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
model = load_model()
|
| 16 |
+
arr = np.array(img)
|
| 17 |
+
results = model(arr, size=640)
|
| 18 |
+
results.render()
|
| 19 |
+
annotated = results.ims[0]
|
| 20 |
+
return Image.fromarray(annotated)
|
| 21 |
+
|
| 22 |
+
demo = gr.Interface(
|
| 23 |
+
fn=detect,
|
| 24 |
+
inputs=gr.Image(type="pil"),
|
| 25 |
+
outputs=gr.Image(type="pil"),
|
| 26 |
+
title="🔍 Detector de Matrículas",
|
| 27 |
+
description="Sube una imagen y detecto matrículas usando YOLOv5n."
|
| 28 |
+
)
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
if __name__ == "__main__":
|
| 31 |
+
demo.launch()
|