### Install Gemini Data Extractor using Pip Source: https://github.com/nicodds/gemini-data-extractor/blob/master/README.md Installs the Gemini Data Extractor tool from the Python Package Index (PyPI). This is the primary method for setting up the tool on your system. ```bash pip install gemini-data-extractor ``` -------------------------------- ### Authentication using API Key Source: https://github.com/nicodds/gemini-data-extractor/blob/master/README.md Illustrates how to authenticate with the Gemini API using a provided API key, either directly via a command-line argument or by setting an environment variable. ```bash gemini-data-extractor --path path/to/your/file.pdf --prompt "Your prompt here" --api-key your-api-key ``` ```bash export GEMINI_API_KEY=your-api-key gemini-data-extractor --path path/to/your/file.pdf --prompt "Your prompt here" ``` -------------------------------- ### Authentication using Google Cloud SDK Source: https://github.com/nicodds/gemini-data-extractor/blob/master/README.md Demonstrates authentication for the Gemini API using the Google Cloud SDK's application default login. Requires project ID and location, which can be set via arguments or environment variables. ```bash gcloud auth application-default login ``` ```bash gemini-data-extractor --path path/to/your/file.pdf --prompt "Your prompt here" --project-id your-project-id --location your-location ``` ```bash export GCP_PROJECT_ID=your-project-id export GCP_LOCATION=your-location gemini-data-extractor --path path/to/your/file.pdf --prompt "Your prompt here" ``` -------------------------------- ### Environment Variables for Configuration Source: https://context7.com/nicodds/gemini-data-extractor/llms.txt Shows how to configure authentication and settings for the Gemini Data Extractor using environment variables. These variables serve as fallbacks when command-line arguments are not provided, with CLI arguments taking precedence. ```Bash # Google AI Studio API Key export GEMINI_API_KEY=your-api-key # Google Cloud Platform / Vertex AI export GCP_PROJECT_ID=my-gcp-project export GCP_LOCATION=us-central1 # Environment variables are used as fallback when CLI args are not provided # CLI arguments take precedence over environment variables ``` -------------------------------- ### Basic Usage: Extract Data from PDF Source: https://github.com/nicodds/gemini-data-extractor/blob/master/README.md Demonstrates the basic command-line usage for extracting data from a PDF file. Requires the path to the PDF and a text prompt. ```bash gemini-data-extractor --path path/to/your/file.pdf --prompt-text "Your prompt here" ``` -------------------------------- ### Environment Variables Configuration Source: https://context7.com/nicodds/gemini-data-extractor/llms.txt Details on how to configure authentication and settings using environment variables for the Gemini Data Extractor. ```APIDOC ## Environment Variables ### Description Configure authentication and settings using environment variables. ### Environment Variables - **GEMINI_API_KEY** (string) - Your Google AI Studio API Key. - **GCP_PROJECT_ID** (string) - Your Google Cloud Platform Project ID (for Vertex AI). - **GCP_LOCATION** (string) - The location for Google Cloud Vertex AI services (e.g., `us-central1`). ### Usage Environment variables are used as a fallback when CLI arguments are not provided. CLI arguments take precedence over environment variables. ### Example ```bash # Google AI Studio API Key export GEMINI_API_KEY=your-api-key # Google Cloud Platform / Vertex AI export GCP_PROJECT_ID=my-gcp-project export GCP_LOCATION=us-central1 ``` ``` -------------------------------- ### Configure Vertex AI for Extraction Source: https://context7.com/nicodds/gemini-data-extractor/llms.txt Authenticate using Google Cloud SDK to utilize Vertex AI endpoints for document extraction. ```bash gcloud auth application-default login export GCP_PROJECT_ID=my-gcp-project export GCP_LOCATION=us-central1 gemini-data-extractor --path document.pdf --prompt-text "Extract all text content as JSON" ``` -------------------------------- ### Usage with Prompt File: Extract Data from Image Source: https://github.com/nicodds/gemini-data-extractor/blob/master/README.md Shows how to use a separate text file for the prompt when extracting data from an image file. This is useful for longer or more complex prompts. ```bash gemini-data-extractor --path path/to/your/file.png --prompt-file path/to/your/prompt.txt ``` -------------------------------- ### Initialize ApiCaller Class Source: https://context7.com/nicodds/gemini-data-extractor/llms.txt Initialize the Python ApiCaller class using either an API key or Google Cloud project credentials. ```python from gemini_data_extractor.api_caller import ApiCaller # Initialize with API key caller = ApiCaller(api_key="your-gemini-api-key") # Initialize with Google Cloud credentials caller = ApiCaller(project_id="my-gcp-project", location="us-central1") ``` -------------------------------- ### Extract Data via CLI Source: https://context7.com/nicodds/gemini-data-extractor/llms.txt Use the command-line interface to process files using either inline prompt text or external prompt files. ```bash export GEMINI_API_KEY=your-api-key gemini-data-extractor --path document.pdf --prompt-text "Extract the following fields as JSON: name, email, phone number" gemini-data-extractor --path scanned_id.pdf --prompt-file extraction_prompt.txt ``` -------------------------------- ### Python API: Extract Data from Documents Source: https://context7.com/nicodds/gemini-data-extractor/llms.txt Demonstrates how to use the ApiCaller class to extract data from different file types like PDFs and images. The tool automatically detects MIME types and supports various document formats. It requires an API key for authentication and accepts either prompt text or a file path for processing. ```Python from gemini_data_extractor.api_caller import ApiCaller caller = ApiCaller(api_key="your-gemini-api-key") # Process a PDF document pdf_result = caller.extract( prompt_text="List all section headings as a JSON array", prompt_file=None, path="report.pdf" ) # Process a PNG image image_result = caller.extract( prompt_text="Extract all visible text from this receipt image as JSON", prompt_file=None, path="receipt.png" ) # Process a JPEG photo photo_result = caller.extract( prompt_text="Identify objects in this image and return as JSON array", prompt_file=None, path="photo.jpg" ) # The MIME type is automatically detected from file extension # Supported: application/pdf, image/png, image/jpeg, etc. ``` ```Python try: result = caller.extract( prompt_text="some prompt", prompt_file="some_file.txt", path="document.pdf" ) except ValueError as e: print(e) # "Either prompt_text or prompt_file must be provided" ``` -------------------------------- ### Python API: Processing Different File Types Source: https://context7.com/nicodds/gemini-data-extractor/llms.txt Demonstrates how to use the ApiCaller to extract data from PDF, PNG, and JPEG files. The tool automatically detects MIME types. ```APIDOC ## Python API: Processing Different File Types ### Description The tool automatically detects MIME types and supports various document formats including PDFs and images. ### Method `ApiCaller.extract()` ### Parameters #### Request Body (Implicit via arguments) - **prompt_text** (string) - Required - The text prompt to guide the extraction. - **prompt_file** (string) - Required - Path to a file containing the prompt. Either `prompt_text` or `prompt_file` must be provided, not both. - **path** (string) - Required - Path to the document file (PDF, PNG, JPEG, etc.) to be processed. ### Request Example ```python from gemini_data_extractor.api_caller import ApiCaller caller = ApiCaller(api_key="your-gemini-api-key") # Process a PDF document pdf_result = caller.extract( prompt_text="List all section headings as a JSON array", prompt_file=None, path="report.pdf" ) # Process a PNG image image_result = caller.extract( prompt_text="Extract all visible text from this receipt image as JSON", prompt_file=None, path="receipt.png" ) # Process a JPEG photo photo_result = caller.extract( prompt_text="Identify objects in this image and return as JSON array", prompt_file=None, path="photo.jpg" ) ``` ### Notes - The MIME type is automatically detected from the file extension. - Supported formats include: `application/pdf`, `image/png`, `image/jpeg`, etc. ``` -------------------------------- ### Extract Data via Python API Source: https://context7.com/nicodds/gemini-data-extractor/llms.txt Process documents programmatically using the extract method with either inline strings or prompt files. ```python from gemini_data_extractor.api_caller import ApiCaller caller = ApiCaller(api_key="your-gemini-api-key") # Extract using inline prompt result = caller.extract(prompt_text="Extract invoice details as JSON", path="invoice.pdf") # Extract using prompt file result = caller.extract(prompt_file="prompts/identity_extraction.txt", path="scanned_document.pdf") ``` -------------------------------- ### Define Data Extraction JSON Schema Source: https://github.com/nicodds/gemini-data-extractor/blob/master/examples/prompt_001.txt This snippet represents the expected JSON output format for the data extraction process. It defines the required fields and their respective data types for person identification. ```json { "name": "Mark", "surname": "Twain", "sex": "M", "birth_date": "1835-11-30" } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.