
    6Fi                         d dl Z d dlZd dlZd dlmZ d dlmZ  e              e j        d          Z ee          Z	dZ
dedefd	ZdS )
    N)OpenAI)load_dotenvOPENAI_API_KEY)api_keya  
You are an attire classification engine. Analyze the person's clothing and classify the dress code into one of three labels:
- 'formal'
- 'informal'
- 'semi-formal' (only if you are uncertain between the two)

Rules:
- Only output JSON. No comments, no explanations outside JSON.
- Include these fields in your JSON output:

{
  "dress_code": "formal | informal | semi-formal",
  "reason": "Brief justification for the classification",
  "formal_score": float between 0 and 1,
  "informal_score": float between 0 and 1,
  "confidence": float between 0 and 1 (confidence in your final label)
}

Scoring guidelines:
- 'formal_score' measures how well the attire fits typical formal standards (e.g., shirt, tie, trousers, tucked-in, formal shoes).
- 'informal_score' measures presence of casual indicators (e.g., t-shirt, jeans, sneakers, rolled sleeves, untucked shirt).
- Use 'semi-formal' only if the scores are very close (e.g., within 0.1 of each other).
- 'confidence' should be high (near 1) only if the difference between scores is large (> 0.4), and low (near 0.5) if close.

You must always return a complete and valid JSON object.
You must return only raw JSON. Do not wrap it in triple backticks. Do not add markdown formatting.
base64_imagereturnc           	      z   	 t           j        j                            dddt          dddd|  idgd	gd
d          }|j        d         j        j                                        }|	                    d          r<|
                    dd          
                    dd                                          }	 t          j        |          S # t          j        $ r}t          d|           d|dcY d }~S d }~ww xY w# t          $ r0}t          d|           t!          |          ddddddcY d }~S d }~ww xY w)Nzgpt-4ousertext)typer   	image_urlurlzdata:image/jpeg;base64,)r   r   )rolecontenti,  g333333?)modelmessages
max_tokenstemperaturer   z```json z```u%   ❌ Failed to parse JSON from OpenAI:zInvalid JSON from OpenAI)errorrawu   ❌ Attire check failed:unknownzFailed to analyze attire)r   
dress_codereasonformal_scoreinformal_score
confidence)clientchatcompletionscreatetext_promptchoicesmessager   strip
startswithreplacejsonloadsJSONDecodeErrorprint	Exceptionstr)r   responseoutput_textes       ?D:\xampp\htdocs\new-grp\engine\services\proctor\attire_check.pycheck_attirer2   (   s   *
;*11 #"(+??"-!#K\#K#K=N    
  2 
 
" &q)19??AA !!),, 	X%--i<<DDUBOOUUWWK	:k***# 	 	 	91===3"       	  	
 	
 	
(!,,,VV#0
 
 	
 	
 	
 	
 	
 	
	
sH   B8D  ;C C=C82C=3D  8C==D   
D:
%D5/D:5D:)osbase64r(   openair   dotenvr   getenvr   r   r"   r-   dictr2        r1   <module>r;      s    				               
")$
%
%		 	 	 8+
s +
t +
 +
 +
 +
 +
 +
r:   