This repo contains files to code that deploys an API endpoint for a user to detect text similarity between 2 texts without the use of any libraries.
The directory structure is provided below.
.
├── Dockerfile
├── DocumentSimilarity.py
├── LICENSE
├── README.md
├── constants.py
├── requirements.txt
├── server.py
├── similarity_scorer.py
├── templates
├── base.html
├── index.html
└── output.html
Listed below are different ways to build and run the system. There are a total of 3 ways to build and run the system. They are:
- Build from the git repo.
- Build using docker image.
-
Clone the project Git repo.
foo@bar:~$ git clone https://github.com/likith11/text-similarity-scorer.git
-
Move into the project directory.
foo@bar:~$ cd text-similarity-scorer
-
Create a virtual environment and activate it.
foo@bar:~$ python3 -m venv venv foo@bar:~$ source venv/bin/activate
-
Install requirements from requirements.txt
(venv) foo@bar:~$ pip install -r requirements.txt
(venv) foo@bar:~$ python similarity_scorer.py "Text 1 goes here" "Text 2 goes here"
NOTE: Here "Text 1 goes here" and "Text 2 goes here" are 2 strings that are passed as the arguments. Replace text within double quotes to pass custom input. For more help pass -h after the executable file. A similarity score is displayed as output.
(venv) foo@bar:~$ python server.py
GUI Steps:
- Navigate to http://0.0.0.0:5000/ or http://localhost:5000/ (Replace port number if its a different port on your machine. The default port above is 5000).
- Two text areas with label Text Area 1 and Text Area 2 along with a blue Process button is displayed.
- Input text to be compared to the text boxes.
- Click on Process_
- A new screen with Translucent alert box is shown with the corresponding Similarity Score calculated
- Click on Retry? button to go back to the main screen and repeat the process.
API Call:
- API end point is deployed at http://0.0.0.0:5000/api/similarity where POST request is accepted.
- The API accepts text inputs in the JSON format of
{ "text_one" : "Text 1 goes here", "text_two" : "Text 2 goes here" }
- An example curl command is
curl -d '{"text_one" : "Text 1 goes here", "text_two" : "Text 2 goes here"}' -H 'Content-Type: application/json' http://0.0.0.0:5000/api/similarity
- An API response json is returned with the similarity score.
- Pull image from docker hub.
foo@bar:~$ docker pull likithponnanna/python-similarity:submission
- Run the image that was pulled. Below port 5000 is mapped between the external and docker container.
foo@bar:~$ docker run -p 5000:5000 python-similarity
- NOTE : To run the server follow the steps mentioned in section 1.2 API Call.
- [OPTIONAL] To build the docker image using the dockerfile locally run the following command before initiating docker run.
foo@bar:~$ git clone https://github.com/likith11/text-similarity-scorer.git foo@bar:~$ cd text-similarity-scorer foo@bar:~$ docker build -t python-similarity .