File size: 2,461 Bytes
ff1f92b
 
 
 
ef8ef68
d108363
ff1f92b
d6141c6
ff1f92b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b3a4b6f
ff1f92b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92b9cf0
b3a4b6f
92b9cf0
 
ff1f92b
92b9cf0
 
 
 
 
 
 
 
 
504e625
ff1f92b
 
 
 
 
 
 
 
 
 
 
92b9cf0
 
 
 
ff1f92b
92b9cf0
ff1f92b
92b9cf0
 
 
 
 
 
 
 
 
ff1f92b
 
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import streamlit as st
from datetime import datetime
import pandas as pd
from pathlib import Path
import os
from pages.llm import create_vectorstore_and_store


st.set_page_config(
    page_title="Hochgeladene Dokumente",
    layout="wide",
    initial_sidebar_state="expanded",
)

make_button_smaller = """
        <style>
        .stbutton {
            width: 20px;
            height: 19px;
            }
        </style>
        """
st.markdown(make_button_smaller, unsafe_allow_html=True)
st.markdown("# Hochgeladene Dokumente")
st.sidebar.markdown("# Hochgeladene Dokumente")

field_names = ['Index', 'Titel', 'Hochladezeitpunkt']

FILES = []

def newIndex():
    lastIndex = len(FILES)
    newIndex = lastIndex + 1
    return newIndex

def generate_files():
    folder = './files'
    files = os.listdir(folder)
    for file in files:
        file_path = Path(folder, file)
        index = newIndex()
        title = file
        upload_time = os.path.getctime(Path(folder, file))
        upload_time = datetime.fromtimestamp(upload_time).strftime("%d.%m.%Y - %H:%M:%S")
        if os.path.isfile(file_path):
            file_info = {
                "Index": index,
                "Titel": title,
                "Hochladezeitpunkt": upload_time
            }
            FILES.append(file_info)
    return FILES

def delete_row_and_file(index):
    folder = './files'
    file_name = FILES[index]['Titel']
    file_path = Path(folder, file_name)

    # Delete the file
    try:
        os.remove(file_path)
        st.success("Datei erfolgreich gelöscht.")
    except FileNotFoundError:
        st.warning("Datei nicht gefunden.")

    # Drop the row from the DataFrame
    FILES.pop(index)
    create_vectorstore_and_store()

def display_table():
        hide_table_row_index = """ 
            <style>
            thead tr th:first-child {display:none}
            tbody th {display:none}
            </style>
            """
# Inject CSS with Markdown
        st.markdown(hide_table_row_index, unsafe_allow_html=True)

        # Display a static table
        table1 = pd.DataFrame.from_dict(generate_files())
        table = st.table(table1)
        return table1

    #.style.format(subset=['Titel']))

col1, col2 = st.columns([0.7, 0.3])
with col1:
    display_table()

with col2:
    for index in range(len(FILES)):
        delete_button = st.button("Löschen", key = index)
        if delete_button:
            delete_row_and_file(index)