Update utils.py
Browse files
utils.py
CHANGED
|
@@ -397,23 +397,24 @@ def document_storage_chroma(splits):
|
|
| 397 |
|
| 398 |
########################################################
|
| 399 |
#Splits für den Vektorstore speichern - bzw. laden
|
| 400 |
-
def
|
| 401 |
# Erstellen des Verzeichnisses, falls es nicht existiert
|
| 402 |
if not os.path.exists(directory):
|
| 403 |
os.makedirs(directory)
|
| 404 |
|
| 405 |
-
#
|
| 406 |
filepath = os.path.join(directory, filename)
|
| 407 |
-
|
| 408 |
-
# Speichern der Splits und Metadaten in der Datei
|
| 409 |
with open(filepath, "wb") as f:
|
| 410 |
pickle.dump(splits, f)
|
|
|
|
|
|
|
|
|
|
| 411 |
|
| 412 |
-
def
|
| 413 |
# Vollständigen Pfad zur Datei erstellen
|
| 414 |
filepath = os.path.join(directory, filename)
|
| 415 |
|
| 416 |
-
# Laden der Splits
|
| 417 |
if os.path.exists(filepath):
|
| 418 |
with open(filepath, "rb") as f:
|
| 419 |
return pickle.load(f)
|
|
@@ -429,36 +430,35 @@ def load_vectorstore():
|
|
| 429 |
return document_storage_chroma(PREPROCESSED_SPLITS)
|
| 430 |
return None
|
| 431 |
|
|
|
|
| 432 |
#################################
|
| 433 |
#das Mapping der orginal-Splits und der preprocessed Splits speichern
|
| 434 |
-
def save_split_to_original_mapping(mapping, directory="chroma/kkg",
|
| 435 |
# Erstellen des Verzeichnisses, falls es nicht existiert
|
| 436 |
if not os.path.exists(directory):
|
| 437 |
os.makedirs(directory)
|
| 438 |
|
| 439 |
# Speichern des Mappings
|
| 440 |
-
|
| 441 |
-
with open(
|
| 442 |
pickle.dump(mapping, f)
|
| 443 |
|
| 444 |
# Hochladen der Mapping-Datei zum Hugging Face Space
|
| 445 |
-
upload_file_to_huggingface(
|
| 446 |
-
|
| 447 |
|
| 448 |
-
def load_split_to_original_mapping(directory="chroma/kkg",
|
| 449 |
-
#
|
| 450 |
-
|
| 451 |
|
| 452 |
-
|
| 453 |
-
|
|
|
|
| 454 |
return pickle.load(f)
|
| 455 |
return None
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
-
|
| 461 |
-
|
| 462 |
|
| 463 |
|
| 464 |
"""
|
|
|
|
| 397 |
|
| 398 |
########################################################
|
| 399 |
#Splits für den Vektorstore speichern - bzw. laden
|
| 400 |
+
def save_splits(splits, directory="chroma/kkg", filename="splits.pkl"):
|
| 401 |
# Erstellen des Verzeichnisses, falls es nicht existiert
|
| 402 |
if not os.path.exists(directory):
|
| 403 |
os.makedirs(directory)
|
| 404 |
|
| 405 |
+
# Speichern der Splits
|
| 406 |
filepath = os.path.join(directory, filename)
|
|
|
|
|
|
|
| 407 |
with open(filepath, "wb") as f:
|
| 408 |
pickle.dump(splits, f)
|
| 409 |
+
|
| 410 |
+
# Hochladen der Splits-Datei zum Hugging Face Space
|
| 411 |
+
upload_file_to_huggingface(filepath, f"{directory}/{filename}")
|
| 412 |
|
| 413 |
+
def load_splits(directory="chroma/kkg", filename="splits.pkl"):
|
| 414 |
# Vollständigen Pfad zur Datei erstellen
|
| 415 |
filepath = os.path.join(directory, filename)
|
| 416 |
|
| 417 |
+
# Laden der Splits aus der Datei
|
| 418 |
if os.path.exists(filepath):
|
| 419 |
with open(filepath, "rb") as f:
|
| 420 |
return pickle.load(f)
|
|
|
|
| 430 |
return document_storage_chroma(PREPROCESSED_SPLITS)
|
| 431 |
return None
|
| 432 |
|
| 433 |
+
|
| 434 |
#################################
|
| 435 |
#das Mapping der orginal-Splits und der preprocessed Splits speichern
|
| 436 |
+
def save_split_to_original_mapping(mapping, directory="chroma/kkg", filename="mapping.pkl"):
|
| 437 |
# Erstellen des Verzeichnisses, falls es nicht existiert
|
| 438 |
if not os.path.exists(directory):
|
| 439 |
os.makedirs(directory)
|
| 440 |
|
| 441 |
# Speichern des Mappings
|
| 442 |
+
filepath = os.path.join(directory, filename)
|
| 443 |
+
with open(filepath, "wb") as f:
|
| 444 |
pickle.dump(mapping, f)
|
| 445 |
|
| 446 |
# Hochladen der Mapping-Datei zum Hugging Face Space
|
| 447 |
+
upload_file_to_huggingface(filepath, f"{directory}/{filename}")
|
|
|
|
| 448 |
|
| 449 |
+
def load_split_to_original_mapping(directory="chroma/kkg", filename="mapping.pkl"):
|
| 450 |
+
# Vollständigen Pfad zur Datei erstellen
|
| 451 |
+
filepath = os.path.join(directory, filename)
|
| 452 |
|
| 453 |
+
# Laden des Mappings aus der Datei
|
| 454 |
+
if os.path.exists(filepath):
|
| 455 |
+
with open(filepath, "rb") as f:
|
| 456 |
return pickle.load(f)
|
| 457 |
return None
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
|
|
|
|
|
|
| 462 |
|
| 463 |
|
| 464 |
"""
|