This Flask API calculates the similarity between two text sentences using the Sentence Transformers library. It utilizes pre-trained models to convert text into embeddings and computes the cosine similarity between them.
- Python 3.x
- Flask
- Sentence Transformers
Install the required Python packages using the following command:
pip install flask sentence-transformers
-
Clone this repository to your local machine.
-
Open a terminal and navigate to the project directory.
-
Run the Flask API using the following command:
python app.py
This will start the API locally on
http://localhost:8080
. -
Use a tool like
curl
orPostman
to send POST requests to the API with JSON data containing two text sentences for which you want to calculate similarity. Example:curl -X POST -H "Content-Type: application/json" -d '{"text1": "First sentence", "text2": "Second sentence"}' http://localhost:8080
-
The API will respond with a JSON object containing the similarity score between the two sentences.
-
POST /
-
Request:
{ "text1": "First sentence", "text2": "Second sentence" }
-
Response:
{ "similarity score": 0.85 }
-