mirror of
https://github.com/icereed/paperless-gpt.git
synced 2025-03-14 05:38:01 -05:00
feat: process multiple documents for auto-tagging and OCR
This commit is contained in:
parent
6e88a1b7bb
commit
7a4a0d6d72
1 changed files with 42 additions and 40 deletions
82
main.go
82
main.go
|
@ -375,27 +375,28 @@ func (app *App) processAutoTagDocuments() (int, error) {
|
||||||
|
|
||||||
log.Debugf("Found at least %d remaining documents with tag %s", len(documents), autoTag)
|
log.Debugf("Found at least %d remaining documents with tag %s", len(documents), autoTag)
|
||||||
|
|
||||||
documents = documents[:1] // Process only one document at a time
|
for _, document := range documents {
|
||||||
docLogger := documentLogger(documents[0].ID)
|
docLogger := documentLogger(document.ID)
|
||||||
docLogger.Info("Processing document for auto-tagging")
|
docLogger.Info("Processing document for auto-tagging")
|
||||||
|
|
||||||
suggestionRequest := GenerateSuggestionsRequest{
|
suggestionRequest := GenerateSuggestionsRequest{
|
||||||
Documents: documents,
|
Documents: []Document{document},
|
||||||
GenerateTitles: strings.ToLower(autoGenerateTitle) != "false",
|
GenerateTitles: strings.ToLower(autoGenerateTitle) != "false",
|
||||||
GenerateTags: strings.ToLower(autoGenerateTags) != "false",
|
GenerateTags: strings.ToLower(autoGenerateTags) != "false",
|
||||||
|
}
|
||||||
|
|
||||||
|
suggestions, err := app.generateDocumentSuggestions(ctx, suggestionRequest, docLogger)
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("error generating suggestions for document %d: %w", document.ID, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = app.Client.UpdateDocuments(ctx, suggestions, app.Database, false)
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("error updating document %d: %w", document.ID, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
docLogger.Info("Successfully processed document")
|
||||||
}
|
}
|
||||||
|
|
||||||
suggestions, err := app.generateDocumentSuggestions(ctx, suggestionRequest, docLogger)
|
|
||||||
if err != nil {
|
|
||||||
return 0, fmt.Errorf("error generating suggestions for document %d: %w", documents[0].ID, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = app.Client.UpdateDocuments(ctx, suggestions, app.Database, false)
|
|
||||||
if err != nil {
|
|
||||||
return 0, fmt.Errorf("error updating document %d: %w", documents[0].ID, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
docLogger.Info("Successfully processed document")
|
|
||||||
return len(documents), nil
|
return len(documents), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -415,29 +416,30 @@ func (app *App) processAutoOcrTagDocuments() (int, error) {
|
||||||
|
|
||||||
log.Debugf("Found at least %d remaining documents with tag %s", len(documents), autoOcrTag)
|
log.Debugf("Found at least %d remaining documents with tag %s", len(documents), autoOcrTag)
|
||||||
|
|
||||||
documents = documents[:1] // Process only one document at a time
|
for _, document := range documents {
|
||||||
docLogger := documentLogger(documents[0].ID)
|
docLogger := documentLogger(document.ID)
|
||||||
docLogger.Info("Processing document for OCR")
|
docLogger.Info("Processing document for OCR")
|
||||||
|
|
||||||
ocrContent, err := app.ProcessDocumentOCR(ctx, documents[0].ID)
|
ocrContent, err := app.ProcessDocumentOCR(ctx, document.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("error processing OCR for document %d: %w", documents[0].ID, err)
|
return 0, fmt.Errorf("error processing OCR for document %d: %w", document.ID, err)
|
||||||
|
}
|
||||||
|
docLogger.Debug("OCR processing completed")
|
||||||
|
|
||||||
|
err = app.Client.UpdateDocuments(ctx, []DocumentSuggestion{
|
||||||
|
{
|
||||||
|
ID: document.ID,
|
||||||
|
OriginalDocument: document,
|
||||||
|
SuggestedContent: ocrContent,
|
||||||
|
RemoveTags: []string{autoOcrTag},
|
||||||
|
},
|
||||||
|
}, app.Database, false)
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("error updating document %d after OCR: %w", document.ID, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
docLogger.Info("Successfully processed document OCR")
|
||||||
}
|
}
|
||||||
docLogger.Debug("OCR processing completed")
|
|
||||||
|
|
||||||
err = app.Client.UpdateDocuments(ctx, []DocumentSuggestion{
|
|
||||||
{
|
|
||||||
ID: documents[0].ID,
|
|
||||||
OriginalDocument: documents[0],
|
|
||||||
SuggestedContent: ocrContent,
|
|
||||||
RemoveTags: []string{autoOcrTag},
|
|
||||||
},
|
|
||||||
}, app.Database, false)
|
|
||||||
if err != nil {
|
|
||||||
return 0, fmt.Errorf("error updating document %d after OCR: %w", documents[0].ID, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
docLogger.Info("Successfully processed document OCR")
|
|
||||||
return 1, nil
|
return 1, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue