Spaces:
Runtime error
Runtime error
Update utility/utils.py
Browse files3 unmodified lines456789109 unmodified lines2021222324252627282975 unmodified lines1051061071081091101111121131143 unmodified linesfrom dotenv import load_dotenvimport jsonimport reimport 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'# Create the reader object and set the model storage directoryreader = 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)# Draw boxes on the processed imageimg_result = Image.fromarray(enhanced_image)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 image3 unmodified lines456789109 unmodified lines2021222324252627282975 unmodified lines1051061071081091101111121131143 unmodified linesfrom dotenv import load_dotenvimport jsonimport re#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'# Create the reader object and set the 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)# Draw boxes on the processed imageimg_result = Image.fromarray(enhanced_image)#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 image
utility/utils.py+5-5