Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,42 @@
|
|
| 1 |
-
import
|
| 2 |
-
|
| 3 |
-
from PIL import Image
|
| 4 |
-
import torch
|
| 5 |
import cv2
|
| 6 |
import numpy as np
|
| 7 |
-
import
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
model
|
| 15 |
-
|
| 16 |
-
def
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import yolov5
|
|
|
|
|
|
|
| 3 |
import cv2
|
| 4 |
import numpy as np
|
| 5 |
+
from PIL import Image
|
| 6 |
+
|
| 7 |
+
@st.cache_resource(show_spinner=False)
|
| 8 |
+
def load_model():
|
| 9 |
+
model = yolov5.load('keremberke/yolov5n-license-plate')
|
| 10 |
+
model.conf = 0.25
|
| 11 |
+
model.iou = 0.45
|
| 12 |
+
return model
|
| 13 |
+
|
| 14 |
+
def main():
|
| 15 |
+
st.title("Detección de placas con YOLOv5")
|
| 16 |
+
st.write("Sube una imagen para detectar placas.")
|
| 17 |
+
|
| 18 |
+
uploaded_file = st.file_uploader("Selecciona una imagen", type=["jpg", "jpeg", "png"])
|
| 19 |
+
|
| 20 |
+
model = load_model()
|
| 21 |
+
|
| 22 |
+
if uploaded_file is not None:
|
| 23 |
+
image = Image.open(uploaded_file).convert("RGB")
|
| 24 |
+
img_array = np.array(image)
|
| 25 |
+
|
| 26 |
+
# Inferencia
|
| 27 |
+
results = model(img_array, size=640)
|
| 28 |
+
|
| 29 |
+
# Mostrar resultados
|
| 30 |
+
results.render() # dibuja cajas en img_array
|
| 31 |
+
st.image(img_array, caption="Resultado de detección", use_column_width=True)
|
| 32 |
+
|
| 33 |
+
# Mostrar texto detectado (categorías y scores)
|
| 34 |
+
detections = results.pred[0]
|
| 35 |
+
if len(detections) == 0:
|
| 36 |
+
st.write("No se detectaron placas.")
|
| 37 |
+
else:
|
| 38 |
+
for *box, conf, cls in detections.cpu().numpy():
|
| 39 |
+
st.write(f"Placa detectada con confianza {conf:.2f}")
|
| 40 |
+
|
| 41 |
+
if __name__ == "__main__":
|
| 42 |
+
main()
|