Master Streamlit: Build & Launch Your App in Minutes

Master Streamlit: Build & Launch Your App in Minutes

Ready to bring your ideas to life? Dive into the world of Streamlit, where creating interactive apps is as easy as a few lines of code! In this tutorial, I'll guide you through crafting your very first Streamlit app, from inception to deployment. Whether you're a coding novice or an experienced developer, join me on this journey to unleash the power of Streamlit and transform your concepts into functional, live applications with ease! Lets create a simple BMI Calculator


Firstly create a virtual Environment using anaconda prompt:

conda create --name streamlitpy python=3.12
conda activate streamlitpy
pip install streamlit
        

Open VS code and activate the environment there. Create a folder name bmi-calculator and in it a file named app.py Write the following code to create a simple BMI calculator:

import streamlit as st

st.title("BMI Calculator")

#function to calculate BMI
def bmi_calc(height, weight):
    bmi = weight / (height ** 2)
    return bmi

col1,col2= st.columns(2)

with col1:
    height = st.number_input("Height (in m)")
with col2:
    weight  = st.number_input("Weight (in kg)")

submit = st.button("Calculate BMI")
if submit:
    bmi = bmi_calc(height, weight)
    st.write("Your BMI is: ", bmi)
    if bmi < 18.5:
        st.warning("You are Underweight")
    elif bmi >= 18.5 and bmi < 25:
        st.success("You are Healthy")
    elif bmi >= 25 and bmi < 30:
        st.warning("You are Overweight")
    elif bmi >=30:
        st.error("You are Obese")
        

To run the application simply type:

streamlit run app.py        

Your output will be displayed like this:

BMI app build using streamlit

Now to deploy it to streamlit cloud just click the deploy link in the top right corner but you need to firstly upload the code to GitHub and link it to streamlit cloud. After successfully uploading code to GitHub your live app will be available for all to use.

Watch the Youtube Video to learn all basic of streamlit:

live Demo link:

Streamlit (zeeshan080-streamlit-app-app-nxl2ns.streamlit.app)

要查看或添加评论,请登录

社区洞察

其他会员也浏览了