
    hg                     n   d dl mZ d dlmZmZ d dlmZ d dlmZ d dl	m
Z
 d dlZd dlZd dlZd dlmZ d dlZ e        dZ ej$                  d	      Z	 ej(                  j+                  e      Z ej.                  e
      Zd Zy# e$ r*Z ede         ej8                  d       Y dZ[d ZydZ[ww xY w)    )Path)convert_from_pathpdfinfo_from_path)vision)service_account)
PredictionN)load_dotenvz>public/credentials/isentropic-card-468114-f6-1ee415ed3a11.jsonPOPPLER_PATH)credentialsz$Failed to initialize Vision client:    c                 R   ddl m}  |       }| j                  |d       t        j                  |j                               }t        j                  |      }|j                  j                  r"t        d|j                  j                         |j                  j                  S )Nr   )BytesIOPNG)format)content)imagezOCR error: )ior   saver   Imagegetvaluevision_clientdocument_text_detectionerrormessageRuntimeErrorfull_text_annotationtext)	pil_imager   bufferr   responses        4/var/www/html/eduruby.in/utils/question_extractor.pyocr_page_imager"      s    YFNN6%N(LL!23E4454AH~~[)?)?(@ABB((---    )pathlibr   	pdf2imager   r   google.cloudr   google.oauth2r   utils.get_layoutr   jsonsystimedotenvr	   osGCP_CREDENTIALS_JSONgetenvr
   Credentialsfrom_service_account_filer   ImageAnnotatorClientr   	Exceptioneprintexitr"    r#   r!   <module>r8      s     :  ) '  
   	 
 X 		.)!--GGK 0F//KHM	.  	0
45CHHQKK	.s   .B B4
B//B4