diff --git a/samples/src/main/java/com/example/detect/DeidentifyFileExampleAsync.java b/samples/src/main/java/com/example/detect/DeidentifyFileExampleAsync.java new file mode 100644 index 00000000..651542f8 --- /dev/null +++ b/samples/src/main/java/com/example/detect/DeidentifyFileExampleAsync.java @@ -0,0 +1,121 @@ +package com.example.detect; + +import java.io.File; +import java.util.concurrent.CompletableFuture; + +import com.skyflow.Skyflow; +import com.skyflow.config.Credentials; +import com.skyflow.config.VaultConfig; +import com.skyflow.enums.Env; +import com.skyflow.enums.LogLevel; +import com.skyflow.enums.MaskingMethod; +import com.skyflow.errors.SkyflowException; +import com.skyflow.vault.detect.DeidentifyFileRequest; +import com.skyflow.vault.detect.DeidentifyFileResponse; +import com.skyflow.vault.detect.FileInput; + +/** + * Skyflow Deidentify File Async Example + *

+ * This example demonstrates how to use the Skyflow SDK to deidentify file in an asynchronous manner. + * It has all available options for deidentifying files. + * Supported file types: images (jpg, png, etc.), pdf, audio (mp3, wav), documents, spreadsheets, presentations, structured text. + * It includes: + * 1. Configure credentials + * 2. Set up vault configuration + * 3. Create a deidentify file request with all options + * 4. Call deidentifyFile to deidentify file + * 5. Handle response and errors + */ +public class DeidentifyFileExampleAsync { + + public static void main(String[] args) throws SkyflowException { + // Step 1: Set up credentials for the first vault configuration + Credentials credentials = new Credentials(); + credentials.setPath(""); // Replace with the path to the credentials file + + // Step 2: Configure the vault config + VaultConfig vaultConfig = new VaultConfig(); + vaultConfig.setVaultId(""); // Replace with the ID of the vault + vaultConfig.setClusterId(""); // Replace with the cluster ID of the vault + vaultConfig.setEnv(Env.PROD); // Set the environment (e.g., DEV, STAGE, PROD) + vaultConfig.setCredentials(credentials); // Associate the credentials with the vault + + // Step 3: Create a Skyflow client + Skyflow skyflowClient = Skyflow.builder() + .setLogLevel(LogLevel.ERROR) // Set log level to ERROR + .addVaultConfig(vaultConfig) // Add the vault configuration + .build(); + + // Step 4: Create a deidentify file request with all options + + // Create file object + File file = new File(""); // Replace with the path to the file you want to deidentify + + // Create file input using the file object + FileInput fileInput = FileInput.builder() + .file(file) + // .filePath("") // Alternatively, you can use .filePath() + .build(); + + // Output configuration + String outputDirectory = ""; // Replace with the desired output directory to save the deidentified file + + // Entities to detect + // List detectEntities = new ArrayList<>(); + // detectEntities.add(DetectEntities.IP_ADDRESS); // Replace with the entities you want to detect + + // Image-specific options + // Boolean outputProcessedImage = true; // Include processed image in output + // Boolean outputOcrText = true; // Include OCR text in output + MaskingMethod maskingMethod = MaskingMethod.BLACKBOX; // Masking method for images + + // PDF-specific options + // Integer pixelDensity = 15; // Pixel density for PDF processing + // Integer maxResolution = 2000; // Max resolution for PDF + + // Audio-specific options + // Boolean outputProcessedAudio = true; // Include processed audio + // DetectOutputTranscriptions outputTanscription = DetectOutputTranscriptions.PLAINTEXT_TRANSCRIPTION; // Transcription type + + // Audio bleep configuration + // AudioBleep audioBleep = AudioBleep.builder() + // .frequency(5D) // Pitch in Hz + // .startPadding(7D) // Padding at start (seconds) + // .stopPadding(8D) // Padding at end (seconds) + // .build(); + + Integer waitTime = 20; // Max wait time for response (max 64 seconds) + + DeidentifyFileRequest deidentifyFileRequest = DeidentifyFileRequest.builder() + .file(fileInput) + .waitTime(waitTime) + // .entities(detectEntities) + .outputDirectory(outputDirectory) + .maskingMethod(maskingMethod) + // .outputProcessedImage(outputProcessedImage) + // .outputOcrText(outputOcrText) + // .pixelDensity(pixelDensity) + // .maxResolution(maxResolution) + // .outputProcessedAudio(outputProcessedAudio) + // .outputTranscription(outputTanscription) + // .bleep(audioBleep) + .build(); + + CompletableFuture future = CompletableFuture.supplyAsync(() -> { + try { + return skyflowClient.detect(vaultConfig.getVaultId()).deidentifyFile(deidentifyFileRequest); + } catch (SkyflowException e) { + throw new RuntimeException(e); + } + }).thenAccept(response -> { + System.out.println("Deidentify file response: " + response.toString()); + }).exceptionally(throwable -> { + System.err.println("Error occurred during deidentify file: "); + throwable.printStackTrace(); + return null; + }); + + future.join(); + } +}