This project contains the implementation of REST API and WEB APP empowered by Vision AI to detect and make the prediction for potential risk of skin cancer while provided with the image of skin.The model is trained using TensorFlow. The REST API services are being distributed through docker image. You can pull the image from Docker Hub.The image comes as the production ready with unit tests and standard algorithm implemented which can be used to expose the REST API to the web.
Following are the major contents to follow, you can jump to any section:
Clone the project
git clone https://github.com/Hassi34/Skin-Cancer-Detector-TF.gitGo to the project directory
cd Skin-Cancer-Detector-TFInstall dependencies
pip install -r requirements.txtStart the server
streamlit run app.pyTo run the following sequence of commands, make sure you have the docker installed on your system.
In case you have not already pulled the image from the Docker Hub, you can use the following command:
docker pull hassi34/skincancer-detectorNow once you have the docker image from the Docker Hub, you can now run the following commands to test and deploye the container to the web
docker imagesUse the following command to run a docker container on your system:
docker run --name <CONTAINER NAME> -p 80:80 -d <IMAGE NAME OR ID>Check if the container is running:
docker psIf the container is running, then the API services will be available on all the network interfaces
Type localhost in the brower and see if you get the success message from the API service.
- Perform Unit Tests
After when the API services are up and running, run the following command on the termial to perform the unit test:
docker exec -it <CONTAINER NAME OR ID> pytest- API documentation
The automatic API documentation will be available at http://localhost/docs
Use the following script as a reference to make a REST API request:
import requests
import base64
IN_IMG_PATH = "in.jpg" # You can give any name with the right extension
OUT_IMG_PATH = "out.jpg"
ENDPOINT = "http://127.0.0.1/predict"
def decodeImage(base64_str, OUT_IMG_PATH):
imgdata = base64.b64decode(base64_str)
with open(OUT_IMG_PATH, 'wb') as f:
f.write(imgdata)
f.close()
def encodeImageIntoBase64(IN_IMG_PATH):
with open(IN_IMG_PATH, "rb") as f:
return base64.b64encode(f.read())
if __name__ == '__main__':
BASE64_STR = encodeImageIntoBase64(IN_IMG_PATH).decode("utf-8")
response = requests.post(ENDPOINT, json={"base64_str":BASE64_STR})
if response.status_code == 200:
response = response.json()
print(response)
decodeImage(response["base64_str"], OUT_IMG_PATH)
else :
print(response)Copyright Β© 2023 Hasanain
Let's connect on LinkedIn