This repository contains a Flask application named "Embedder" that processes text inputs, splits them into chunks, computes embeddings for each chunk, and returns the processed data in JSON format. Additionally, it includes a Docker setup for containerization and a GitHub Actions workflow for Continuous Integration and Continuous Deployment (CI/CD).
The main file of the Flask application is app.py
, which defines the following functionalities:
- Receives a POST request at the endpoint
/process_text
. - Processes the text input by splitting it into chunks and computing embeddings for each chunk.
- Returns the processed data in JSON format.
You can test the Flask application using the following payload with curl:
curl -X POST -H "Content-Type: application/json" -d '{"text": "Hello world!"}' http://127.0.0.1:5000/process_text
This is the result:
The Dockerfile
sets up the Docker environment for the Flask application. It installs necessary packages, sets the working directory, copies application files, installs dependencies, exposes port 5000, and specifies the command to run the Flask app.
The main.yml
file defines the GitHub Actions workflow for CI/CD. It consists of the following steps:
- Sets up the Python environment with version 3.10.
- Installs project dependencies.
- Lints the code using pylint.
- Formats the code using black.
- Builds the Docker image.
- Pushes the Docker image to DockerHub.
The CI/CD process ensures that changes to the codebase are tested, linted, and formatted automatically. It also automates the Docker image build and pushes it to DockerHub, enabling seamless deployment and version control.
The Makefile
simplifies common development tasks with the following commands:
venv
: Sets up a virtual environment.install
: Installs project dependencies.format
: Formats the code using black.lint
: Lints the code using pylint.docker
: Builds the Docker image.
To run the Flask application locally, ensure you have Python 3.10 and the required dependencies installed. Then, follow these steps:
- Create a virtual environment:
python -m venv venv
- Activate the virtual environment:
- On Windows:
venv\Scripts\activate
- On macOS/Linux:
source venv/bin/activate
- On Windows:
- Install project dependencies:
pip install -r requirements.txt
- Run the Flask app:
python app.py
For Docker usage, ensure Docker is installed on your machine and run the following commands:
- Build the Docker image:
make docker
- Run the Docker container:
docker run -p 5000:5000 bugarin10/embedder:latest