Spaces:
Sleeping
Sleeping
Venkat V
commited on
Commit
·
c2717d6
1
Parent(s):
8896007
changed to use gpu if applicable
Browse files- device_config.py +10 -0
- ocr_module/__init__.py +6 -2
- summarizer_module/__init__.py +5 -1
- yolo_module/__init__.py +4 -1
device_config.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# device_config.py
|
2 |
+
import torch
|
3 |
+
|
4 |
+
def get_device():
|
5 |
+
if torch.cuda.is_available():
|
6 |
+
return "cuda"
|
7 |
+
elif torch.backends.mps.is_available():
|
8 |
+
return "mps" # For Apple Silicon
|
9 |
+
else:
|
10 |
+
return "cpu"
|
ocr_module/__init__.py
CHANGED
@@ -5,9 +5,13 @@ import cv2
|
|
5 |
import torch
|
6 |
from textblob import TextBlob
|
7 |
|
|
|
|
|
|
|
8 |
# Enable GPU if available
|
9 |
-
|
10 |
-
reader
|
|
|
11 |
|
12 |
def expand_bbox(bbox, image_size, pad=10):
|
13 |
x1, y1, x2, y2 = bbox
|
|
|
5 |
import torch
|
6 |
from textblob import TextBlob
|
7 |
|
8 |
+
from device_config import get_device
|
9 |
+
device = get_device()
|
10 |
+
|
11 |
# Enable GPU if available
|
12 |
+
reader = easyocr.Reader(['en'], gpu=(device == "cuda"))
|
13 |
+
print(f"✅ EasyOCR reader initialized on: {device}")
|
14 |
+
|
15 |
|
16 |
def expand_bbox(bbox, image_size, pad=10):
|
17 |
x1, y1, x2, y2 = bbox
|
summarizer_module/__init__.py
CHANGED
@@ -1,12 +1,16 @@
|
|
1 |
# summarizer_module/__init__.py
|
2 |
|
3 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
|
|
|
|
|
|
|
|
4 |
|
5 |
# Use a small local model (e.g., Phi-2)
|
6 |
MODEL_ID = "microsoft/phi-2" # Ensure it's downloaded and cached locally
|
7 |
|
8 |
# Load model and tokenizer
|
9 |
-
model = AutoModelForCausalLM.from_pretrained(MODEL_ID)
|
10 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
11 |
summarizer = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
12 |
|
|
|
1 |
# summarizer_module/__init__.py
|
2 |
|
3 |
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
4 |
+
from device_config import get_device
|
5 |
+
import torch
|
6 |
+
|
7 |
+
device = get_device()
|
8 |
|
9 |
# Use a small local model (e.g., Phi-2)
|
10 |
MODEL_ID = "microsoft/phi-2" # Ensure it's downloaded and cached locally
|
11 |
|
12 |
# Load model and tokenizer
|
13 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_ID).to(device)
|
14 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
15 |
summarizer = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
16 |
|
yolo_module/__init__.py
CHANGED
@@ -1,12 +1,15 @@
|
|
1 |
# yolo_module.py
|
2 |
from ultralytics import YOLO
|
|
|
3 |
from PIL import Image, ImageDraw
|
4 |
import numpy as np
|
5 |
import easyocr
|
6 |
|
7 |
# Load YOLO model
|
8 |
MODEL_PATH = "models/best.pt"
|
9 |
-
model = YOLO(MODEL_PATH)
|
|
|
|
|
10 |
|
11 |
# Optional OCR reader for arrow label detection
|
12 |
reader = easyocr.Reader(['en'], gpu=False)
|
|
|
1 |
# yolo_module.py
|
2 |
from ultralytics import YOLO
|
3 |
+
from device_config import get_device
|
4 |
from PIL import Image, ImageDraw
|
5 |
import numpy as np
|
6 |
import easyocr
|
7 |
|
8 |
# Load YOLO model
|
9 |
MODEL_PATH = "models/best.pt"
|
10 |
+
model = YOLO(MODEL_PATH).to(device)
|
11 |
+
print(f"✅ YOLO model loaded on: {device}")
|
12 |
+
|
13 |
|
14 |
# Optional OCR reader for arrow label detection
|
15 |
reader = easyocr.Reader(['en'], gpu=False)
|