Open In App

Blood Pressure Analysis GUI Using Gradio in Python

Last Updated : 30 Dec, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

This article will teach you to create a basic GUI using Gradio to analyze blood pressure in Python.

Gradio is an open-source library that helps coders effortlessly create User Interface(UI) components for functions with minimal lines of code.

Based on the systole and diastole values of a patient’s blood pressure in mmHg, the task is to analyze whether the patient has normal blood pressure, elevated blood pressure, and so on.

Understanding the Problem

Two parameters have to be provided to the bp function that checks for the normalcy of blood pressure values. The parameters are:

  1. systole is the blood pressure reading measured when the heart beats
  2. diastole is the blood pressure reading measured when the heart rests between the beats.

For convenience in the analysis, we assume that the above parameters are entered in mmHg units.
Now, based on the parameters, the following conclusions are reached by the function:

  1. If systole is less than 120 mmHg and diastole is less than 80 mmHg then the message given below is returned :
    “Normal Blood Pressure”
  2. If systole lies in the range of 120-129 mmHg and diastole is less than 80 mmHg then the following message is returned:
    “Elevated Blood Pressure”
  3. If systole lies in the range of 130-139 mmHg or if diastole falls between 80-89 mmHg range then the message given below is returned
    “First Stage High Blood Pressure”
  4. If none of the conditions is satisfied then the following message is returned:
    “Second Stage High Blood Pressure”

Install the required Packages

First and foremost we need to add the gradio package to our system. To install the gradio run the following command in the terminal:

pip install gradio

Algorithm

In order to analyze the systole and diastole values of the patient’s blood pressure, the steps given below are followed:

  1. Import Gradio as gr
  2. Create a function called bp that accepts systole and diastole values as parameters
  3. Within the bp function, follow the interpretation of inputs given above by creating an if-elif ladder and return the messages accordingly.
  4. Create Gradio Interface stored into the ‘interface’ variable and specify the input and output types.
  5. Launch the interface to obtain the “Analysis of Blood Pressure” UI using the interface.launch() method.

Following is an implementation of the algorithm stated above:

Python




# importing Gradio
import gradio as gr
  
# creating a function bp that has systole and
# diastole as parameters
def bp(systole,diastole):
    
  # interpreting the systole and diastole values
  if((systole<120) and (diastole<80)):
    return ("Normal Blood Pressure")
  
  elif ((systole>=120 and systole<130
  and (diastole<80)):
    return ("Elevated Blood Pressure")
  
  elif ((systole>=130 and systole<140
  or (diastole>=80 and diastole<=89)):
    return ("First Stage High Blood Pressure")
  
  else:
    return ("Second Stage High Blood Pressure")
  
  
# creating an interface
interface=gr.Interface(fn=bp,inputs=["number","number"],
outputs=['text'],title="ANALYSIS OF BLOOD PRESSURE")
  
# launching the interface
interface.launch()


Output:

When the interpreter runs the interface.launch() command it prints out the following as output:

Gradio interface.launch() output

Gradio interface.launch() output

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

Resulting Gradio GUI

Resulting Gradio GUI



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads