Implementation of Streamlit web Application
pip install streamlit
- We Run this command to install streamlit dependencies in our program
import streamlit as st
# Define function to predict academic assistance need based on learner details
def predict_academic_assistance(age, gender):
# Simple rule-based prediction:
# If the learner is under 18 years old or if the learner is female, predict that academic assistance is needed
if age < 18 or gender == "Female":
return 1 # Academic assistance likely needed
else:
return 0 # Academic assistance not likely needed
# Define Streamlit application
def main():
st.title("Academic Assistance Predictor")
# Collect learner details from user input
age = st.number_input("Enter Age", min_value=0, max_value=120, step=1)
gender = st.selectbox("Select Gender", ["Male", "Female"])
# Predict academic assistance need
if st.button("Predict"):
prediction = predict_academic_assistance(age, gender)
if prediction == 1:
st.error("This learner likely needs academic assistance.")
else:
st.success("This learner does not likely need academic assistance.")
if __name__ == "__main__":
main()
Import Streamlit Library:
Purpose: This line imports the Streamlit library, which is used for creating simple web applications quickly. Streamlit allows developers to build interactive and attractive web apps solely with Python, without the need for front-end technologies like HTML, CSS, or JavaScript.
Define Prediction Function:
Function Overview: This function, predict_academic_assistance, uses a simple rule-based logic to determine if a learner might need academic assistance.
Parameters:
age: Learner's age.
gender: Learner's gender.
Logic: If the learner is under 18 years old or if the learner is female, the function predicts that academic assistance is needed (return 1). Otherwise, it predicts that academic assistance is not needed (return 0).
Define Streamlit Application:
Application Setup:
st.title(): Sets the title of the web application.
Input Widgets:
st.number_input(): Creates a numeric input for age, with specified minimum and maximum values and a step size.
st.selectbox(): Creates a dropdown menu for selecting gender.
Prediction Trigger:
st.button(): Adds a button that users can click to trigger the prediction. When the button is pressed, predict_academic_assistance is called with the user inputs.
Display Results:
st.error() and st.success(): These functions display the prediction results as either an error message (indicating assistance is needed) or a success message (indicating no assistance is needed).
Run the Streamlit Application:
This conventional Python boilerplate checks if the script is the main program and not being imported as a module. If it is the main program, it calls the main() function, which starts the Streamlit application.
When the App is run you get this output:



Comments
Post a Comment