This project provides an API to analyze documents for signatures, company stamps, and duty stamps (meterai) using the Gemini model.
project/
├── images
├── __init__.py
├── main.py
├── api.py
├── config.py
├── utils.py
├── pdf_processor.py
└── .env
Follow these steps to set up the project:
-
Clone the repository:
git clone https://github.com/your-repo/signature-stamp-analysis.git
-
Navigate to the project directory:
cd signature-stamp-analysis -
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install the required dependencies:
pip install -r requirements.txt
-
Create a
.envfile with your project credentials:PROJECT_ID=your-project-id CREDENTIALS_FILE_PATH=/path/to/your/credentials.json GEMINI_MODEL=name-of-gemini-model
To start the FastAPI application, run:
uvicorn main:app --host 0.0.0.0 --port [port]The application will be available at http://localhost:[port]
The API documentation will be available at http://localhost:[port]/docs
- Endpoint:
POST /analyze - Description: Analyze a document for signatures, stamps, and duty stamps (meterai).
- Parameters:
file: Upload a document file (PDF, PNG, JPEG)url: Provide a URL to the document file
Example usage with URL:
import requests
url = 'http://localhost:[port]/analyze'
file_url = 'https://example.com/yourfile.pdf'
data = {
'url': file_url
}
response = requests.post(url, data=data)
print(response.status_code)
print(response.json())Example usage with FILE_PATH:
import requests
url = 'http://localhost:[port]/analyze'
file_path = 'path/to/yourfile.pdf'
files = {'file': open(file_path, 'rb')}
response = requests.post(url, files=files)
print(response.status_code)
print(response.json())The project uses a .env file to manage environment variables. Ensure you have the following variables set:
PROJECT_ID: Your Google Cloud project IDCREDENTIALS_FILE_PATH: Path to your Google Cloud service account credentials fileGEMINI_MODEL: Model Name for Gemini API
Explanation of the project directory structure:
__init__.py: Initializes the project modulemain.py: Defines the FastAPI app and includes routingapi.py: Contains API endpoint definitionsconfig.py: Handles project configuration and Vertex AI initializationutils.py: Utility functions for content analysis and PDF processingpdf_processor.py: Handles PDF processing and conversion to images.env: Environment variables file
Ensure that the images for sample duty stamp and company stamp are located in the images directory.