
    x5hk              	           d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
 e
j                  Ze
j                  Ze
j                  Zddededed	efd
Zy)    N)Image)BytesIO)STATIC_PATH)settingsdesclayoutstyleimage_numberc           
         g }t        |      D ]  }	 |  d| d| }t        d|        t        j                  t        dt
        id|fdd      }t        d	|j                          |j                  d
k7  rt        d|j                         |j                         j                  d      d   j                  d      }|st        d      t        j                  |      }	|	j                  d
k7  rt        d      t        t        j                               }
d|dz    d|
 d}t        j                  j                  t         |      }t#        j$                  t'        |	j(                              }|j+                  |       t        d|        t,         d| }|j/                  |        |S # t        $ r(}t        d|dz    dt1        |              Y d}~d}~ww xY w)a  
    Generate and save multiple images based on description, layout, and style using Ideogram API.
    
    Args:
        desc (str): Description of the content.
        layout (str): Layout keyword to include in the prompt.
        style (str): Style keyword to include in the prompt.
        image_number (int): Number of images to generate (default is 1).
    
    Returns:
        List[str]: URLs of the saved images.
    z	. Style: z
, layout: zGenerating image with prompt: zApi-KeyN)N1x1)promptaspect_ratio)headersfilesz%Received response from Ideogram API:    zIdeogram API error: datar   urlz&No image URL returned by Ideogram API.z'Failed to download the generated image.image_   _z.pngzSaved image at: zstatic/generated_images/zError generating image z: )rangeprintrequestspostIDEOGRAM_URLIDEOGRAM_API_KEYstatus_code	Exceptiontextjsongetinttimeospathjoinr   r   openr   contentsaveBASE_URLappendstr)r   r   r	   r
   
image_urlsiimage_promptresponsegeneration_urlimage_response	timestampimage_filenameimage_filepathimgfull_image_urles                   F/var/www/html/hubwallet-dev/src/menu_design/apps/AI_chat/controller.pygenerate_imager:      s    J<  0?/	?"V9UG:fXFL2<.AB  }}/  $\2$1	H 9(:N:N9OPQ ##s*"6x}}o FGG &]]_008;??FN! HII &\\.9N))S0 IJJ DIIK(I%acU!I;d;NWW\\+~FN**W^%;%;<=CHH^$$^$456 !)z)A.AQRNn-[0?d   	?+AE7"SVH=>>	?s   FF33	G$<GG$)r   )r$   r#   r   PILr   ior    src.menu_design.core.menu_designr   src.utils.settingsr   r   r   r*   r,   r"   r:        r9   <module>rA      sf    	     8 ' ,, $$ A Ac A# AS Ar@   