Dockerizing and Running AI model

August 05, 2025
25 min read
Lalit Mahato
Dockerizing and Running AI model

Dockerizing and Running AI model

This is a simple gradio app that uses the BLIP model to generate captions for images.

Usage

  1. Upload an image to the app.
  2. The app will generate a caption for the image.
  3. 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

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

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 and Dockerfile

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

http://localhost:7860

 

Tags

ai docker
Lalit Mahato

Lalit Mahato

Software Engineer | Machine Learning Enthusiast

Innovative and results-driven software developer with 5+ years of experience in designing, developing, and deploying high-quality software solutions. Proficient in various programming languages and technologies, with a keen interest in …

Comments (0)

No comments yet. Be the first to comment!

Leave a Comment

Search

Categories

Related Posts

Running First Docker Image
Running First Docker Image

Aug 05, 2025

Read More
Introduction to Docker and Containers
Introduction to Docker and Containers

Aug 05, 2025

Read More
Docker Installation Guide for Linux
Docker Installation Guide for Linux

Jul 07, 2025

Read More