This is a simple Flask application that provides an API endpoint for processing images using Amazon Textract. The API receives an image file through a POST request, extracts text using Amazon Textract, and returns the extracted text along with the processing time.
Before running the application, make sure you have the following:
- AWS account with Textract service enabled.
- AWS Access Key ID and Secret Access Key with appropriate permissions set in your environment variables.
- Python installed on your system.
-
Clone the repository:
git clone https://github.com/your_username/flask-textract-api.git
-
Navigate to the project directory:
cd flask-textract-api
- Install the required Python packages:
pip install -r requirements.txt
- Create a .env file in the project root directory and add the following environment variables:
AWS_ACCESS_KEY_ID=your_access_key_id
AWS_SECRET_ACCESS_KEY=your_secret_access_key
Replace your_access_key_id and your_secret_access_key with your AWS Access Key ID and Secret Access Key.
Run the Flask application:
python app.py
The application will be accessible at http://localhost:5000 by default.
- Endpoint:
/
- Method:
POST
- Request Body:
- Form parameter:
image
(image file)
- Form parameter:
curl -X POST -F "image=@path/to/your/image.jpg" http://localhost:5000/
{
"processing_time": 1.472205400466919,
"text": " Human Resources Développement des Development Canada ressources humaines Canada SOCIAL NUMÉRO INSURANCE D'ASSURANCE NUMBER SOCIALE 000 000 000 NAME HERE"
}
This application is configured to run on a local development server (host='0.0.0.0'). For production deployment, consider using a production-ready server like Gunicorn or deploying it on a platform like AWS Elastic Beanstalk.
Feel free to contribute to this project by creating issues or submitting pull requests.