Skip to content

Commit 48a83ca

Browse files
committed
add crop calls
1 parent 5e93607 commit 48a83ca

6 files changed

Lines changed: 167 additions & 11 deletions

File tree

.github/workflows/_test-code-samples.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ env:
1212
MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID }}
1313
MINDEE_V2_SE_TESTS_CROP_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CROP_MODEL_ID }}
1414
MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID }}
15+
MINDEE_V2_SE_TESTS_OCR_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_OCR_MODEL_ID }}
1516

1617
jobs:
1718
test_sample_code:

.github/workflows/_test-integrations.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ on:
44
workflow_call:
55
workflow_dispatch:
66

7+
env:
8+
MINDEE_API_KEY: ${{ secrets.MINDEE_API_KEY_SE_TESTS }}
9+
WORKFLOW_ID: ${{ secrets.WORKFLOW_ID_SE_TESTS }}
10+
MINDEE_V2_API_KEY: ${{ secrets.MINDEE_V2_SE_TESTS_API_KEY }}
11+
MINDEE_V2_SE_TESTS_BLANK_PDF_URL: ${{ secrets.MINDEE_V2_SE_TESTS_BLANK_PDF_URL }}
12+
MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }}
13+
MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID }}
14+
MINDEE_V2_SE_TESTS_CROP_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CROP_MODEL_ID }}
15+
MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID }}
16+
MINDEE_V2_SE_TESTS_OCR_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_OCR_MODEL_ID }}
17+
718
jobs:
819
integration_tests:
920
name: Run Integration Tests
@@ -31,11 +42,5 @@ jobs:
3142
cache: "maven"
3243

3344
- name: Verify with Maven
34-
env:
35-
MINDEE_API_KEY: ${{ secrets.MINDEE_API_KEY_SE_TESTS }}
36-
WORKFLOW_ID: ${{ secrets.WORKFLOW_ID_SE_TESTS }}
37-
MINDEE_V2_API_KEY: ${{ secrets.MINDEE_V2_SE_TESTS_API_KEY }}
38-
MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }}
39-
MINDEE_V2_SE_TESTS_BLANK_PDF_URL: ${{ secrets.MINDEE_V2_SE_TESTS_BLANK_PDF_URL }}
4045
run: |
4146
mvn clean test-compile failsafe:integration-test failsafe:verify

