-
Installation:
- First, you need to install Streamlit. You can do this by running the following command in your terminal or command prompt:
pip install streamlit
- This command installs Streamlit, which is a Python library for creating interactive web apps from data scripts.
- First, you need to install Streamlit. You can do this by running the following command in your terminal or command prompt:
-
Creating a Streamlit App:
- Next, create a Python file (let's call it
hello.py
). - Inside
hello.py
, you'll write your Streamlit app.
- Next, create a Python file (let's call it
-
Streamlit Basics:
- The code you provided is an example of a simple Streamlit app.
- Let's go through each part:
import streamlit as st st.title("Hello World")
st.title("Hello World")
: This line sets the title of your app to "Hello World". When you run your Streamlit app, you'll see this title displayed.
st.write("This is Rafi Ali")
st.write("This is Rafi Ali")
: This line displays the text "This is Rafi Ali" on your app. You can usest.write()
to show any text or data.
st.markdown("# Markdown content")
st.markdown("# Markdown content")
: This line renders a markdown heading (level 1) with the text "Markdown content". You can usest.markdown()
to display formatted text using Markdown syntax.
st.code("""if post == "good": print("Hit Like")""")
st.code("""if post == "good": print("Hit Like")""")
: This line displays code in a code block. The code snippet checks if the variablepost
is equal to "good" and prints "Hit Like" if the condition is true.- Note that
post
is not defined in the provided code snippet, so you'd need to define it elsewhere in your app.
-
Running the App:
- After creating
hello.py
, run it using the following command:streamlit run hello.py
- This command starts a local web server and opens your app in a web browser at
http://localhost:8501/
.
- After creating
-
Interacting with Your App:
- When you visit the local URL, you'll see your Streamlit app with the title, text, markdown, and code snippet displayed.
- You can modify the code in
hello.py
and see the changes reflected in real-time as you save the file.
Streamlit makes it easy to create interactive web apps directly from your Python code, without needing to write HTML, CSS, or JavaScript. It's a great tool for data science and machine learning projects! 😊🚀
Follow me on LinkedIn: www.linkedin.com/comm/mynetwork/discovery-see-all?usecase=PEOPLE_FOLLOWS&followMember=therafiali