Myloiose commited on
Commit
52036a4
·
verified ·
1 Parent(s): 7d8f571

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -31
app.py CHANGED
@@ -1,44 +1,31 @@
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
12
 
13
- def main():
14
- st.title("🔍 Detector de Matrículas - YOLOv5")
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
- 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()
 
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()