mirror of
https://github.com/icereed/paperless-gpt.git
synced 2025-03-13 21:28:02 -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
26
main.go
26
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)
|
||||
|
||||
documents = documents[:1] // Process only one document at a time
|
||||
docLogger := documentLogger(documents[0].ID)
|
||||
for _, document := range documents {
|
||||
docLogger := documentLogger(document.ID)
|
||||
docLogger.Info("Processing document for auto-tagging")
|
||||
|
||||
suggestionRequest := GenerateSuggestionsRequest{
|
||||
Documents: documents,
|
||||
Documents: []Document{document},
|
||||
GenerateTitles: strings.ToLower(autoGenerateTitle) != "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", documents[0].ID, err)
|
||||
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", documents[0].ID, err)
|
||||
return 0, fmt.Errorf("error updating document %d: %w", document.ID, err)
|
||||
}
|
||||
|
||||
docLogger.Info("Successfully processed document")
|
||||
}
|
||||
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)
|
||||
|
||||
documents = documents[:1] // Process only one document at a time
|
||||
docLogger := documentLogger(documents[0].ID)
|
||||
for _, document := range documents {
|
||||
docLogger := documentLogger(document.ID)
|
||||
docLogger.Info("Processing document for OCR")
|
||||
|
||||
ocrContent, err := app.ProcessDocumentOCR(ctx, documents[0].ID)
|
||||
ocrContent, err := app.ProcessDocumentOCR(ctx, document.ID)
|
||||
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: documents[0].ID,
|
||||
OriginalDocument: documents[0],
|
||||
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", documents[0].ID, err)
|
||||
return 0, fmt.Errorf("error updating document %d after OCR: %w", document.ID, err)
|
||||
}
|
||||
|
||||
docLogger.Info("Successfully processed document OCR")
|
||||
}
|
||||
return 1, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue