Dockerizing and Running AI model
This is a simple gradio app that uses the BLIP model to generate captions for images.
Usage
- Upload an image to the app.
- The app will generate a caption for the image.
- You can copy the caption and use it as a title for your blog post or any other purpose.
Dependencies
- git/github
- gradio
- transformers
- Pillow
- torch
Run the App In Local Environment
- Clone the repo from github
git clone https://github.com/lalitmahato/image-caption-generator.git
- Make virtual environment and activate it.
Fow Windows
python -m venv venv
venv\Scripts\activate.bat
For Linux
virtualenv venv
source venv/bin/activate
- Install the required dependencies
pip install -r requirements.txt
- Run the app.
python3 app.py
- Open your web browser and navigate to
http://localhost:7860
.
https://localhost:7860
- Upload an image and click "Submit" to see the caption generated for the image inside the output box.
Run the App using Docker
Using Dockerfile only
- Uncomment the following line inside the Dockerfile.
#EXPOSE 7860
#CMD ["python", "app.py"]
The Dockerfile looks like after change
FROM python:3.12-slim
ENV PYTHONUNBUFFERED 1
WORKDIR /code
ADD ./ /code
RUN pip install -r /code/requirements.txt
EXPOSE 7860
CMD ["python", "app.py"]
- Build the Docker image
docker build -t image_caption_generator .
- Run the Docker container
docker run -p 7860:7860 image_caption_generator
- Verify the container is running
docker ps
- Open your web browser and navigate to
http://localhost:7860
.
Using Dockerfile and docker-compose.yml file
- Comment the following line inside the Dockerfile.
EXPOSE 7860
CMD ["python", "app.py"]
The Dockerfile looks like after change
FROM python:3.12-slim
ENV PYTHONUNBUFFERED 1
WORKDIR /code
ADD ./ /code
RUN pip install -r /code/requirements.txt
#EXPOSE 7860
#CMD ["python", "app.py"]
- Build the Docker image using
docker-compose.yml
andDockerfile
docker-compose -f docker-compose.yml up -d --build
Above command build the image and run the container in detach mode.
- Verify the container is running
docker ps
- Open your web browser and navigate to
http://localhost:7860
.
http://localhost:7860