Spaces:
Runtime error
Runtime error
Update utility/utils.py
Browse files3 unmodified lines4567789109 unmodified lines20212223232425262627282975 unmodified lines1051061071081081091101111111121131143 unmodified linesfrom dotenv import load_dotenvimport jsonimport reimport easyocr#import easyocrfrom PIL import Image, ImageEnhance, ImageDrawimport cv2import numpy as np9 unmodified linesclient = InferenceClient(model="mistralai/Mistral-7B-Instruct-v0.3", token=HFT)
# Specify a custom model storage directory (ensure this path is writable)model_storage_directory = '/app/models'#model_storage_directory = '/app/models'
# Create the reader object and set the model storage directoryreader = easyocr.Reader(['en'], model_storage_directory=model_storage_directory)#reader = easyocr.Reader(['en'], model_storage_directory=model_storage_directory)
def draw_boxes(image, bounds, color='red', width=2): draw = ImageDraw.Draw(image)75 unmodified lines # Enhance the image before OCR #enhanced_image = load_image(image_path) enhanced_image = process_image(image_path, scale=2) bounds = reader.readtext(enhanced_image) #bounds = reader.readtext(enhanced_image) # Draw boxes on the processed image img_result = Image.fromarray(enhanced_image) draw_boxes(img_result, bounds) #draw_boxes(img_result, bounds)
result_image_path = os.path.join(RESULT_FOLDER, f'result_{os.path.basename(image_path)}') img_result.save(result_image_path) # Save the processed imageutility/utils.py+5-5