o
    ^h
                     @   s8  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
 eddZejedgd	dgdgd
 dd Ze Zede  ejdd	d ejdd	d ejdedddd ejdedddd d dlmZ d dlmZ ejejddgd ejejddgd edkrd dlZejeddd  dS dS )!    )FastAPI)CORSMiddleware)StaticFilesN)Pathz/backend)	root_path*T)allow_originsallow_credentialsallow_methodsallow_headersc               
   C   s  t jt jt} t j| dd}t j|odt jt j|dodt jt j|dodt jt j|dodt jt j|dodt jt j|dodt jt j|dodt jt j|d	}|std
| d zUtj	|  zddl
m
} | std tdW n9 ty   t j| d}tjtj|gdddd}|jdkrtd td|j  td|j  tdY nw W n ty } ztdt|  td W Y d }~nd }~ww |t jd< |S )Nmodelszgrounding-dinozconfig.jsonzmodel.safetensorszpreprocessor_config.jsonzspecial_tokens_map.jsonztokenizer_config.jsonztokenizer.jsonz	vocab.txtzModel not found at z. Downloading...r   )download_modelz-Failed to download model using import method.zDownload failedzdownload_model.pyTF)capture_outputtextcheckzError downloading model:zSTDOUT: zSTDERR: z@Failed to download model. Please check the error messages above.zERROR: zJThe application will continue, but image comparison features may not work.	MODEL_DIR)ospathdirnameabspath__file__joinexistsprintsysappendr   ImportError
subprocessrun
executable
returncodestdoutstderrRuntimeError	Exceptionstrenviron)current_dir	model_dirmodel_files_existr   download_scriptresulte r-   6/var/www/html/construction_image-detection-poc/main.pyensure_model_exists   sb   

r/   zUsing model directory: Input_Images)exist_okOutput_Imagesz/Input_Images)	directoryinput_images)namez/Output_Imagesoutput_images)auth)uploadz/apir7   )prefixtagsr8   __main__z	127.0.0.1i  )hostport)fastapir   fastapi.middleware.corsr   fastapi.staticfilesr   r   r   r   pathlibr   appadd_middlewarer/   r(   r   makedirsmountsrc.routersr7   r8   include_routerrouter__name__uvicornr   r-   r-   r-   r.   <module>   s<    
	2