docs/code_samples/v2_crop.txt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import com.mindee.MindeeClientV2;
2+
import com.mindee.input.LocalInputSource;
3+
import com.mindee.v2.product.crop.CropResponse;
4+
import com.mindee.v2.product.crop.params.CropParameters;
5+
import java.io.File;
6+
import java.io.IOException;
7+
8+
public class SimpleMindeeClientV2 {
9+
10+
public static void main(String[] args)
11+
throws IOException, InterruptedException
12+
{
13+
String apiKey = "MY_API_KEY";
14+
String filePath = "/path/to/the/file.ext";
15+
String modelId = "MY_MODEL_ID";
16+
17+
// Init a new client
18+
MindeeClientV2 mindeeClient = new MindeeClientV2(apiKey);
19+
20+
// Set inference parameters
21+
// Note: modelId is mandatory.
22+
CropParameters cropParams = CropParameters
23+
// ID of the model, required.
24+
.builder(modelId)
25+
.build();
26+
27+
// Load a file from disk
28+
LocalInputSource inputSource = new LocalInputSource(
29+
new File(filePath)
30+
);
31+
32+
// Send for processing
33+
CropResponse response = mindeeClient.enqueueAndGetResult(
34+
CropResponse.class,
35+
inputSource,
36+
cropParams
37+
);
38+
39+
// Print a summary of the response
40+
System.out.println(response.getInference().toString());
41+
}
42+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.mindee.v2.product.crop.params;
2+
3+
import com.mindee.AsyncPollingOptions;
4+
import com.mindee.v2.clientOptions.BaseParameters;
5+
import com.mindee.v2.http.ProductInfo;
6+
7+
@ProductInfo(slug = "crop")
8+
public class CropParameters extends BaseParameters {
9+
10+
public CropParameters(
11+
String modelId,
12+
String alias,
13+
String[] webhookIds,
14+
AsyncPollingOptions pollingOptions
15+
) {
16+
super(modelId, alias, webhookIds, pollingOptions);
17+
}
18+
19+
/**
20+
* Create a new builder.
21+
*
22+
* @param modelId the mandatory model identifier
23+
* @return a fresh {@link CropParameters.Builder}
24+
*/
25+
public static Builder builder(String modelId) {
26+
return new Builder(modelId);
27+
}
28+
29+
public static final class Builder extends BaseParameters.BaseBuilder<Builder> {
30+
31+
Builder(String modelId) {
32+
super(modelId);
33+
}
34+
35+
/** Build an immutable {@link CropParameters} instance. */
36+
public CropParameters build() {
37+
return new CropParameters(modelId, alias, webhookIds, pollingOptions);
38+
}
39+
}
40+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.mindee.v2.product;
2+
3+
import static com.mindee.TestingUtilities.getResourcePath;
4+
import static org.junit.jupiter.api.Assertions.*;
5+
6+
import com.mindee.AsyncPollingOptions;
7+
import com.mindee.MindeeClientV2;
8+
import com.mindee.input.LocalInputSource;
9+
import com.mindee.parsing.v2.InferenceFile;
10+
import com.mindee.v2.product.crop.CropInference;
11+
import com.mindee.v2.product.crop.CropResponse;
12+
import com.mindee.v2.product.crop.CropResult;
13+
import com.mindee.v2.product.crop.params.CropParameters;
14+
import java.io.IOException;
15+
import org.junit.jupiter.api.BeforeAll;
16+
import org.junit.jupiter.api.DisplayName;
17+
import org.junit.jupiter.api.Tag;
18+
import org.junit.jupiter.api.Test;
19+
import org.junit.jupiter.api.TestInstance;
20+
21+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
22+
@Tag("integration")
23+
@DisplayName("MindeeV2 –Integration Tests - Crop")
24+
class CropIT {
25+
26+
private MindeeClientV2 mindeeClient;
27+
private String modelId;
28+
29+
@BeforeAll
30+
void setUp() {
31+
String apiKey = System.getenv("MINDEE_V2_API_KEY");
32+
modelId = System.getenv("MINDEE_V2_SE_TESTS_CROP_MODEL_ID");
33+
mindeeClient = new MindeeClientV2(apiKey);
34+
}
35+
36+
@Test
37+
@DisplayName("Empty, multi-page PDF – enqueue & parse must succeed")
38+
void parseFile_emptyMultiPage_mustSucceed() throws IOException, InterruptedException {
39+
LocalInputSource source = new LocalInputSource(
40+
getResourcePath("file_types/pdf/multipage_cut-2.pdf")
41+
);
42+
CropParameters params = CropParameters
43+
.builder(modelId)
44+
.alias("java_integration-test_crop_multipage")
45+
.pollingOptions(
46+
AsyncPollingOptions.builder().initialDelaySec(3.0).intervalSec(1.5).maxRetries(80).build()
47+
)
48+
.build();
49+
50+
CropResponse response = mindeeClient.enqueueAndGetResult(CropResponse.class, source, params);
51+
assertNotNull(response);
52+
CropInference inference = response.getInference();
53+
assertNotNull(inference);
54+
55+
InferenceFile file = inference.getFile();
56+
assertNotNull(file);
57+
assertEquals("multipage_cut-2.pdf", file.getName());
58+
assertEquals(2, file.getPageCount());
59+
60+
assertNotNull(inference.getModel());
61+
assertEquals(modelId, inference.getModel().getId());
62+
63+
CropResult result = inference.getResult();
64+
assertNotNull(result);
65+
assertEquals(1, result.getCrops().size());
66+
assertEquals("other", result.getCrops().get(0).getObjectType());
67+
}
68+
}

tests/test_v2_code_samples.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,27 @@ do
1818
sed "s/MY_API_KEY/${MINDEE_V2_API_KEY}/" "${f}" > $OUTPUT_FILE
1919
sed -i "s/\/path\/to\/the\/file.ext/src\/test\/resources\/file_types\/pdf\/blank_1.pdf/" $OUTPUT_FILE
2020

21-
if echo "${f}" | grep -q "v2_classification.txt"
21+
if echo "${f}" | grep -q "v2_classification"
2222
then
2323
sed -i "s/MY_MODEL_ID/${MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID}/" $OUTPUT_FILE
2424
fi
2525

26-
if echo "${f}" | grep -q "v2_crop.txt"
26+
if echo "${f}" | grep -q "v2_crop"
2727
then
2828
sed -i "s/MY_MODEL_ID/${MINDEE_V2_SE_TESTS_CROP_MODEL_ID}/" $OUTPUT_FILE
2929
fi
3030

31-
if echo "${f}" | grep -q "v2_extraction.txt"
31+
if echo "${f}" | grep -q "v2_extraction"
3232
then
3333
sed -i "s/MY_MODEL_ID/${MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID}/" $OUTPUT_FILE
3434
fi
3535

36-
if echo "${f}" | grep -q "v2_ocr.txt"
36+
if echo "${f}" | grep -q "v2_ocr"
3737
then
3838
sed -i "s/MY_MODEL_ID/${MINDEE_V2_SE_TESTS_OCR_MODEL_ID}/" $OUTPUT_FILE
3939
fi
4040

41-
if echo "${f}" | grep -q "v2_split.txt"
41+
if echo "${f}" | grep -q "v2_split"
4242
then
4343
sed -i "s/MY_MODEL_ID/${MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID}/" $OUTPUT_FILE
4444
fi

0 commit comments

Comments
 (0)