Skip to content

Commit

Permalink
📝 harmonize custom doc sample code
Browse files Browse the repository at this point in the history
  • Loading branch information
ianardee committed Nov 22, 2023
1 parent df8265b commit f5a792d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 20 deletions.
28 changes: 18 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,25 @@ print(result.document)
```python
from mindee import Client, product

# Init a new client and add your custom endpoint (document)
# Init a new client
mindee_client = Client(api_key="my-api-key")
custom_endpoint = mindee_client.create_endpoint(
account_name="john",
endpoint_name="wnine",

# Add your custom endpoint (document)
my_endpoint = mindee_client.create_endpoint(
account_name="my-account",
endpoint_name="my-endpoint",
)

# Load a file from disk
input_doc = mindee_client.source_from_path("/path/to/the/file.ext")

# Parse the file.
# The endpoint must be specified since it can't be determined from the class.
result = parse(product.CustomV1, endpoint=custom_endpoint)
# The endpoint must be specified since it cannot be determined from the class.
result = mindee_client.parse(
product.CustomV1,
input_doc,
endpoint=my_endpoint
)

# Print a brief summary of the parsed data
print(result.document)
Expand All @@ -109,12 +115,14 @@ Allows sending only certain pages in a PDF.
In this example we only send the first, penultimate and last pages:

```python
api_response = mindee_client.parse(
mindee.product.InvoiceV4,
from mindee import Client, product, PageOptions

result = mindee_client.parse(
product.InvoiceV4,
input_source,
page_options=mindee.PageOptions(
page_options=PageOptions(
page_indexes=[0, -2, -1],
operation: mindee.PageOptions.KEEP_ONLY,
operation=PageOptions.KEEP_ONLY,
on_min_pages=2
)
)
Expand Down
16 changes: 12 additions & 4 deletions docs/extras/code_samples/custom_v1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@ from mindee import Client, PredictResponse, product
# Init a new client
mindee_client = Client(api_key="my-api-key")

custom_endpoint = mindee_client.create_endpoint("my-endpoint", "my-account")
# Add your custom endpoint (document)
my_endpoint = mindee_client.create_endpoint(
account_name="my-account",
endpoint_name="my-endpoint",
)

# Load a file from disk
input_doc = mindee_client.source_from_path("/path/to/the/file.ext")

# Load a file from disk and parse it.
# The endpoint name must be specified since it cannot be determined from the class.
result: PredictResponse = mindee_client.parse(product.CustomV1, input_doc, endpoint=custom_endpoint)
# Parse the file.
# The endpoint must be specified since it cannot be determined from the class.
result: PredictResponse = mindee_client.parse(
product.CustomV1,
input_doc,
endpoint=my_endpoint
)

# Print a brief summary of the parsed data
print(result.document)
Expand Down
17 changes: 11 additions & 6 deletions docs/extras/guide/custom_v1.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ from mindee import Client, product
# Init a new client
mindee_client = Client(api_key="my-api-key")

# Load a file from disk
input_doc = mindee_client.source_from_path("/path/to/the/file.ext")
# Add your custom endpoint (document)
my_endpoint = mindee_client.create_endpoint(
account_name="my-account",
endpoint_name="my-endpoint",
account_name="my-account-name",
version="my-version",
)

# Parse the document as an invoice by passing the appropriate type
# Load a file from disk
input_doc = mindee_client.source_from_path("/path/to/the/file.ext")

# Parse the file.
# The endpoint must be specified since it cannot be determined from the class.
result = mindee_client.parse(
product.CustomV1,
input_doc,
Expand All @@ -29,6 +31,10 @@ result = mindee_client.parse(

# Print a brief summary of the parsed data
print(result.document)

# Iterate over all the fields in the document
for field_name, field_values in result.document.fields.items():
print(field_name, "=", field_values)
```

# Custom Endpoints
Expand All @@ -47,7 +53,6 @@ If it is not set, it will default to "1".

A `ListField` is a special type of custom list that implements the following:


* **confidence** (`float`): the confidence score of the field prediction.
* **reconstructed** (`bool`): indicates whether or not an object was reconstructed (not extracted as the API gave it).
* **values** (`List[`[ListFieldValue](#list-field-value)`]`): list of value fields
Expand Down

0 comments on commit f5a792d

Please sign in to comment.