Skip to content

Commit

Permalink
refactor: improve OCR pipeline initialization
Browse files Browse the repository at this point in the history
Co-Authored-By: ben <ben@prologe.io>
  • Loading branch information
devin-ai-integration[bot] and benjaminshafii committed Feb 14, 2025
1 parent 7d1c2b6 commit 15a0b72
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
14 changes: 0 additions & 14 deletions packages/web/app/api/ocr/init/route.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1 @@
import { processOCRForInvoicesAndAdmin } from '@/lib/ocr/pipeline';

// Initialize the OCR pipeline when this route is first accessed
let initialized = false;

export async function GET() {
if (!initialized) {
initialized = true;
// Start the OCR pipeline
setInterval(() => {
processOCRForInvoicesAndAdmin().catch(console.error);
}, 60000);
}
return new Response('OCR pipeline initialized', { status: 200 });
}
9 changes: 3 additions & 6 deletions packages/web/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,10 @@ export default async function RootLayout({
}: Readonly<{
children: React.ReactNode;
}>) {
// Initialize OCR pipeline
// Initialize OCR pipeline on server-side only
if (process.env.NODE_ENV === 'production') {
try {
await fetch('/api/ocr/init');
} catch (error) {
console.error('Failed to initialize OCR pipeline:', error);
}
const { initializeOCRPipeline } = require('@/lib/ocr/init');
initializeOCRPipeline();
}
return (
<html
Expand Down
14 changes: 14 additions & 0 deletions packages/web/lib/ocr/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { processOCRForInvoicesAndAdmin } from './pipeline';

let initialized = false;

export function initializeOCRPipeline() {
if (!initialized && typeof window === 'undefined') {
initialized = true;
// Start the OCR pipeline
setInterval(() => {
processOCRForInvoicesAndAdmin().catch(console.error);
}, 60000);
console.log('OCR pipeline initialized');
}
}

0 comments on commit 15a0b72

Please sign in to comment.