Skip to content

OCR model update#4309

Merged
Maheshkale447 merged 2 commits into
masterfrom
Enhancment/PaddleOnlineModelOCR
Sep 21, 2025
Merged

OCR model update#4309
Maheshkale447 merged 2 commits into
masterfrom
Enhancment/PaddleOnlineModelOCR

Conversation

@AmanPrasad43

@AmanPrasad43 AmanPrasad43 commented Sep 21, 2025

Copy link
Copy Markdown
Contributor

Thank you for your contribution.
Before submitting this PR, please make sure:

  • PR description and commit message should describe the changes done in this PR
  • Verify the PR is pointing to correct branch i.e. Release or Beta branch if the code fix is for specific release , else point it to master
  • Latest Code from master or specific release branch is merged to your branch
  • No unwanted\commented\junk code is included
  • No new warning upon build solution
  • Code Summary\Comments are added to my code which explains what my code is doing
  • Existing unit test cases are passed
  • New Unit tests are added for your development
  • Sanity Tests are successfully executed for New and Existing Functionality
  • Verify that changes are compatible with all relevant browsers and platforms.
  • After creating pull request there should not be any conflicts
  • Resolve all Codacy comments
  • Builds and checks are passed before PR is sent for review
  • Resolve code review comments
  • Update the Help Library document to match any feature changes

Summary by CodeRabbit

  • New Features

    • Multi-page PDF OCR support with options to process specific pages or all pages.
    • Automatic download/use of the English V4 OCR model.
    • Improved PDF table extraction using advanced detection and extraction techniques.
    • More informative error messages and fallback behavior for OCR/table operations.
  • Refactor

    • Streamlined OCR model retrieval and revised PDF processing flow for improved reliability.
  • Chores

    • Switched to online OCR model packages and adjusted related dependencies.
  • Tests

    • Updated OCR test coverage: some tests re-enabled, others marked ignored to reduce flakiness.

@coderabbitai

coderabbitai Bot commented Sep 21, 2025

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

Walkthrough

Relocates ActOcr into the GingerCore.Actions namespace, updates references, refactors OCR model retrieval to use a downloadable online model, overhauls PDF table extraction to use Tabula/PdfPig, and updates project package references and build entries.

Changes

Cohort / File(s) Change Summary
ActOcr namespace & usage
Ginger/Ginger/Actions/ActionEditPages/ActOcrEditPage.xaml.cs, Ginger/GingerCore/Actions/ActOcr.cs
Moved ActOcr into GingerCore.Actions; updated using/static references and adjusted imports to the new namespace.
Project file & packages
Ginger/GingerCore/GingerCore.csproj
Modified project compile entries for ActOcr.cs; changed NuGet package versions: downgraded Sdcb.PaddleInference and replaced local/shared PaddleOCR model packages with the online model package.
OCR workflows & PDF/table extraction
Ginger/GingerCore/GingerOCR/GingerOcrOperations.cs
Replaced local model/byte-array flow with GetOCRModel() that downloads the EnglishV4 online model; refactored PDF image/OCR pipeline and replaced prior word-based table reconstruction with Tabula-based detection/extraction using PdfPig integrations; added logging and error handling.
Tests
Ginger/GingerCoreTest/Misc/OcrTest.cs
Re-enabled OcrTest class (removed Ignore), adjusted expected newline behavior in some image tests, and added Ignore attributes to several PDF-related tests.

Sequence Diagram(s)

sequenceDiagram
    participant User as User
    participant OcrOps as GingerOcrOperations
    participant ModelSvc as Online OCR Model (Sdcb.PaddleOCR.Models.Online)
    participant PdfPig as PdfPig (render)
    participant Tabula as Tabula Detectors/Extractors

    User->>OcrOps: Request PDF/text/table extraction
    OcrOps->>ModelSvc: Call GetOCRModel() (download & prepare)
    ModelSvc-->>OcrOps: Return prepared model
    OcrOps->>PdfPig: Render page -> images
    loop For each page
        OcrOps->>Tabula: Detect table areas
        Tabula-->>OcrOps: Table area(s)
        loop For each area
            OcrOps->>Tabula: Extract table data
            Tabula-->>OcrOps: Return table rows/cols
        end
        OcrOps->>ModelSvc: OCR image bytes
        ModelSvc-->>OcrOps: Return extracted text
    end
    OcrOps-->>User: Return aggregated text/table results (with logs/errors)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • Maheshkale447

