Spaces:
Runtime error
Runtime error
Update bert_explainer.py
Browse files- bert_explainer.py +12 -1
bert_explainer.py
CHANGED
|
@@ -16,7 +16,18 @@ HF_TOKEN = os.environ.get("HF_TOKEN")
|
|
| 16 |
|
| 17 |
|
| 18 |
# OCR 模組
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# 設定裝置(GPU 優先)
|
| 22 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
# OCR 模組
|
| 19 |
+
import os
|
| 20 |
+
|
| 21 |
+
# 在目前專案資料夾下創建一個安全的模型資料夾 (保證有權限)
|
| 22 |
+
easyocr_dir = os.path.join(os.path.dirname(__file__), "easyocr_models")
|
| 23 |
+
os.makedirs(easyocr_dir, exist_ok=True)
|
| 24 |
+
|
| 25 |
+
reader = easyocr.Reader(
|
| 26 |
+
['ch_tra', 'en'],
|
| 27 |
+
gpu=torch.cuda.is_available(),
|
| 28 |
+
model_storage_directory=easyocr_dir
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
|
| 32 |
# 設定裝置(GPU 優先)
|
| 33 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|