Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -12,10 +12,22 @@ os.environ['USE_TF'] = '0' # Set TensorFlow to off
|
|
12 |
os.environ['USE_TORCH'] = '1' # Set PyTorch to on
|
13 |
|
14 |
from doctr.models import ocr_predictor
|
15 |
-
|
16 |
|
|
|
17 |
|
|
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
"""
|
20 |
Perform OCR with doctr
|
21 |
"""
|
|
|
12 |
os.environ['USE_TORCH'] = '1' # Set PyTorch to on
|
13 |
|
14 |
from doctr.models import ocr_predictor
|
15 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
16 |
|
17 |
+
# Example for PyTorch model or doctr model
|
18 |
|
19 |
+
ocr_model = ocr_predictor(det_arch='db_resnet50', reco_arch='crnn_vgg16_bn', pretrained=True).to(device)
|
20 |
|
21 |
+
|
22 |
+
import torch
|
23 |
+
|
24 |
+
# Check if CUDA is available
|
25 |
+
if torch.cuda.is_available():
|
26 |
+
print(f"GPU is available. Device: {torch.cuda.get_device_name(0)}")
|
27 |
+
else:
|
28 |
+
print("GPU is not available, using CPU.")
|
29 |
+
|
30 |
+
|
31 |
"""
|
32 |
Perform OCR with doctr
|
33 |
"""
|