Spaces:
Sleeping
Sleeping
Update app/utils.py
Browse files- app/utils.py +12 -3
app/utils.py
CHANGED
@@ -4,14 +4,22 @@ from transformers import AutoModel, AutoTokenizer
|
|
4 |
from PIL import Image, ImageEnhance, ImageFilter
|
5 |
import torch
|
6 |
import logging
|
7 |
-
|
|
|
8 |
|
9 |
|
10 |
logger = logging.getLogger(__name__)
|
11 |
|
12 |
class OCRModel:
|
13 |
_instance = None
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
def __new__(cls):
|
16 |
if cls._instance is None:
|
17 |
cls._instance = super(OCRModel, cls).__new__(cls)
|
@@ -21,7 +29,8 @@ class OCRModel:
|
|
21 |
def initialize(self):
|
22 |
try:
|
23 |
|
24 |
-
|
|
|
25 |
logger.info("Initializing OCR model...")
|
26 |
# Try loading with use_fast=False if the fast tokenizer fails
|
27 |
try:
|
|
|
4 |
from PIL import Image, ImageEnhance, ImageFilter
|
5 |
import torch
|
6 |
import logging
|
7 |
+
import shutil
|
8 |
+
import os
|
9 |
|
10 |
|
11 |
logger = logging.getLogger(__name__)
|
12 |
|
13 |
class OCRModel:
|
14 |
_instance = None
|
15 |
+
|
16 |
+
def clear_huggingface_cache(self):
|
17 |
+
cache_dir = os.path.expanduser("~/.cache/huggingface")
|
18 |
+
if os.path.exists(cache_dir):
|
19 |
+
shutil.rmtree(cache_dir)
|
20 |
+
print("Hugging Face cache cleared.")
|
21 |
+
else:
|
22 |
+
print("No Hugging Face cache found.")
|
23 |
def __new__(cls):
|
24 |
if cls._instance is None:
|
25 |
cls._instance = super(OCRModel, cls).__new__(cls)
|
|
|
29 |
def initialize(self):
|
30 |
try:
|
31 |
|
32 |
+
self.clear_huggingface_cache()
|
33 |
+
|
34 |
logger.info("Initializing OCR model...")
|
35 |
# Try loading with use_fast=False if the fast tokenizer fails
|
36 |
try:
|