Spaces:
Runtime error
Runtime error
Update utility/utils.py
Browse files- utility/utils.py +5 -5
utility/utils.py
CHANGED
|
@@ -4,7 +4,7 @@ from huggingface_hub import InferenceClient
|
|
| 4 |
from dotenv import load_dotenv
|
| 5 |
import json
|
| 6 |
import re
|
| 7 |
-
import easyocr
|
| 8 |
from PIL import Image, ImageEnhance, ImageDraw
|
| 9 |
import cv2
|
| 10 |
import numpy as np
|
|
@@ -20,10 +20,10 @@ HFT = os.getenv('HF_TOKEN')
|
|
| 20 |
client = InferenceClient(model="mistralai/Mistral-7B-Instruct-v0.3", token=HFT)
|
| 21 |
|
| 22 |
# Specify a custom model storage directory (ensure this path is writable)
|
| 23 |
-
model_storage_directory = '/app/models'
|
| 24 |
|
| 25 |
# Create the reader object and set the model storage directory
|
| 26 |
-
reader = easyocr.Reader(['en'], model_storage_directory=model_storage_directory)
|
| 27 |
|
| 28 |
def draw_boxes(image, bounds, color='red', width=2):
|
| 29 |
draw = ImageDraw.Draw(image)
|
|
@@ -105,10 +105,10 @@ def extract_text_from_images(image_paths, RESULT_FOLDER):
|
|
| 105 |
# Enhance the image before OCR
|
| 106 |
#enhanced_image = load_image(image_path)
|
| 107 |
enhanced_image = process_image(image_path, scale=2)
|
| 108 |
-
bounds = reader.readtext(enhanced_image)
|
| 109 |
# Draw boxes on the processed image
|
| 110 |
img_result = Image.fromarray(enhanced_image)
|
| 111 |
-
draw_boxes(img_result, bounds)
|
| 112 |
|
| 113 |
result_image_path = os.path.join(RESULT_FOLDER, f'result_{os.path.basename(image_path)}')
|
| 114 |
img_result.save(result_image_path) # Save the processed image
|
|
|
|
| 4 |
from dotenv import load_dotenv
|
| 5 |
import json
|
| 6 |
import re
|
| 7 |
+
#import easyocr
|
| 8 |
from PIL import Image, ImageEnhance, ImageDraw
|
| 9 |
import cv2
|
| 10 |
import numpy as np
|
|
|
|
| 20 |
client = InferenceClient(model="mistralai/Mistral-7B-Instruct-v0.3", token=HFT)
|
| 21 |
|
| 22 |
# Specify a custom model storage directory (ensure this path is writable)
|
| 23 |
+
#model_storage_directory = '/app/models'
|
| 24 |
|
| 25 |
# Create the reader object and set the model storage directory
|
| 26 |
+
#reader = easyocr.Reader(['en'], model_storage_directory=model_storage_directory)
|
| 27 |
|
| 28 |
def draw_boxes(image, bounds, color='red', width=2):
|
| 29 |
draw = ImageDraw.Draw(image)
|
|
|
|
| 105 |
# Enhance the image before OCR
|
| 106 |
#enhanced_image = load_image(image_path)
|
| 107 |
enhanced_image = process_image(image_path, scale=2)
|
| 108 |
+
#bounds = reader.readtext(enhanced_image)
|
| 109 |
# Draw boxes on the processed image
|
| 110 |
img_result = Image.fromarray(enhanced_image)
|
| 111 |
+
#draw_boxes(img_result, bounds)
|
| 112 |
|
| 113 |
result_image_path = os.path.join(RESULT_FOLDER, f'result_{os.path.basename(image_path)}')
|
| 114 |
img_result.save(result_image_path) # Save the processed image
|