
    Z|h                         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y)
    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           	      b   	 t         j                  j                  j                  dddt        dddd|  idgd	gd
d      }|j
                  d   j                  j                  j                         }|j                  d      r0|j                  dd      j                  dd      j                         }	 t        j                  |      S # t        j                  $ r}t        d|       d|dcY d }~S d }~ww xY w# t        $ r(}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       ?E:\xampp\htdocs\new-grp\engine\services\proctor\attire_check.pycheck_attirer2   (   sH   *
;;**11 #"(+?"-!%<\N#K=N  
  2 
" &&q)1199??A !!),%--i<DDUBOUUWK	::k**## 	91=3" 	  	
(!,V#0
 	
	
sH   B4C= 7C C:C5/C:0C= 5C::C= =	D.D)#D.)D.)osbase64r(   openair   dotenvr   getenvr   r   r"   r-   dictr2        r1   <module>r;      sP    	     
"))$
%		 8+
s +
t +
r:   