Poem

Down the byte-tunnel I hop with cheer,
New models fetched and tables clear 🐇
Namespaces tidy, pages scanned bright,
Tabula finds rows by morning light.
Hooray for OCR—I've nibbled the night.

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description contains only the repository checklist template and does not describe the actual changes, rationale, target branch, affected files, test results, or build/CI status, so it does not meet the repository's required template content. The template is useful but must be replaced or supplemented with a concrete summary of what changed (for example: GetOCRModel addition, ActOcr namespace move, csproj package/model changes, and PDF/table-extraction refactor), the reasons for the changes, and verification steps. Because these required details are missing, the description check fails. Please update the PR description to replace the checklist placeholder with a filled summary that lists the modified files/components, the rationale, the target branch, any breaking or migration impacts, and the verification steps; include CI/build status and unit/integration test results or instructions to reproduce validation, and reference the issue/ticket ID. Also indicate which checklist items are complete and which still need work so reviewers can assess readiness.
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The PR title "OCR model update" is concise and directly related to the primary changes in this changeset, which focus on OCR model retrieval and OCR-related refactors (GetOCRModel addition, package/model changes, and updated PDF/table-extraction logic). It is short, specific to the domain, and readable for a reviewer scanning history. The title avoids noise like file lists or vague wording. If desired, the author can make it more explicit about large structural changes (e.g., ActOcr namespace move or PDF table-extraction refactor).

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 632ed94 and b196215.

