A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
write classifier model to temporary file before copying to final location
jonaswinklera3dae02cfbcd
diff --git a/src/documents/classifier.py b/src/documents/classifier.pyindex 2895c788a..36e906350 100644--- a/src/documents/classifier.py+++ b/src/documents/classifier.py@@ -3,6 +3,7 @@ import loggingimport osimport pickleimport re+import shutilfrom django.conf import settings@@ -96,7 +97,10 @@ class DocumentClassifier(object):raise ClassifierModelCorruptError()def save(self):- with open(settings.MODEL_FILE, "wb") as f:+ target_file = settings.MODEL_FILE+ target_file_temp = settings.MODEL_FILE + ".part"++ with open(target_file_temp, "wb") as f:pickle.dump(self.FORMAT_VERSION, f)pickle.dump(self.data_hash, f)pickle.dump(self.data_vectorizer, f)@@ -107,6 +111,10 @@ class DocumentClassifier(object):pickle.dump(self.correspondent_classifier, f)pickle.dump(self.document_type_classifier, f)+ if os.path.isfile(target_file):+ os.unlink(target_file)+ shutil.move(target_file_temp, target_file)+def train(self):data = list()