Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,17 +3,23 @@ import cv2
|
|
| 3 |
import numpy as np
|
| 4 |
import uvicorn
|
| 5 |
import math
|
|
|
|
| 6 |
from fastapi import FastAPI, HTTPException
|
| 7 |
from fastapi.responses import PlainTextResponse
|
| 8 |
from fastapi.encoders import jsonable_encoder
|
| 9 |
from pydantic import BaseModel
|
| 10 |
from paddleocr import PaddleOCR, PPStructureV3
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
from collections.abc import Mapping, Sequence
|
| 15 |
from dataclasses import is_dataclass, asdict
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# --- Configuration & Model Loading ---
|
| 19 |
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
import uvicorn
|
| 5 |
import math
|
| 6 |
+
import os
|
| 7 |
from fastapi import FastAPI, HTTPException
|
| 8 |
from fastapi.responses import PlainTextResponse
|
| 9 |
from fastapi.encoders import jsonable_encoder
|
| 10 |
from pydantic import BaseModel
|
| 11 |
from paddleocr import PaddleOCR, PPStructureV3
|
|
|
|
|
|
|
|
|
|
| 12 |
from collections.abc import Mapping, Sequence
|
| 13 |
from dataclasses import is_dataclass, asdict
|
| 14 |
|
| 15 |
+
# --- Update temp directories so it works in upgraded CPU environment ---
|
| 16 |
+
# Set PADDLEX_HOME to a writable directory like the current working directory
|
| 17 |
+
# or the standard temporary directory.
|
| 18 |
+
os.environ['PADDLEX_HOME'] = os.path.join(os.getcwd(), 'paddlex_cache')
|
| 19 |
+
# os.environ['PADDLEX_HOME'] = '/tmp/paddlex_cache' # Also a good, writable option
|
| 20 |
+
|
| 21 |
+
# Ensure the directory exists before PaddleX tries to use it
|
| 22 |
+
os.makedirs(os.environ['PADDLEX_HOME'], exist_ok=True)
|
| 23 |
|
| 24 |
# --- Configuration & Model Loading ---
|
| 25 |
|