
    h                         S SK JrJr  S SKrS SKJr  S SKJrJ	r	J
r
  SSKJrJr  S SKJr   " S S	\5      r\S
\4S j5       r\" \S9r\R'                  S5      S 5       r\R+                  S5      S\4S j5       rg)    )FastAPIHTTPExceptionN)	BaseModel)ListDictAny   )
load_modelpredict)asynccontextmanagerc                        \ rS rSr% \\S'   Srg)PredictionRequest   gw N)__name__
__module____qualname____firstlineno__int__annotations____static_attributes__r       1G:\Projects\Python Projects\fpl_model\app\main.pyr   r      s    Gr   r   appc                   #    [        S5         [        5       nU(       d  [        S5      e S7v   [        S5        g! [         a  n[        SU 35        [        S5      eSnAff = f7f)z?
Lifespan event to load the model when the application starts.
z1Starting FastAPI application and loading model...z$Failed to load the model on startup.zError loading model: z6Application startup failed due to model loading error.Nz'FastAPI application is shutting down...)printr
   RuntimeError	Exception)r   modeles      r   lifespanr"      sn     
 

=>UEFF 
 
	
34	  U%aS)*STTUs%   A(= A(
A%A  A%%A()r"   /c                  
    SS0$ )Nmessagez"Welcome to the FPL Prediction API!r   r   r   r   	read_rootr&   #   s    ;<<r   z/predictrequestc                     U R                   (       d
  [        SSS9eU R                   n [        U5      nSUR                  SS90$ ! [         a  n[        S[        U5      S9eSnAff = f)z
Endpoint to make predictions using the pre-trained model.

:param request: PredictionRequest containing the features for prediction.
:return: Dictionary with predictions.
i  z$No features provided for prediction.)status_codedetailpredictionsrecords)orientN)r   r   r   to_json
ValueErrorstr)r'   r   r+   r!   s       r   predict_endpointr1   &   sj     ::4Z[[	B<bk{22)2DEE <CF;;<s   A 
A'A""A')fastapir   r   pandaspdpydanticr   typingr   r   r   
core.modelr
   r   
contextlibr   r   r"   r   getr&   postr1   r   r   r   <module>r;      s    )   " " + *	  5 5 5" x = =*</ < <r   