This Flask application utilizes machine learning models from the Hugging Face transformers library to generate embeddings for input texts and find the most similar text in a predefined knowledge base. It leverages the power of pre-trained models for understanding and comparing text data, making it useful for applications requiring text similarity, question answering, or recommendation systems.
- Generate Embeddings: Converts input texts into dense vector representations using a pre-trained model.
- Text Similarity: Finds the most similar text in the knowledge base to the input query.
- REST API: Offers a simple RESTful API endpoint for processing text similarity queries.
-
Clone the Repository
git clone https://your-repository-url.git cd your-project-directory -
Setup Environment
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install Dependencies
Install the required packages using
pip:pip install -r requirements.txt
-
Run the Application
Start the Flask application locally:
python main.py
Or use the provided
start.shscript:./start.sh
To test the application, use the /chat endpoint to send a POST request with a JSON body containing the text for which you want to find a similar match.
- Method: POST
- URL:
http://localhost:5000/chat - Headers:
- Content-Type: application/json
- Body:
{ "text": ["Your text here"] }
Replace "Your text here" with the actual text you want to find similarities for.
The response will be a JSON object containing the most similar text from the knowledge base:
{
"response": ["Similar text response"]
}Refer to the provided Dockerfile for containerizing and deploying the application using Docker.
Ensure you have Docker installed and configured if you plan to deploy the application using a Docker container. For deploying on cloud platforms like AWS EC2, additional setup for security and environment variables might be required.