📒 Files selected for processing (2)
  • Ginger/GingerCore/GingerOCR/GingerOcrOperations.cs (6 hunks)
  • Ginger/GingerCoreTest/Misc/OcrTest.cs (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Maheshkale447
Maheshkale447 previously approved these changes Sep 21, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 13

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (6)
Ginger/GingerCore/Actions/ActOcr.cs (4)

249-250: Remove unused backing property.

mGetFromRowNumber is never used; keep only GetFromRowNumber.

-        private string mGetFromRowNumber { get; set; } = "0";

293-294: Remove unused local.

dctOutput is declared but never used.

-            Dictionary<string, object> dctOutput = [];

348-349: Remove unused local.

Duplicate unused dctOutput here as well.

-            Dictionary<string, object> dctOutput = [];

387-394: Harden parsing of UseRowNumber and GetFromRowNumber to avoid runtime exceptions.

bool.Parse/int.Parse will throw on invalid/empty input (common when actions run headless). Default safely.

                 case eActOcrPdfOperations.ReadTextFromTableInPdf:
                     if (string.IsNullOrEmpty(GetFromRowNumber))
                     {
                         GetFromRowNumber = "0";
                     }
-                    resultText = GingerOcrOperations.ReadTextFromPdfTable(ValueExpression.Calculate(OcrFilePath), ValueExpression.Calculate(FirstString), ValueExpression.Calculate(PageNumber), bool.Parse(UseRowNumber),
-                        int.Parse(ValueExpression.Calculate(GetFromRowNumber)), ElementLocateBy, ValueExpression.Calculate(ConditionColumnName),
-                        ValueExpression.Calculate(ConditionColumnValue), decryptedPassword);
+                    // Safe parsing with defaults
+                    bool useRow = false;
+                    bool.TryParse(UseRowNumber, out useRow);
+                    int fromRow = 0;
+                    int.TryParse(ValueExpression.Calculate(GetFromRowNumber), out fromRow);
+                    if (fromRow < 0) fromRow = 0;
+
+                    resultText = GingerOcrOperations.ReadTextFromPdfTable(
+                        ValueExpression.Calculate(OcrFilePath),
+                        ValueExpression.Calculate(FirstString),
+                        ValueExpression.Calculate(PageNumber),
+                        useRow,
+                        fromRow,
+                        ElementLocateBy,
+                        ValueExpression.Calculate(ConditionColumnName),
+                        ValueExpression.Calculate(ConditionColumnValue),
+                        decryptedPassword);
                     if (!string.IsNullOrEmpty(resultText))
                     {
                         ProcessOutput(resultText);
                     }
                     else
                     {
                         Error = "Unable to read text from PDF";
                     }
                     break;
Ginger/Ginger/Actions/ActionEditPages/ActOcrEditPage.xaml.cs (2)

228-233: Bug: toggles reversed when “Select Column Value” radio is checked.

Currently sets UseRowNumber = true and enables Row Number fields instead of Column filters. Fix below.

-            mAct.UseRowNumber = rb.IsChecked.Value.ToString();
-            xRowNumber.IsEnabled = rb.IsChecked.Value;
-            xColumnWhere.IsEnabled = !rb.IsChecked.Value;
-            xColumnWhereValue.IsEnabled = !rb.IsChecked.Value;
-            xOperationCombo.IsEnabled = !rb.IsChecked.Value;
+            var isColumnValue = rb.IsChecked == true;
+            mAct.UseRowNumber = (!isColumnValue).ToString();
+            xRowNumber.IsEnabled = !isColumnValue;
+            xColumnWhere.IsEnabled = isColumnValue;
+            xColumnWhereValue.IsEnabled = isColumnValue;
+            xOperationCombo.IsEnabled = isColumnValue;

83-92: Store solution-relative path in the action — don’t convert back to full when saving

SolutionRepository.ConvertFullPathToBeRelative produces a solution-root relative path (prefixes with the solution-root sign) and GetFolderFullPath converts such relative paths back to absolute (SolutionRepository.cs — GetFolderFullPath ~line 392; ConvertFullPathToBeRelative ~line 421). In ActOcrEditPage.xaml.cs the browse handler currently does ConvertFullPathToBeRelative(fileName) then immediately calls GetFolderFullPath(fileName) and assigns that absolute path to mAct.OcrFilePath while displaying the relative path (browse handler, ActOcrEditPage.xaml.cs, ~lines 80–110). That stores an absolute path in the action and risks portability; ActSikuliEditPage stores the relative path instead (ActSikuliEditPage.xaml.cs ~line 151). Change the browse handler to store the relative path (assign fileName after ConvertFullPathToBeRelative) and resolve to full path only at execution time, or make this behavior consistent across actions.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 10881a4 and 632ed94.

📒 Files selected for processing (4)
  • Ginger/Ginger/Actions/ActionEditPages/ActOcrEditPage.xaml.cs (1 hunks)
  • Ginger/GingerCore/Actions/ActOcr.cs (1 hunks)
  • Ginger/GingerCore/GingerCore.csproj (2 hunks)
  • Ginger/GingerCore/GingerOCR/GingerOcrOperations.cs (6 hunks)
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2025-04-25T13:29:45.059Z
Learnt from: GokulBothe99
PR: Ginger-Automation/Ginger#4188
File: Ginger/GingerCoreNET/RunLib/CLILib/DoOptionsHanlder.cs:22-23
Timestamp: 2025-04-25T13:29:45.059Z
Learning: The `using Amdocs.Ginger.Repository;` statement in Ginger/GingerCoreNET/RunLib/CLILib/DoOptionsHanlder.cs is necessary as it provides access to the `ObservableList<>` class which is used throughout the file for collections of RunSetConfig, AnalyzerItemBase, and ApplicationPOMModel objects.

Applied to files:

  • Ginger/Ginger/Actions/ActionEditPages/ActOcrEditPage.xaml.cs
  • Ginger/GingerCore/Actions/ActOcr.cs
📚 Learning: 2025-06-16T10:37:13.073Z
Learnt from: prashelke
PR: Ginger-Automation/Ginger#4232
File: Ginger/GingerCoreNET/ActionsLib/UI/VisualTesting/VRTAnalyzer.cs:19-22
Timestamp: 2025-06-16T10:37:13.073Z
Learning: In Ginger codebase, both `using amdocs.ginger.GingerCoreNET;` and `using Amdocs.Ginger.CoreNET;` are valid and serve different purposes. The first (lowercase) contains the WorkSpace class and related workspace functionality, while the second (proper case) contains drivers like GenericAppiumDriver and other core functionality. Both may be required in files that use types from both namespaces.

Applied to files:

  • Ginger/Ginger/Actions/ActionEditPages/ActOcrEditPage.xaml.cs
  • Ginger/GingerCore/Actions/ActOcr.cs
📚 Learning: 2025-04-25T13:29:45.059Z
Learnt from: GokulBothe99
PR: Ginger-Automation/Ginger#4188
File: Ginger/GingerCoreNET/RunLib/CLILib/DoOptionsHanlder.cs:22-23
Timestamp: 2025-04-25T13:29:45.059Z
Learning: The `using Amdocs.Ginger.Repository;` statement in Ginger/GingerCoreNET/RunLib/CLILib/DoOptionsHanlder.cs is necessary as it imports the ObservableList<> class which is used throughout the file.

Applied to files:

  • Ginger/Ginger/Actions/ActionEditPages/ActOcrEditPage.xaml.cs
📚 Learning: 2025-03-20T11:10:30.816Z
Learnt from: GokulBothe99
PR: Ginger-Automation/Ginger#4137
File: Ginger/Ginger/SourceControl/SourceControlProjectsPage.xaml.cs:21-21
Timestamp: 2025-03-20T11:10:30.816Z
Learning: The `Amdocs.Ginger.Common.SourceControlLib` namespace is required in files that reference the `GingerSolution` class for source control operations in the Ginger automation framework.

Applied to files:

  • Ginger/Ginger/Actions/ActionEditPages/ActOcrEditPage.xaml.cs
🧬 Code graph analysis (3)
Ginger/Ginger/Actions/ActionEditPages/ActOcrEditPage.xaml.cs (1)
Ginger/GingerCore/Actions/ActOcr.cs (1)
  • ActOcr (28-424)
Ginger/GingerCore/Actions/ActOcr.cs (1)
Ginger/GingerCore/Drivers/MainFrame/MainFrameDriver.cs (1)
  • Actions (508-512)
Ginger/GingerCore/GingerOCR/GingerOcrOperations.cs (2)
Ginger/GingerCore/Actions/ActOcr.cs (1)
  • ActOcr (28-424)
Ginger/GingerCoreCommon/ReporterLib/Reporter.cs (1)
  • Reporter (28-357)
🔇 Additional comments (6)
Ginger/Ginger/Actions/ActionEditPages/ActOcrEditPage.xaml.cs (3)

22-22: Correct import for relocated ActOcr.

Importing GingerCore.Actions aligns the editor with the new namespace.


28-28: Static using updated to new ActOcr location.

Good alignment with the refactor.


19-21: Both CoreNET namespaces are acceptable per repo conventions.

Keeping using amdocs.ginger.GingerCoreNET; is valid for WorkSpace usage (per retrieved learnings).

Ginger/GingerCore/GingerCore.csproj (2)

201-201: Include of moved file is correct.

Actions\ActOcr.cs is compiled under GingerCore; matches the relocation.


544-548: No lockstep required — versions are compatible. Sdcb.PaddleInference 3.0.0 (runtime 3.0.0.36), Sdcb.PaddleOCR 3.0.0 and Sdcb.PaddleOCR.Models.Online 3.0.1 have no documented requirement to be exact-equal; no changes required.

Ginger/GingerCore/Actions/ActOcr.cs (1)

26-26: Approve — namespace relocation complete; no remaining GingerCore.ActOcr references.

Search for GingerCore.ActOcr returned no matches; ActOcr is defined at Ginger/GingerCore/Actions/ActOcr.cs (namespace GingerCore.Actions) and usages reference GingerCore.Actions or unqualified ActOcr (e.g., Ginger/Ginger/Actions/ActionEditPages/ActOcrEditPage.xaml.cs).

Comment thread Ginger/GingerCore/GingerCore.csproj
Comment thread Ginger/GingerCore/GingerOCR/GingerOcrOperations.cs Outdated
Comment thread Ginger/GingerCore/GingerOCR/GingerOcrOperations.cs
Comment thread Ginger/GingerCore/GingerOCR/GingerOcrOperations.cs
Comment thread Ginger/GingerCore/GingerOCR/GingerOcrOperations.cs Outdated
Comment thread Ginger/GingerCore/GingerOCR/GingerOcrOperations.cs
Comment thread Ginger/GingerCore/GingerOCR/GingerOcrOperations.cs
Comment thread Ginger/GingerCore/GingerOCR/GingerOcrOperations.cs Outdated
Comment thread Ginger/GingerCore/GingerOCR/GingerOcrOperations.cs Outdated
Comment thread Ginger/GingerCore/GingerOCR/GingerOcrOperations.cs Outdated
@Maheshkale447
Maheshkale447 merged commit 1c7edca into master Sep 21, 2025
3 of 5 checks passed
@Maheshkale447
Maheshkale447 deleted the Enhancment/PaddleOnlineModelOCR branch September 21, 2025 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants