In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "how to write a Python script". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Streamlit is the first application development framework specifically for machine learning and data science teams. it is the fastest way to develop custom machine learning tools. you can think of it as a goal to replace Flask in machine learning projects and help machine learning engineers to quickly develop user interaction tools.
1 、 Hello world
Streamlit applications are Python scripts, there is no implicit state, you can use function call refactoring. As long as you can write Python scripts, you can develop Streamlit applications. For example, the following code outputs Hellograd worldstories in a web page:
Import streamlit as stst.write ('Hello, Worldwide')
The results are as follows:
2. Use UI components
Streamlit treats components as variables, there are no callbacks in Streamlit, and each interaction is simply returned, ensuring that the code is clean:
Import streamlit as stx = st.slider ('x') st.write (x, 'squared is', x * x)
The results are as follows:
3. Data reuse and computing
How do you do this if you want to download a lot of data or run complex calculations? The key is to reuse data securely. Streamlit introduces caching primitives to make Steamlit applications safe and easy to reuse information. For example, the following code only needs to download data from Udacity's self-driving car project once to get a simple, fast application:
Import streamlit as stimport pandas as pd# Reuse this data across runsreadreadsheets and installed cachets CSV = st.cache (pd.read_csv) BUCKET = "https://streamlit-self-driving.s3-us-west-2.amazonaws.com/"data = read_and_cache_csv (BUCKET +" labels.csv.gz ", nrows=1000) desired_label = st.selectbox ('Filter to:', [' car', 'truck']) st.write (data [data.label = = desired_label])
The results are as follows:
In short, Streamlit works as follows:
For each user interaction, the entire script is executed from beginning to end
Streamlit assigns values to variables based on the state of the UI component
Caching allows Streamlit to avoid duplicate requests for data or repeated calculations
Or refer to the following figure:
If the above is not clear, you can try Streamlit directly!
$pip install-upgrade streamlit
$streamlit hello
You can now view your Streamlit app in your browser.
Local URL: http://localhost:8501
Network URL: http://10.0.1.29:8501
This automatically opens the local web browser and accesses the Streamlit application:
4. Example: autopilot dataset tool
The following Streamlit application allows you to semantically search the entire Udacity self-driving vehicle photo dataset, visualize manual tagging, and run a YOLO target detector in real time:
The whole application has only 300 lines of Python code, most of which are machine learning code. In fact, there are only 23 Streamlit calls. You can try to run it yourself:
That's all for $pip install-how to write Python scripts for upgrade streamlit opencv-python$ streamlit run https://raw.githubusercontent.com/streamlit/demo-self-driving/master/app.py". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.