Damanger commited on
Commit
d0ee279
·
1 Parent(s): 65bad76

corrigiendo app

Browse files
Files changed (2) hide show
  1. app.py +16 -4
  2. models/best_placas.pt +3 -0
app.py CHANGED
@@ -9,11 +9,23 @@ from fastapi.middleware.cors import CORSMiddleware
9
  from pydantic import BaseModel, Field
10
  from huggingface_hub import hf_hub_download
11
 
 
 
12
  # --- Modelo YOLO desde el Hub (cachea en HF_HOME si lo configuras) ---
13
- WEIGHTS = hf_hub_download(
14
- repo_id="keremberke/yolov8n-license-plate",
15
- filename="yolov8n-license-plate.pt"
16
- ) # devuelve una ruta local. :contentReference[oaicite:2]{index=2}
 
 
 
 
 
 
 
 
 
 
17
  yolo = YOLO(WEIGHTS)
18
 
19
  # EasyOCR con GPU si está disponible
 
9
  from pydantic import BaseModel, Field
10
  from huggingface_hub import hf_hub_download
11
 
12
+ local_path = "/app/best.pt"
13
+
14
  # --- Modelo YOLO desde el Hub (cachea en HF_HOME si lo configuras) ---
15
+ try:
16
+ WEIGHTS = hf_hub_download(
17
+ repo_id="keremberke/yolov5n-license-plate",
18
+ filename="best.pt",
19
+ token=os.getenv("HF_TOKEN", None), # si no tienes token, no pasa nada
20
+ )
21
+ except Exception:
22
+ # Fallback simple por si hay un token inválido en el entorno
23
+ if not os.path.exists(local_path):
24
+ url = "https://huggingface.co/keremberke/yolov5n-license-plate/resolve/main/best.pt"
25
+ req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})
26
+ with urllib.request.urlopen(req) as r, open(local_path, "wb") as f:
27
+ f.write(r.read())
28
+ WEIGHTS = local_path
29
  yolo = YOLO(WEIGHTS)
30
 
31
  # EasyOCR con GPU si está disponible
models/best_placas.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:658f7b26354a2906ac8dbb2a0536637f92c425850af9273d05566f35d780d58a
3
+ size 6245603