File size: 2,137 Bytes
ff1f92b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0275424
ff1f92b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0275424
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
import streamlit as st
from transformers import pipeline
from datetime import datetime
import pandas as pd
from pathlib import Path
import csv
import os

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_entry(key):
    folder = './files'
    file = FILES[key]['Titel']
    os.remove(Path(folder, file))
    FILES.pop(key)
    generate_files()


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
col1, col2 = st.columns([5, 1])
with col1:
    table1 = pd.DataFrame.from_dict(generate_files())
    st.table(table1.style.format(subset=['Titel']))
with col2:
    key = 0
    for entry in FILES:
        st.button('Löschen', on_click = delete_entry(key), key = key, use_container_width = True)
        key = key + 1

display_table()