CODING JOY

The stunning potpourri of coding and mundane life

CHOLESTROL LEVEL ANALYZER GUI IN PYTHON



AMRUHA AHMED
27th March,2023.


This article will help you create a cholesterol level analyser using Gradio library in Python.
Gradio is an open-source library that helps coders to effortlessly create User Interface UI components for functions with minimal lines of code.


Based on the readings of total cholesterol, LDL cholesterol,HDL cholesterol and triglycerides of a patient’s blood sample taken in mg/dL obtained from Cholesterol Test/ Lipid Profile, the task at hand is to interpret these readings and check whether the patient has an ideal level of cholesterol or not.


blog1

DELVING DEEPER:

Four parameters need to be provided to the “cholcheck” function that checks the normalcy of cholesterol level. The parameters are as follows:
1.total_cholesterol: this is the total of the blood sample’s cholesterol content
2.ldl_cholesterol: LDL is Low Density Lipoprotein. This is called as the “Bad cholesterol”
3.hdl_cholesterol: HDL is High Density Lipoprotein.This is also known as “Good Cholesterol”
4.triglycerides:this is a form of fat in the body which is harmful in large quantities.


For convenience during analysis, the above parameters are assumed to be in mg/dL.
Based on the parameters specified, the following conclusions are reached by the “cholcheck” function:
blog1

ALGORITHM:

1.Install Gradio library
2.Import Gradio as gr
3.Create a “cholcheck” function that accepts total cholesterol, LDL cholesterol,HDL cholesterol and triglycerides as parameters .
4.Within the “cholcheck” function, the interpretation of inputs as shown above is followed and appropriate messages are returned.
5.Create a Gradio interface, stored in ‘interface’ variable.Here, the input and output types, as well as the underlying function name need to be specified.
6.Launch the interface by using interface.launch() to obtain the GUI of cholesterol level analyzer.


The following is the implementation of the algorithm stated above:


                

! pip install gradio
#installing gradio
import gradio as gr#importing gradio library
#creating a function cholcheck that accepts total_cholesterol,ldl_cholesterol,hdl_cholesterol,triglycerides as parameters in terms of mg/dL

def cholcheck(total_cholesterol,ldl_cholesterol,hdl_cholesterol,triglycerides):
  #interpreting cholestrol test values
  if(total_cholesterol<200 and ldl_cholesterol<130 and hdl_cholesterol>50 and triglycerides<200):
    return("Ideal Level of cholesterol")
  elif((total_cholesterol>=200 and total_cholesterol<=239) and (ldl_cholesterol>=130 and ldl_cholesterol<=159) and (hdl_cholesterol>=40 and hdl_cholesterol<=49) and (triglycerides>200 and triglycerides<=399)):
    return("Borderline High Level of Cholesterol detected")
  else:
    return("High Levels of Cholesterol detected")

interface=gr.Interface(fn=cholcheck,inputs=["number","number","number","number"],outputs=['text'],title="CHOLESTROL TEST ANALYSER")
interface.launch()
                   
             
         
CODE COPIED

OUTPUT:


When interface.launch() is executed, the following output is displayed:

blog1

On clicking this link, the interface is displayed and the inputs are provided accordingly.