-
Notifications
You must be signed in to change notification settings - Fork 274
docs(genapi): added ocr models #6419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
firdevs-a
wants to merge
4
commits into
main
Choose a base branch
from
MTA-7061
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| --- | ||
| title: How to query OCR models | ||
| description: Learn how to interact with powerful OCR models using Scaleway's Generative APIs service. | ||
| tags: generative-apis ai-data ocr-models ocr-api | ||
| dates: | ||
| validation: 2026-04-14 | ||
| posted: 2026-04-14 | ||
| --- | ||
| import Requirements from '@macros/iam/requirements.mdx' | ||
|
|
||
| Scaleway's Generative APIs service allows users to interact with powerful OCR (Optical Character Recognition) models hosted on the platform. | ||
|
|
||
| OCR models can extract structured text from documents such as PDFs and images, preserving formatting and layout in the output. | ||
|
|
||
| <Message type="note"> | ||
| OCR models are currently available via the [OCR API](https://www.scaleway.com/en/developers/api/generative-apis/#path-ocr-beta-create-a-text-extraction) only and are not yet integrated into the Scaleway console playground. | ||
| </Message> | ||
|
|
||
| <Requirements /> | ||
|
|
||
| - A Scaleway account logged in to the [console](https://console.scaleway.com) | ||
| - [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization | ||
| - A valid [API key](/iam/how-to/create-api-keys/) for API authentication | ||
| - Python 3.7+ installed on your system | ||
|
|
||
| ## Query OCR models via API | ||
|
|
||
| You can query the models programmatically using your favorite tools or languages. | ||
| In the example that follows, we will use the MistralAI Python client. | ||
|
|
||
| ### Install the MistralAI SDK | ||
|
|
||
| Install the MistralAI SDK using pip: | ||
|
|
||
| ```bash | ||
| pip install mistralai | ||
| ``` | ||
|
|
||
| ### Initialize the client | ||
|
|
||
| Initialize the MistralAI client with your base URL and API key: | ||
|
|
||
| ```python | ||
| from mistralai.client import Mistral | ||
| import os | ||
|
|
||
| # Initialize the client with your server URL and API key | ||
| mistral = Mistral( | ||
| server_url="https://api.scaleway.ai", # Scaleway's Generative APIs service URL | ||
| api_key="<SCW_SECRET_KEY>" # Your unique API secret key from Scaleway | ||
| ) | ||
| ``` | ||
|
|
||
|
firdevs-a marked this conversation as resolved.
|
||
| ### Generate an OCR text extraction | ||
|
|
||
| You can now generate a text extraction. | ||
| In the example below, the sample PDF file, [scaleway-impact-report-10-pages.pdf](https://genapi-documentation-assets.s3.fr-par.scw.cloud/scaleway-impact-report-10-pages.pdf), is sent to the OCR model via a public URL. The extracted text from each page is written to a local Markdown file. | ||
|
|
||
| ```python | ||
| # Generate a text extraction using the 'mistral-ocr-2512' model | ||
| FILE_URL = "https://genapi-documentation-assets.s3.fr-par.scw.cloud/scaleway-impact-report-10-pages.pdf" | ||
| MODEL = "mistral-ocr-2512" | ||
|
|
||
| res = mistral.ocr.process( | ||
| model=MODEL, | ||
| document={ | ||
| "document_url": FILE_URL, | ||
| "type": "document_url", | ||
| } | ||
| ) | ||
|
|
||
| filename = FILE_URL.split("/")[-1].split(".")[0] | ||
| with open(f"{filename}.md", "w") as f: | ||
| for page in res.pages: | ||
| f.write(page.markdown) | ||
|
|
||
| # Print the generated response | ||
| print(f"File processed. Result markdown file stored in: {filename}.md") | ||
| ``` | ||
|
|
||
| Once the script completes, a Markdown file named `scaleway-impact-report-10-pages.md` is created in the current directory, containing the extracted and formatted text from each page of the PDF. | ||
|
|
||
| <Message type="tip"> | ||
| You can replace `FILE_URL` with the URL of any publicly accessible PDF or image file. | ||
| The input file or image must be stored in Scaleway Object Storage and referenced by its URL. | ||
|
firdevs-a marked this conversation as resolved.
Outdated
|
||
| </Message> | ||
|
|
||
|
firdevs-a marked this conversation as resolved.
|
||
| Refer to the dedicated [OCR API documentation](https://www.scaleway.com/en/developers/api/generative-apis/#path-ocr-beta-create-a-text-extraction) for a full list of all available parameters. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.