This project uses Python FastAPI to build AI applications. It leverages the transformers
library for model processing and Pillow
for image handling.
- Python 3.9 or higher
- Docker
To install the required dependencies, run:
pip install -r requirements.txt
To run the application locally, execute:
sh uvicorn main:app --reload --port 8000 --host 0.0.0.0
To build and run the application using Docker, use the following command:
sh docker compose up --build
Your application will be available at http://localhost:8000.
GET /
Returns a simple greeting message.
POST /ask
Accepts a text question and an image file, and returns the answer based on the AI model.
- [
text
] (str): The question to ask. - [
image
] (UploadFile): The image file to analyze.
The model pipeline is defined in [model.py
]. It uses the [ViltProcessor
] and [ViltForQuestionAnswering
] from the [transformers
] library to process the input image and text.
from transformers import ViltProcessor, ViltForQuestionAnswering
from PIL import Image
processor = ViltProcessor.from_pretrained("dandelin/vilt-b32-finetuned-vqa")
model = ViltForQuestionAnswering.from_pretrained("dandelin/vilt-b32-finetuned-vqa")
def model_pipeline(text: str, image: Image):
# prepare inputs ...
The Docker configuration is defined in the [Dockerfile
] and [compose.yaml
] The application is built using a multi-stage build to optimize the image size and performance.
For more details on building and running the application with Docker, refer to [README.Docker.md
].