U
    JXLh                     @   sZ   d dl Z d dlmZ dZdZeedZd dl Z d dl Z dd Zdd	 Zd
d Zdd Z	dS )    N)OpenAIZ%hf_RwrpebXRyHAHIwBflkGrsqeAeFgoGcPYCuzsk-proj-O44Tus5LHWDwreXOqQOMjJqqKIVMrIYHNBoJSitbCH4OLdT5bDUp3Ey9n7qtt1zTsbwrUtHX6gT3BlbkFJLbzL1SHbiJDfiSin8Kyf--R9BfRQp4WTCa7kxGxQlZB-ALIqFlror4MCBBAcT5mc6k4a0T3PkA)api_keyc              	      s   t | dddd"}tt|}dd |D  W 5 Q R X  rF d |r~tdd	 |D  fd
dtdt D }ng }t | dddd}t|}|	| W 5 Q R X dS )z
    Deletes the first element (top-left cell) of a CSV file and adjusts
    the rest of the content so there are no blank cells left.

    Args:
        csv_file_path (str): Path to the CSV file.

    Returns:
        None
    r utf-8modenewlineencodingc                 S   s   g | ]}|D ]}|qqS  r   ).0rowcellr   r   E/home/ankuromar296_gmail_com/publish_blogs_ai/news/get_article_obj.py
<listcomp>   s       z(delete_first_element.<locals>.<listcomp>r   c                 s   s   | ]}t |V  qd S )N)len)r   r   r   r   r   	<genexpr>%   s     z'delete_first_element.<locals>.<genexpr>c                    s   g | ]} ||  qS r   r   )r   i	flat_datanum_colsr   r   r   &   s     wN)
openlistcsvreaderpopmaxranger   writer	writerows)csv_file_pathfiler   new_rowsr   r   r   r   delete_first_element   s    
"
r$   c                 C   s(   t jjj|d| dgd}|jd jjS )Nuser)rolecontent)modelmessagesr   )clientchatcompletionscreatechoicesmessager'   )promptr(   
completionr   r   r   
call_genai/   s    r2   c              
   C   sZ   t | dddd@}t|}|D ] }|r |d   W  5 Q R  S q W 5 Q R  dS Q R X dS )z
    Reads the first element (top-left cell) of a CSV file.

    Args:
        csv_file_path (str): Path to the CSV file.

    Returns:
        str: The first element of the CSV file, or None if file is empty.
    r   r   r   r   r   N)r   r   r   )r!   r"   r   r   r   r   r   read_first_element?   s    

r3   c           	      C   s   t | }t| d}d}d| d| }t||}td| d| krLdS d}td	| d
|}d|i}g }|| ||fS )Na  agriculture/forestry/farming news, precision agriculture, remote sensing, NDVI, satellite imagery, crop monitoring, yield estimation, soil moisture, irrigation advisory, farm management, agri-tech, climate-smart agriculture, sustainable agriculture, agri-input optimization, agricultural IoT, GPS mapping, weather forecasting, drought monitoring, land use mapping, pest detection, crop health, forestry monitoring, carbon sequestration, agroforestry, biomass estimation, drone mapping, smart farming, geospatial analytics, carbon credits, deforestation tracking, land degradation, crop insurance, agricultural subsidies, regenerative agriculture, organic farming, climate change, water resource management, AI in agriculture, ML for crop prediction, agricultural policy, smart irrigation, field scouting, weed detection, fertilizer advisory, farm automation, agronomy, agri-fintech, farm-to-fork traceability, agricultural extension, rural development, ESG in agriculture, remote field diagnostics, plant disease detection, agricultural marketplaces, agricultural data platforms, precision forestry, sustainable land management, government agri schemes, digital agriculture, food security, global food supply, agricultural exports, food price inflation, commodity markets, land monitoring, harvest forecastingzgpt-4.1-mini-2025-04-14zKOutput YES if the provided text is related to any of the following topics: z. Only answer YES OR NO. Text: zis relevantno)NNz%gpt-4o-mini-search-preview-2025-03-11z[I want to write an article on this topic in the context of agriculture/ farming/ forestry: zR Can you cover everything about this topic in 1000 words. Output only the content.body)r3   printr2   lowerappend)		file_pathmain_keywordZrelevant_keywordsr(   r0   Zis_relevantr'   Zcontent_objZall_contentsr   r   r   get_article_objP   s"    

 
r;   )
r   openair   Zhf2	model_keyr*   r$   r2   r3   r;   r   r   r   r   <module>   s   
 