import streamlit as st from datetime import datetime import pandas as pd from pathlib import Path import os from pages.bot import create_vectorstore_and_store st.set_page_config( page_title="Hochgeladene Dokumente", layout="wide", initial_sidebar_state="expanded", ) make_button_smaller = """ """ 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 = """ """ # 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)