o
    Yf                     @   sP   d dl Z d dlZd dlZd dlZddlmZmZm	Z	m
Z
mZ dd Zdd ZdS )    N   )	db_dbnamedb_userdb_passworddb_hostdb_portc                 C   s   |dkr!t | ddd}| W  d   S 1 sw   Y  dS t | d}dt| d W  d   S 1 s>w   Y  dS )z7Read and convert image files to base64-encoded strings.svgrzutf-8)encodingNrbzdata:image/jpeg;base64,)openreadbase64	b64encodedecode)	file_path	file_typefile r   :/Users/putuwistika/Documents/BELAJAR/HYDRA/utils/common.pyreplace_image   s   $$r   c              
   C   s   zcz7t jtttttd}| }||  |	 }dd |j
D }tj||d}|W W |r1|  |r8|  S S  t jyc } ztd|  W Y d }~W |rU|  |r]|  d S d S d }~ww |rj|  |rq|  w w )N)Zdbnameuserpasswordhostportc                 S   s   g | ]}|d  qS )r   r   ).0descr   r   r   
<listcomp>   s    zload_data.<locals>.<listcomp>)columnsz Error connecting to PostgreSQL: )psycopg2connectr   r   r   r   r   cursorexecutefetchalldescriptionpd	DataFramecloseErrorsterror)query
connectionr!   recordsr   dfer   r   r   	load_data   sD   


r0   )r   r   	streamlitr)   pandasr%   credentialsr   r   r   r   r   r   r0   r   r   r   r   <module>   s    	