Upload 2 files
Browse files- pages/table.py +28 -24
- pages/upload.py +2 -8
pages/table.py
CHANGED
@@ -1,12 +1,9 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import pipeline
|
3 |
from datetime import datetime
|
4 |
import pandas as pd
|
5 |
from pathlib import Path
|
6 |
import os
|
7 |
-
from huggingface_hub import login
|
8 |
|
9 |
-
login(token = "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")
|
10 |
|
11 |
st.set_page_config(
|
12 |
page_title="Hochgeladene Dokumente",
|
@@ -36,7 +33,7 @@ def newIndex():
|
|
36 |
return newIndex
|
37 |
|
38 |
def generate_files():
|
39 |
-
folder = '
|
40 |
files = os.listdir(folder)
|
41 |
for file in files:
|
42 |
file_path = Path(folder, file)
|
@@ -53,13 +50,20 @@ def generate_files():
|
|
53 |
FILES.append(file_info)
|
54 |
return FILES
|
55 |
|
56 |
-
def
|
57 |
-
folder = '
|
58 |
-
|
59 |
-
|
60 |
-
FILES.pop(key)
|
61 |
-
generate_files()
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
def display_table():
|
65 |
hide_table_row_index = """
|
@@ -68,24 +72,24 @@ def display_table():
|
|
68 |
tbody th {display:none}
|
69 |
</style>
|
70 |
"""
|
71 |
-
|
72 |
-
|
73 |
# Inject CSS with Markdown
|
74 |
st.markdown(hide_table_row_index, unsafe_allow_html=True)
|
75 |
|
76 |
-
# Display a static table
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
st.table(table1.style.format(subset=['Titel']))
|
81 |
-
with col2:
|
82 |
-
key = 0
|
83 |
-
for entry in FILES:
|
84 |
-
# st.button('Löschen', on_click = delete_entry(key), key = key, use_container_width = True)
|
85 |
-
st.button('Löschen', key = key, use_container_width = True)
|
86 |
-
key = key + 1
|
87 |
|
88 |
-
|
89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
|
91 |
|
|
|
1 |
import streamlit as st
|
|
|
2 |
from datetime import datetime
|
3 |
import pandas as pd
|
4 |
from pathlib import Path
|
5 |
import os
|
|
|
6 |
|
|
|
7 |
|
8 |
st.set_page_config(
|
9 |
page_title="Hochgeladene Dokumente",
|
|
|
33 |
return newIndex
|
34 |
|
35 |
def generate_files():
|
36 |
+
folder = 'C:/Users/keckm/Documents/GitHub/Streamlit/files'
|
37 |
files = os.listdir(folder)
|
38 |
for file in files:
|
39 |
file_path = Path(folder, file)
|
|
|
50 |
FILES.append(file_info)
|
51 |
return FILES
|
52 |
|
53 |
+
def delete_row_and_file(index):
|
54 |
+
folder = 'C:/Users/keckm/Documents/GitHub/Streamlit/files'
|
55 |
+
file_name = FILES[index]['Titel']
|
56 |
+
file_path = Path(folder, file_name)
|
|
|
|
|
57 |
|
58 |
+
# Delete the file
|
59 |
+
try:
|
60 |
+
os.remove(file_path)
|
61 |
+
st.success("Datei erfolgreich gelöscht.")
|
62 |
+
except FileNotFoundError:
|
63 |
+
st.warning("Datei nicht gefunden.")
|
64 |
+
|
65 |
+
# Drop the row from the DataFrame
|
66 |
+
FILES.pop(index)
|
67 |
|
68 |
def display_table():
|
69 |
hide_table_row_index = """
|
|
|
72 |
tbody th {display:none}
|
73 |
</style>
|
74 |
"""
|
|
|
|
|
75 |
# Inject CSS with Markdown
|
76 |
st.markdown(hide_table_row_index, unsafe_allow_html=True)
|
77 |
|
78 |
+
# Display a static table
|
79 |
+
table1 = pd.DataFrame.from_dict(generate_files())
|
80 |
+
table = st.table(table1)
|
81 |
+
return table1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
+
#.style.format(subset=['Titel']))
|
84 |
|
85 |
+
col1, col2 = st.columns([0.7, 0.3])
|
86 |
+
with col1:
|
87 |
+
display_table()
|
88 |
+
|
89 |
+
with col2:
|
90 |
+
for index in range(len(FILES)):
|
91 |
+
delete_button = st.button("Löschen", key = index)
|
92 |
+
if delete_button:
|
93 |
+
delete_row_and_file(index)
|
94 |
|
95 |
|
pages/upload.py
CHANGED
@@ -2,17 +2,12 @@ import streamlit as st
|
|
2 |
from pathlib import Path
|
3 |
from pages.table import generate_files
|
4 |
from pages.bot import create_vectorstore_and_store
|
5 |
-
|
6 |
-
st.set_page_config(
|
7 |
-
page_title="Dokumentenupload",
|
8 |
-
layout="wide",
|
9 |
-
initial_sidebar_state="expanded",
|
10 |
-
)
|
11 |
|
12 |
st.markdown("# Dokumentenupload")
|
13 |
st.sidebar.markdown("# Dokumentenupload")
|
14 |
|
15 |
-
UPLOAD_FOLDER = '
|
16 |
|
17 |
def save_file(uploaded_file):
|
18 |
save_folder = UPLOAD_FOLDER
|
@@ -22,7 +17,6 @@ def save_file(uploaded_file):
|
|
22 |
if save_path.exists():
|
23 |
st.success(f'Dokument {uploaded_file.name} wurde erfolgreich auf den Server hochgeladen.')
|
24 |
create_vectorstore_and_store()
|
25 |
-
|
26 |
# file uploader
|
27 |
with st.form('upload_form'):
|
28 |
uploaded_file = st.file_uploader("Wählen Sie eine Datei aus.", type = [ ".pdf"])
|
|
|
2 |
from pathlib import Path
|
3 |
from pages.table import generate_files
|
4 |
from pages.bot import create_vectorstore_and_store
|
5 |
+
#from bot.py import *
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
st.markdown("# Dokumentenupload")
|
8 |
st.sidebar.markdown("# Dokumentenupload")
|
9 |
|
10 |
+
UPLOAD_FOLDER = 'C:/Users/keckm/Documents/GitHub/Streamlit/files' # Ordner für Dateiablage
|
11 |
|
12 |
def save_file(uploaded_file):
|
13 |
save_folder = UPLOAD_FOLDER
|
|
|
17 |
if save_path.exists():
|
18 |
st.success(f'Dokument {uploaded_file.name} wurde erfolgreich auf den Server hochgeladen.')
|
19 |
create_vectorstore_and_store()
|
|
|
20 |
# file uploader
|
21 |
with st.form('upload_form'):
|
22 |
uploaded_file = st.file_uploader("Wählen Sie eine Datei aus.", type = [ ".pdf"])
|