a
    fM                     @   s.   d dl Z d dlZd dlmZ G dd dZdS )    N)load_dotenvc                   @   sL   e Zd ZdZdZdZdZedg feee	dddZ
eeed	d
dZdS )ContentEvaluator<   iN)	image_urlrequired_tagrequirementsc              
   C   s   d |}dtj d}t|dkr2| d| nd}dtj d| d}t| t  tjt	j
d	d
}dd|dd| dddgdg}z<d|dd}	|jjjf i |	}
|
jd jj}t||W S  t y } zd| W  Y d }~S d }~0 0 d S )Nz
- zThe brand requested the following requirements. If any of the following requirements are very clearly not met, return a score of .r    a  
You are a simulated AI photo reviewer who assesses UGC content for brands.
Based the provided photo and the below criteria, provide a hypothetical score out of 100, understanding that this is an estimation and not a definitive assessment. 

A few notes: 
- The scoring scale should follow a grade-school approach, where 90-100 is an A, 80-89 is a B, 70-79 is a C, 60-69 is a D, and 0-59 is an F. Your should only include a number and not a letter grade. However, keep the grade scale in mind when determining the score.
- It's okay if the content contains text, especially if the text adds to the photo.

The following qualities are not requirements. Photos with these qualities should receive higher scores, but lacking these qualities should not result in a negative score.
The brand would prefer if the photo is:
- Clear
- High-quality
- Well-lit
- In-focus
- Well-composed
- Visually appealing
 
Remember negative scores serve as error codes. Do not return a negative score unless you are 100% certain that there is an issue with the content. If you return a negative score, ensure it is the correct error code.

If offensive language is found, return a score of z.

a  

In your response, please include the following.
Score: a number out of 100, where 100 is the best possible score
Pros: Up to three, one-to-four word bullet points of "pros"
Cons: Up to three, one-to-four word bullet points of "cons"
Text: A list of all text found in the image. If no text is found, return an empty list.

Do not mention profanity in the pros or cons. Do not include any additional information.
ZOPENAI_API_KEY)api_keyusertext)typer   r   low)urldetail)r   r   )rolecontentzgpt-4-vision-previewi   )modelmessagesZ
max_tokenszError in processing request: )joinr   *ADDITIONAL_REQUIREMENTS_NOT_MET_ERROR_CODElenPROFANITY_DETECTED_ERROR_CODEprintr   openaiZOpenAIosenvirongetZchatZcompletionscreatechoicesmessager   extract_info_from_response	Exception)r   r   r	   Zrequirements_textZ
intro_textZfull_requirements_textprompt_textclientZprompt_messagesparamsresultZresult_contente r*   B/var/www/html/python-backend/backend/services/content_evaluator.pyscore_content   s>    
zContentEvaluator.score_content)responser   c                 C   s   g }g }g }d }|  d}|  d}| |td |  }|d dkr^t|dd  d }nt|}|  d}	|  d}
| |	td |
  }|d}|  d}|  d	}| |td |  }|d}|  d	}|dkr| |td	 d   }|r||vrtj}||||d
S )NzScore:zPros:r   -   r   zCons:z
-zText:)scoreprosconsZtexts)findr   stripintsplitr   TAG_NOT_FOUND_ERROR_CODE)r-   r   r1   r2   Z	text_listr0   Zscore_start_indexZscore_end_indexZ
score_textZpros_start_indexZpros_end_indexZ	pros_textZcons_start_indexZcons_end_indexZ	cons_textZtext_start_indexZall_text_strr*   r*   r+   r#   Z   s2    









z+ContentEvaluator.extract_info_from_response)__name__
__module____qualname__MINIMUM_SCORE_THRESHOLDr7   r   r   staticmethodstrlistr,   r#   r*   r*   r*   r+   r      s   Gr   )r   r   dotenvr   r   r*   r*   r*   r+   <module>   s   