Damanger commited on
Commit
af9ef77
·
1 Parent(s): f16d0cc

corrigiendo app

Browse files
Files changed (2) hide show
  1. app.py +8 -18
  2. requirements.txt +8 -7
app.py CHANGED
@@ -10,6 +10,9 @@ from fastapi import FastAPI, HTTPException, File, UploadFile, Form
10
  from fastapi.middleware.cors import CORSMiddleware
11
  from pydantic import BaseModel, Field
12
 
 
 
 
13
 
14
  TMP_DIR = "/tmp"
15
  paths = [
@@ -23,21 +26,10 @@ for p in paths:
23
 
24
  from huggingface_hub import hf_hub_download
25
 
26
- try:
27
- WEIGHTS = hf_hub_download(
28
- repo_id="keremberke/yolov5n-license-plate",
29
- filename="best.pt",
30
- token=os.getenv("HF_TOKEN", None), # opcional
31
- )
32
- except Exception:
33
- # 2) Fallback directo a /tmp si falla la caché
34
- local_path = os.path.join(TMP_DIR, "best.pt")
35
- if not os.path.exists(local_path):
36
- url = "https://huggingface.co/keremberke/yolov5n-license-plate/resolve/main/best.pt"
37
- req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})
38
- with urllib.request.urlopen(req) as r, open(local_path, "wb") as f:
39
- f.write(r.read())
40
- WEIGHTS = local_path
41
 
42
  yolo = YOLO(WEIGHTS)
43
 
@@ -45,9 +37,7 @@ yolo = YOLO(WEIGHTS)
45
  reader = easyocr.Reader(
46
  ['en'],
47
  gpu=torch.cuda.is_available(),
48
- model_storage_directory=f"{TMP_DIR}/.EasyOCR",
49
- user_network_directory=f"{TMP_DIR}/.EasyOCR/user_network",
50
- download_enabled=True,
51
  )
52
 
53
  ALLOW = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
 
10
  from fastapi.middleware.cors import CORSMiddleware
11
  from pydantic import BaseModel, Field
12
 
13
+ os.environ.setdefault("YOLO_CONFIG_DIR", "/tmp/Ultralytics")
14
+ os.environ.setdefault("HF_HOME", "/tmp/.cache/huggingface")
15
+ os.makedirs(os.environ["YOLO_CONFIG_DIR"], exist_ok=True)
16
 
17
  TMP_DIR = "/tmp"
18
  paths = [
 
26
 
27
  from huggingface_hub import hf_hub_download
28
 
29
+ # --- PESOS COMPATIBLES ULTRALYTICS (YOLOv11) ---
30
+ REPO_ID = "morsetechlab/yolov11-license-plate-detection"
31
+ FILENAME = "license-plate-finetune-v1n.pt" # o v1s/v1m/v1l/v1x
32
+ WEIGHTS = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
 
 
 
 
 
 
 
 
 
 
 
33
 
34
  yolo = YOLO(WEIGHTS)
35
 
 
37
  reader = easyocr.Reader(
38
  ['en'],
39
  gpu=torch.cuda.is_available(),
40
+ model_storage_directory="/tmp/.EasyOCR",
 
 
41
  )
42
 
43
  ALLOW = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
requirements.txt CHANGED
@@ -1,12 +1,13 @@
1
- fastapi
2
- uvicorn[standard]
3
  pydantic==2.*
4
- python-multipart
5
- ultralytics
6
  yolov5
7
- easyocr
8
  opencv-python==4.10.0.84
9
- huggingface_hub
10
  torch
11
  pillow
12
- pillow-heif
 
 
 
 
 
 
 
 
 
 
1
  pydantic==2.*
 
 
2
  yolov5
 
3
  opencv-python==4.10.0.84
 
4
  torch
5
  pillow
6
+ pillow-heif
7
+ ultralytics==8.3.180
8
+ easyocr==1.7.1
9
+ fastapi==0.111.0
10
+ uvicorn[standard]==0.30.1
11
+ opencv-python-headless==4.10.0.84
12
+ python-multipart==0.0.9
13
+ huggingface_hub==0.24.6