Update utils.py
Browse files
utils.py
CHANGED
@@ -471,47 +471,6 @@ def load_split_to_original_mapping(directory="chroma/kkg", filename="mapping.pkl
|
|
471 |
|
472 |
|
473 |
|
474 |
-
|
475 |
-
|
476 |
-
"""
|
477 |
-
|
478 |
-
def save_vectorstore(vectorstore, directory="chroma/kkg", splits_filename="splits_and_metadata.pkl", vectorstore_filename="vectorstore.pkl"):
|
479 |
-
# Erstellen des Verzeichnisses, falls es nicht existiert
|
480 |
-
if not os.path.exists(directory):
|
481 |
-
os.makedirs(directory)
|
482 |
-
|
483 |
-
# Speichern der Splits und Metadaten
|
484 |
-
splits_filepath = os.path.join(directory, splits_filename)
|
485 |
-
with open(splits_filepath, "wb") as f:
|
486 |
-
pickle.dump((vectorstore.documents, SPLIT_TO_ORIGINAL_MAPPING), f)
|
487 |
-
|
488 |
-
# Speichern des Vektorstores (ohne die SQLite-Verbindung)
|
489 |
-
vectorstore_filepath = os.path.join(directory, vectorstore_filename)
|
490 |
-
with open(vectorstore_filepath, "wb") as f:
|
491 |
-
pickle.dump(vectorstore, f)
|
492 |
-
|
493 |
-
# Hochladen der gespeicherten Dateien zum Hugging Face Space
|
494 |
-
upload_file_to_huggingface(splits_filepath, f"{directory}/{splits_filename}")
|
495 |
-
upload_file_to_huggingface(vectorstore_filepath, f"{directory}/{vectorstore_filename}")
|
496 |
-
|
497 |
-
def load_vectorstore(directory="chroma/kkg", splits_filename="splits_and_metadata.pkl", vectorstore_filename="vectorstore.pkl"):
|
498 |
-
# Laden der Splits und Metadaten
|
499 |
-
splits_filepath = os.path.join(directory, splits_filename)
|
500 |
-
vectorstore_filepath = os.path.join(directory, vectorstore_filename)
|
501 |
-
|
502 |
-
if os.path.exists(splits_filepath) and os.path.exists(vectorstore_filepath):
|
503 |
-
with open(splits_filepath, "rb") as f:
|
504 |
-
documents, SPLIT_TO_ORIGINAL_MAPPING = pickle.load(f)
|
505 |
-
|
506 |
-
with open(vectorstore_filepath, "rb") as f:
|
507 |
-
vectorstore = pickle.load(f)
|
508 |
-
vectorstore.documents = documents # Setze die Dokumente im Vektorstore
|
509 |
-
return vectorstore, SPLIT_TO_ORIGINAL_MAPPING
|
510 |
-
return None, None
|
511 |
-
"""
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
# Beispiel-Upload-Funktion
|
516 |
def upload_file_to_huggingface(file_path, upload_path):
|
517 |
api.upload_file(
|
@@ -769,29 +728,32 @@ def download_link(doc):
|
|
769 |
|
770 |
|
771 |
|
|
|
|
|
|
|
|
|
|
|
772 |
def display_files():
|
773 |
files = os.listdir(DOCS_DIR_PDF)
|
774 |
files_table = "<table style='width:100%; border-collapse: collapse;'>"
|
775 |
-
files_table += "<tr style='background-color: #930BBA; color: white; font-weight: bold; font-size: larger;'><th>Dateiname
|
776 |
for i, file in enumerate(files):
|
777 |
file_path = os.path.join(DOCS_DIR_PDF, file)
|
778 |
file_size = os.path.getsize(file_path) / 1024 # Größe in KB
|
779 |
row_color = "#4f4f4f" if i % 2 == 0 else "#3a3a3a" # Wechselnde Zeilenfarben
|
780 |
files_table += f"<tr style='background-color: {row_color}; border-bottom: 1px solid #ddd;'>"
|
781 |
-
files_table += f"<td><b>{download_link(file)}</b></td>"
|
782 |
-
files_table += f"<td>{file_size:.2f}</td></tr>"
|
783 |
files_table += "</table>"
|
784 |
|
785 |
files = os.listdir(DOCS_DIR_WORD)
|
786 |
files_table += "<table style='width:100%; border-collapse: collapse;'>"
|
787 |
-
files_table += "<tr style='background-color: #930BBA; color: white; font-weight: bold; font-size: larger;'><th>Dateiname
|
788 |
for i, file in enumerate(files):
|
789 |
file_path = os.path.join(DOCS_DIR_WORD, file)
|
790 |
file_size = os.path.getsize(file_path) / 1024 # Größe in KB
|
791 |
row_color = "#4f4f4f" if i % 2 == 0 else "#3a3a3a" # Wechselnde Zeilenfarben
|
792 |
files_table += f"<tr style='background-color: {row_color}; border-bottom: 1px solid #ddd;'>"
|
793 |
-
files_table += f"<td><b>{download_link(file)}</b></td>"
|
794 |
-
files_table += f"<td>{file_size:.2f}</td></tr>"
|
795 |
files_table += "</table>"
|
796 |
return files_table
|
797 |
|
|
|
471 |
|
472 |
|
473 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
474 |
# Beispiel-Upload-Funktion
|
475 |
def upload_file_to_huggingface(file_path, upload_path):
|
476 |
api.upload_file(
|
|
|
728 |
|
729 |
|
730 |
|
731 |
+
|
732 |
+
|
733 |
+
#################################################
|
734 |
+
#File Liste beim Tab für File-Upload schön darstellen
|
735 |
+
#################################################
|
736 |
def display_files():
|
737 |
files = os.listdir(DOCS_DIR_PDF)
|
738 |
files_table = "<table style='width:100%; border-collapse: collapse;'>"
|
739 |
+
files_table += "<tr style='background-color: #930BBA; color: white; font-weight: bold; font-size: larger;'><th>Dateiname - PDF-Ordner</th></tr>"
|
740 |
for i, file in enumerate(files):
|
741 |
file_path = os.path.join(DOCS_DIR_PDF, file)
|
742 |
file_size = os.path.getsize(file_path) / 1024 # Größe in KB
|
743 |
row_color = "#4f4f4f" if i % 2 == 0 else "#3a3a3a" # Wechselnde Zeilenfarben
|
744 |
files_table += f"<tr style='background-color: {row_color}; border-bottom: 1px solid #ddd;'>"
|
745 |
+
files_table += f"<td><b>{download_link(file)}</b></td></tr>"
|
|
|
746 |
files_table += "</table>"
|
747 |
|
748 |
files = os.listdir(DOCS_DIR_WORD)
|
749 |
files_table += "<table style='width:100%; border-collapse: collapse;'>"
|
750 |
+
files_table += "<tr style='background-color: #930BBA; color: white; font-weight: bold; font-size: larger;'><th>Dateiname - Word-Ordner</th></tr>"
|
751 |
for i, file in enumerate(files):
|
752 |
file_path = os.path.join(DOCS_DIR_WORD, file)
|
753 |
file_size = os.path.getsize(file_path) / 1024 # Größe in KB
|
754 |
row_color = "#4f4f4f" if i % 2 == 0 else "#3a3a3a" # Wechselnde Zeilenfarben
|
755 |
files_table += f"<tr style='background-color: {row_color}; border-bottom: 1px solid #ddd;'>"
|
756 |
+
files_table += f"<td><b>{download_link(file)}</b></td></tr>"
|
|
|
757 |
files_table += "</table>"
|
758 |
return files_table
|
759 |
|