Spaces:
Runtime error
Runtime error
Damanger
commited on
Commit
·
62aa642
1
Parent(s):
d0ee279
corrigiendo app
Browse files- Dockerfile +5 -5
- app.py +11 -6
Dockerfile
CHANGED
|
@@ -1,12 +1,12 @@
|
|
| 1 |
FROM python:3.11-slim
|
| 2 |
|
| 3 |
ENV PYTHONUNBUFFERED=1 \
|
| 4 |
-
HF_HOME=/
|
|
|
|
| 5 |
|
| 6 |
-
# 👇 añade estas dependencias del sistema
|
| 7 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 8 |
-
libgl1 libglib2.0-0 \
|
| 9 |
-
|
| 10 |
|
| 11 |
WORKDIR /app
|
| 12 |
COPY requirements.txt .
|
|
@@ -14,4 +14,4 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
| 14 |
|
| 15 |
COPY . .
|
| 16 |
EXPOSE 7860
|
| 17 |
-
CMD ["uvicorn",
|
|
|
|
| 1 |
FROM python:3.11-slim
|
| 2 |
|
| 3 |
ENV PYTHONUNBUFFERED=1 \
|
| 4 |
+
HF_HOME=/tmp/.cache/huggingface \
|
| 5 |
+
YOLO_CONFIG_DIR=/tmp/Ultralytics
|
| 6 |
|
|
|
|
| 7 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 8 |
+
libgl1 libglib2.0-0 && \
|
| 9 |
+
rm -rf /var/lib/apt/lists/*
|
| 10 |
|
| 11 |
WORKDIR /app
|
| 12 |
COPY requirements.txt .
|
|
|
|
| 14 |
|
| 15 |
COPY . .
|
| 16 |
EXPOSE 7860
|
| 17 |
+
CMD ["uvicorn","app:app","--host","0.0.0.0","--port","7860"]
|
app.py
CHANGED
|
@@ -7,29 +7,34 @@ import easyocr
|
|
| 7 |
from fastapi import FastAPI, HTTPException, File, UploadFile
|
| 8 |
from fastapi.middleware.cors import CORSMiddleware
|
| 9 |
from pydantic import BaseModel, Field
|
| 10 |
-
from huggingface_hub import hf_hub_download
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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), #
|
| 20 |
)
|
| 21 |
except Exception:
|
| 22 |
-
# Fallback
|
|
|
|
| 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
|
| 32 |
-
reader = easyocr.Reader(['en'], gpu=torch.cuda.is_available()
|
|
|
|
| 33 |
|
| 34 |
ALLOW = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
| 35 |
|
|
|
|
| 7 |
from fastapi import FastAPI, HTTPException, File, UploadFile
|
| 8 |
from fastapi.middleware.cors import CORSMiddleware
|
| 9 |
from pydantic import BaseModel, Field
|
|
|
|
| 10 |
|
| 11 |
+
TMP_DIR = "/tmp"
|
| 12 |
+
os.makedirs(f"{TMP_DIR}/Ultralytics", exist_ok=True)
|
| 13 |
+
os.makedirs(f"{TMP_DIR}/.EasyOCR", exist_ok=True)
|
| 14 |
+
|
| 15 |
+
from huggingface_hub import hf_hub_download
|
| 16 |
|
|
|
|
| 17 |
try:
|
| 18 |
WEIGHTS = hf_hub_download(
|
| 19 |
repo_id="keremberke/yolov5n-license-plate",
|
| 20 |
filename="best.pt",
|
| 21 |
+
token=os.getenv("HF_TOKEN", None), # opcional
|
| 22 |
)
|
| 23 |
except Exception:
|
| 24 |
+
# 2) Fallback directo a /tmp si falla la caché
|
| 25 |
+
local_path = os.path.join(TMP_DIR, "best.pt")
|
| 26 |
if not os.path.exists(local_path):
|
| 27 |
url = "https://huggingface.co/keremberke/yolov5n-license-plate/resolve/main/best.pt"
|
| 28 |
req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})
|
| 29 |
with urllib.request.urlopen(req) as r, open(local_path, "wb") as f:
|
| 30 |
f.write(r.read())
|
| 31 |
WEIGHTS = local_path
|
| 32 |
+
|
| 33 |
yolo = YOLO(WEIGHTS)
|
| 34 |
|
| 35 |
# EasyOCR con GPU si está disponible
|
| 36 |
+
reader = easyocr.Reader(['en'], gpu=torch.cuda.is_available(),
|
| 37 |
+
model_storage_directory=f"{TMP_DIR}/.EasyOCR")
|
| 38 |
|
| 39 |
ALLOW = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
| 40 |
|