Matze420's picture
Update pages/table.py
0275424
raw
history blame
2.14 kB
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()