Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -5,7 +5,9 @@ from fastapi.security.api_key import APIKeyHeader
|
|
5 |
from typing import Optional, Annotated
|
6 |
from fastapi.encoders import jsonable_encoder
|
7 |
from PIL import Image
|
8 |
-
|
|
|
|
|
9 |
import pytesseract
|
10 |
from nltk.tokenize import sent_tokenize
|
11 |
from transformers import MarianMTModel, MarianTokenizer
|
@@ -30,9 +32,14 @@ async def ocr(
|
|
30 |
print("[1]",os.popen(f'cat /etc/debian_version').read())
|
31 |
print("[2]",os.popen(f'cat /etc/issue').read())
|
32 |
print("[3]",os.popen(f'apt search tesseract').read())
|
33 |
-
content = await image.read()
|
34 |
-
image = Image.open(BytesIO(content))
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
36 |
if hasattr(pytesseract, "image_to_string"):
|
37 |
print("Image to string function is available")
|
38 |
else:
|
|
|
5 |
from typing import Optional, Annotated
|
6 |
from fastapi.encoders import jsonable_encoder
|
7 |
from PIL import Image
|
8 |
+
import io
|
9 |
+
import cv2
|
10 |
+
import numpy as np
|
11 |
import pytesseract
|
12 |
from nltk.tokenize import sent_tokenize
|
13 |
from transformers import MarianMTModel, MarianTokenizer
|
|
|
32 |
print("[1]",os.popen(f'cat /etc/debian_version').read())
|
33 |
print("[2]",os.popen(f'cat /etc/issue').read())
|
34 |
print("[3]",os.popen(f'apt search tesseract').read())
|
35 |
+
# content = await image.read()
|
36 |
+
# image = Image.open(BytesIO(content))
|
37 |
+
image_stream = io.BytesIO(image)
|
38 |
+
image_stream.seek(0)
|
39 |
+
file_bytes = np.asarray(bytearray(image_stream.read()), dtype=np.uint8)
|
40 |
+
frame = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
|
41 |
+
# label = read_img(frame)
|
42 |
+
print("[image]",frame)
|
43 |
if hasattr(pytesseract, "image_to_string"):
|
44 |
print("Image to string function is available")
|
45 |
else:
|