This project is a FastAPI-based image processing pipeline API that automatically processes images, generates thumbnails, extracts metadata, and provides analysis through API endpoints.
The Image Processing Pipeline API is a FastAPI-based application that automates the processing of uploaded images. It generates thumbnails, extracts metadata, and uses AI to caption images. The processed results are made available through RESTful API endpoints.
- Image Upload: Accepts image uploads in JPG or PNG formats.
- Metadata Extraction: Extracts basic metadata like dimensions, file format, and file size, and store them in memory.
- In-Memory Storage: Stores processesed results in memory for quick retrieval.
- Thumbnail Generator: Automatically generates small and medium sized thumbnails for each uploaded image.
- AI-Powered Captioning: Uses the Blip Image Captioning by Salesforce
The flowchart below represents what happens when a file is uploaded using the API
Do refer to here for the processing pipeline documentation.
Do refer to this section for the API endpoints documentation.
- FastAPI: For building the pipeline API.
- Uvicorn: For running the FastAPI server.
- Pillow: Used for image processing and thumbnail generation.
- Transformers: Used for the AI-powered image captioning.
Follow the steps to set up the project on your local machine.
- Python 3.8 or higher
- To verify, enter
python -V
in CMD.
- To verify, enter
- pip
- Postman
- Clone this repository
git clone https://github.com/your-username/your-repo-name.git
cd repo-folder
- Install Dependencies
pip install -r requirements.txt
- Start the FastAPI server
- Running in CMD:
cd repo-folder
python3 main.py
- Runing in VSCode
Run with Debugger, choosing the options Python > FastAPI.
🠪 The API will be available at http://localhost:8000 or http://127.0.0.1:8000
To view the API documentation, see here under Documentations folder.
All of these are done in Postman in this section:
Send a POST request to /api/images with an image file to process it.
How To:
- In Postman, in the Body tab, for form-data input, include the **Key** as "file" and **Value* as an uploaded file in your local machine.
Send a GET request to /api/images to retrieve all images and their metadata details.
Send a GET request to /api/images/{image_id} to retrieve that image's metadata details.
Send a GET request to **/api/images/{image_id}/thumbnails/{size} to retrieve a thumbnail (small or medium).
How To:
- In Postman, select the GET option, input the URL as shown and send the request.
- Thumbnails request can be small or medium.
- Creating a job queue for images coming in
- Handle the images asynchronously
- Dockerise the project
- Blip Image Captioning by Salesforce: [https://huggingface.co/Salesforce/blip-image-captioning-base]
- FastAPI Documentation: [https://code.visualstudio.com/docs/python/tutorial-fastapi]
- List of HTTP status codes: [https://en.wikipedia.org/wiki/List_of_HTTP_status_codes]
- UUID Documentation: [https://docs.python.org/3/library/uuid.html]
- Getting file's creation and modification dates: [https://docs.vultr.com/python/examples/get-file-creation-and-modification-date]
- AI used to resolve following errors:
- time format for when the image is processed at (eg. "processed_at": "2024-03-10T10:00:00Z")
- resolve errors in running uvicorn
- resolve deprecated usage of time format (see test case readme)