
    Ŕi              	       6    d Z ddlZddlmZ d	dedededefdZy)
zO
Image generation service using Replicate (black-forest-labs/flux-2-klein-4b).
    N)loggerpromptaspect_ratio
resolutionreturnc                   K   	 t        j                  d| d| d| d       t        j                  d| g d|ddd	d
       d{   }|r5t	        |d   j
                        }t        j                  d|        |ddS t        j                  d       dddS 7 U# t        $ r0}t        j                  d|        t	        |      ddcY d}~S d}~ww xY ww)aP  Generate an image using Replicate's flux-2-klein-4b model.

    Args:
        prompt: Text description of the image to generate.
        aspect_ratio: Aspect ratio (e.g. "1:1", "16:9", "4:3").
        resolution: Output resolution ("1K", "2K", "4K").

    Returns:
        dict with "url" key on success, or "error" key on failure.
    z![ImageService] Generating image: z (z, )z!black-forest-labs/flux-2-klein-4bFjpg_   1)r   imagesgo_fastr   output_formatoutput_qualityoutput_megapixels)inputNr   z [ImageService] Image generated: T)urlsuccessz/[ImageService] No image returned from Replicatez)No image was generated. Please try again.)errorr   z'[ImageService] Error generating image: )	r   info	replicate	async_runstrr   warning	Exceptionr   )r   r   r   outputr   es         L/Users/thippareddysaicharanreddy/Desktop/agent_all/services/image_service.pygenerate_imager   	   s     &37zL>QST^S__`ab !**/   ,!&"$%(
 
 fQimm$CKK:3%@A400HIDQVWW'
*  3>qcBCQE223sS   CAB B:B  CB CB 	C&%CCCCC)z1:11K)__doc__r   logurur   r   dictr        r   <module>r&      s4     13 13C 13S 13\` 13r%   