Thursday, December 8, 2022

Configure localhost with secure https

 

Steps :

sudo apt install libnss3-tools -y 

wget https://github.com/FiloSottile/mkcert/releases/download/v1.4.3/mkcert-v1.4.3-linux-amd64 

sudo cp mkcert-v1.4.3-linux-amd64 /usr/local/bin/mkcert 

sudo chmod +x /usr/local/bin/mkcert 

mkcert -install

Now use your virtualhost name in the below command instead of app.localhost. You can generate same certificate for multiple virtualhosts. Add multiple virtualhosts space separated in the below command.

mkcert app.localhost localhost 127.0.0.1 

Use certificates in Apache ssl config, and restart Apache. Now open localhost and other virtualhosts in the browser. it should be secured.

Sunday, November 27, 2022

IBM / MAX Text Sentiment Analysis

Run an already trained model instance

git clone https://github.com/IBM/MAX-Text-Sentiment-Classifier.git
cd MAX-Text-Sentiment-Classifier
docker build -t max-text-sentiment-classifier .
docker run -it -p 5000:5000 max-text-sentiment-classifier
It will create a build in a docker container. We can check the application on port 5000.
http://localhost:5000

Open it by a domain / subdomain or it can be accessed by http://ip:5000
It will open a web interface. Since its model is already trained and it gives you output as positive and negative.

We need to pass the sentence and it will tell you, either the sentence is positive or negative. Once docker container is running, we can send the request using curl and collect the output in response.

curl -d "{ \"text\": [ \"The Model Asset Exchange is a crucial element of a developer's toolkit.\" ]}" -X POST "http://localhost:5000/model/predict" -H "Content-Type: application/json"

Response :

{
  "status": "ok",
  "predictions": [
    [
      {
        "positive": 0.9977352619171143,
        "negative": 0.0022646968718618155
      }
    ]
  ]
}

To Train the Model :

We are already in the folder MAX-Text-Sentiment-Classifier, cd into training folder. Create a virtual env.

cd training/
pip install -r requirements.txt
python setup_max_model_training.py max-text-classifier-training-config.yaml
Now this command will need account set up in IBM Cloud.  How much the output is accurate, it depends on the training tsv file.
https://cloud.ibm.com/login
Go On Manage > Access > API Keys > generate a key
Download the file apikey.json, copy on the server and Provide your key path.

Now run the docker instance, it will be launched based on this training.
docker build -t max-text-sentiment-classifier --build-arg use_pre_trained_model=false .
docker run -it -p 5000:5000 max-text-sentiment-classifier
Open url
http://ip:5000
Now it will give us the response with neutral output too as it has been trained based on the given tsv input.

To reset everything on cloud, delete Created service and Created storage in the cloud IBM account.
Remove all keys Entries from /etc/environment, exit or close the terminal, open and login again and run

python setup_max_model_training.py max-text-classifier-training-config.yaml
Note :

https://github.com/IBM/MAX-Text-Sentiment-Classifier


Saturday, November 19, 2022

Bash Sleep Sort

#!/bin/bash

function f() {
sleep "$1"
echo "$1"

}
while [ -n "$1" ]
do
f "$1" &
shift
done
wait

 Run the script.

./file.sh 6 1 3 7 8 4 2

Output :

It will sort the numbers and print them after 'printed number' seconds.

ex- 7 will be printed after 7 seconds.