-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload_files.py
53 lines (46 loc) · 1.61 KB
/
upload_files.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import streamlit as st
import psycopg2
from psycopg2 import sql
# Set the page configuration first
st.set_page_config(
page_title="RAG",
page_icon="/users/francksidi/downloads/logo.png", # Ensure the icon path is correct
layout="wide",
)
# Display the logo using st.image
st.image("/users/francksidi/downloads/logo.png", use_column_width=True)
# Input for the database IP
db_ip = st.sidebar.text_input('Database IP', '')
if db_ip:
# Database connection
conn = psycopg2.connect(
user="postgres",
password="admin",
host=db_ip,
port=5432,
database="postgres"
)
# Input for the directory path
directory_path = st.text_input('Enter the directory path to process files:', '')
# Input for dataset name
dataset_name = st.text_input('Enter dataset name:', '')
if directory_path and dataset_name:
# Button to trigger the processing
if st.button('Process Files'):
with conn.cursor() as cur:
try:
# Call the pl-python3u function
cur.execute(
"""
SELECT process_files_in_directory(%s, %s);
""", (dataset_name, directory_path)
)
conn.commit()
st.success("Files processed and data inserted successfully.")
except Exception as e:
st.error(f"An error occurred: {e}")
finally:
cur.close()
conn.close()
else:
st.warning("Please enter the database IP to connect.")