can u change the folder to dynamic detect…
- User
can u change the folder to dynamic detect C:\Users\ADAM7\Desktop\Projects_demo\03_ocr\output like in this code can only work for 1_output only into excel... : import os import azure.ai.vision as sdk import openpyxl from openpyxl.styles import Font, PatternFill from openpyxl.utils import get_column_letter import os
Exported to environment variable, safer and more secure for sensitive information like APIs
VISION_ENDPOINT = "https://e1455.cognitiveservices.azure.com/" #os.environ.get("VISION_ENDPOINT") VISION_KEY = "f854095df16b4e889476c0881b81ab44" #os.environ.get("VISION_KEY")
if VISION_ENDPOINT is None or VISION_KEY is None: raise ValueError("VISION_ENDPOINT and VISION_KEY must be set in the environment")
service_options = sdk.VisionServiceOptions(VISION_ENDPOINT, VISION_KEY)
Specify the paths to your local image files
image_paths = [ r'C:\Users\ADAM7\Desktop\Projects_demo\03_ocr\output\1_output\01_lead_number.jpg', r'C:\Users\ADAM7\Desktop\Projects_demo\03_ocr\output\1_output\02_company.jpg', r'C:\Users\ADAM7\Desktop\Projects_demo\03_ocr\output\1_output\03_name.jpg', r'C:\Users\ADAM7\Desktop\Projects_demo\03_ocr\output\1_output\07_industry.jpg', r'C:\Users\ADAM7\Desktop\Projects_demo\03_ocr\output\1_output\08_interest.jpg', r'C:\Users\ADAM7\Desktop\Projects_demo\03_ocr\output\1_output\11_preparedBy.jpg', r'C:\Users\ADAM7\Desktop\Projects_demo\03_ocr\output\1_output\06_category_resized.jpg\06_category_resized.jpg', r'C:\Users\ADAM7\Desktop\Projects_demo\03_ocr\output\1_output\09_product_resized.jpg\09_product_resized.jpg', r'C:\Users\ADAM7\Desktop\Projects_demo\03_ocr\output\1_output\05_nameCards.jpg' ]
Specify corresponding headers
headers = ["Lead Number", "Company", "Name", "Industry", "Interest", "Prepared by","Category","Product", "Etc"]
Initialize the Excel workbook and sheet
excel_file_path = r'C:\Users\ADAM7\Desktop\Projects_demo\03_ocr\test.xlsx' wb = openpyxl.Workbook() sheet = wb.active
Write headers to the Excel sheet and apply formatting
sheet.append(headers)
Header formatting
for cell in sheet[1]: cell.font = Font(bold=True) cell.fill = PatternFill(start_color="DDDDDD", end_color="DDDDDD", fill_type="solid")
Initialize a list to store the extracted information
extracted_info_list = []
Iterate through each image path and extract information using OCR
for image_path, header in zip(image_paths, headers): with open(image_path, 'rb') as image_file: image_buffer = image_file.read()
code - Assistant