Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -5,20 +5,13 @@ from PIL import Image
|
|
5 |
import torch
|
6 |
import spaces
|
7 |
|
8 |
-
load_dotenv() # load .env file
|
9 |
-
|
10 |
-
HF_TOKEN = os.getenv("ocr_sec")
|
11 |
-
client = Client("theoracle/easyocr-api", hf_token=HF_TOKEN)
|
12 |
-
|
13 |
-
# Create dummy tensor to confirm GPU availability
|
14 |
-
zero = torch.Tensor([0]).cuda()
|
15 |
-
print("Torch is using:", zero.device) # Should be 'cuda:0'
|
16 |
|
17 |
# Declare reader outside the function (only once)
|
18 |
-
|
19 |
|
20 |
@spaces.GPU # Ensures this function runs on GPU
|
21 |
def extract_text(image):
|
|
|
22 |
result = reader.readtext(np.array(image), detail=0)
|
23 |
text = "\n".join(result)
|
24 |
print("OCR complete. Text:", text)
|
|
|
5 |
import torch
|
6 |
import spaces
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
# Declare reader outside the function (only once)
|
10 |
+
|
11 |
|
12 |
@spaces.GPU # Ensures this function runs on GPU
|
13 |
def extract_text(image):
|
14 |
+
reader = easyocr.Reader(['en'], gpu=True)
|
15 |
result = reader.readtext(np.array(image), detail=0)
|
16 |
text = "\n".join(result)
|
17 |
print("OCR complete. Text:", text)
|