Running Streamlit code in Google Colab involves a few steps. Streamlit is a Python library that is typically used to create web applications for data science and machine learning projects. Google Colab, on the other hand, is a cloud-based platform that allows you to run Python code in a Jupyter Notebook-like environment. Here’s a step-by-step guide on how to run Streamlit code in Colab:
Start by installing Streamlit in your Colab environment. You can do this by running the following command in a Colab cell:
! pip install streamlit -q
The second line (!wget -q -O - ipv4.icanhazip.com
) retrieves your external IP address using the wget
command.
!wget -q -O - ipv4.icanhazip.com
Copy IP address
The line %%writefile app.py
writes the Streamlit app code to a file named app.py
. The Streamlit app itself is a simple calculator. It takes two input numbers, adds them together, and displays the result.
The line !streamlit run app.py &
runs the Streamlit app in the background. The &
at the end allows the Colab notebook to continue executing other cells without waiting for the Streamlit app to finish.
!npx localtunnel --port 8501
uses npx localtunnel
to expose the locally running Streamlit app to the internet. The app is hosted on port 8501, and localtunnel
provides a public URL through which the app can be accessed.
Done ! Wow it’s work
Feel free to contact if you have any doubt