Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,11 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from PIL import Image
|
| 3 |
-
import torch
|
| 4 |
-
import cv2
|
| 5 |
import numpy as np
|
|
|
|
| 6 |
|
| 7 |
@st.cache_resource(show_spinner=False)
|
| 8 |
def load_model():
|
| 9 |
-
model =
|
| 10 |
model.conf = 0.25
|
| 11 |
model.iou = 0.45
|
| 12 |
return model
|
|
@@ -20,23 +19,26 @@ def main():
|
|
| 20 |
st.info("Por favor sube una imagen.")
|
| 21 |
return
|
| 22 |
|
| 23 |
-
model = load_model()
|
| 24 |
image = Image.open(img_file).convert("RGB")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
img = np.array(image)
|
| 26 |
|
| 27 |
results = model(img, size=640)
|
| 28 |
-
results.render()
|
| 29 |
|
| 30 |
-
|
| 31 |
-
st.image(
|
| 32 |
|
|
|
|
| 33 |
detections = results.pred[0]
|
| 34 |
if detections is None or len(detections) == 0:
|
| 35 |
-
st.warning("No se detectaron
|
| 36 |
else:
|
| 37 |
-
st.success(f"Se detectaron {len(detections)}
|
| 38 |
for *box, conf, cls in detections.cpu().numpy():
|
| 39 |
-
st.write(f"
|
| 40 |
|
| 41 |
if __name__ == "__main__":
|
| 42 |
main()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from PIL import Image
|
|
|
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
+
import yolov5
|
| 5 |
|
| 6 |
@st.cache_resource(show_spinner=False)
|
| 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
|
|
|
|
| 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 |
img = np.array(image)
|
| 28 |
|
| 29 |
results = model(img, size=640)
|
|
|
|
| 30 |
|
| 31 |
+
results.render()
|
| 32 |
+
st.image(results.ims[0], caption="Resultado con detecciones", use_column_width=True)
|
| 33 |
|
| 34 |
+
|
| 35 |
detections = results.pred[0]
|
| 36 |
if detections is None or len(detections) == 0:
|
| 37 |
+
st.warning("No se detectaron matrículas.")
|
| 38 |
else:
|
| 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 |
main()
|