In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "how to install streamlit framework". In daily operation, I believe many people have doubts about how to install streamlit framework. Xiaobian consulted all kinds of materials and sorted out simple and easy operation methods. I hope to help you answer the doubts about "how to install streamlit framework"! Next, please follow the small series to learn together!
frame mounting
Installation of streamlit framework is very simple, using pip you can install:
pip install streamlit
After the installation is complete, you can verify the version using the command:
streamlit --version
In this article, I'll give you a brief introduction to using the streamlit framework with a real-world example.
project preparation
Collaborative-Distillation is an image stylization scheme that supports high resolution. The input of this model is stylized images and images to be processed, and the output is stylized images.
In this code repository, we need to use more complex command-line commands to perform stylized operations:
# use original VGG-19, normal imagesCUDA_VISIBLE_DEVICES=0 python WCT.py --debug --mode original# use original VGG-19, ultra-res imagesCUDA_VISIBLE_DEVICES=0 python WCT.py --debug --mode original --UHD# use our pruned VGG-19, normal imagesCUDA_VISIBLE_DEVICES=0 python WCT.py --debug --mode 16x# use our pruned VGG-19, ultra-res imagesCUDA_VISIBLE_DEVICES=0 python WCT.py --debug --mode 16x --UHD# If your RAM cannot afford some large images, you can change the content and style size via '--content_size' and '--style_size'CUDA_VISIBLE_DEVICES=0 python WCT.py --debug --mode 16x --UHD --content_size 3000 --style_size 2000
However, this is quite complicated for users, so we can use streamlit to write a demo page that is convenient for users to use.
In this demo page, the following components of streamlit will be used:
streamlit.file_uploader: file upload component, see the figure below for details
This component supports dragging and uploading files and file manager selection files, which is relatively convenient. The use method is as shown in the following code:
style_file = st.file_uploader("Please upload stylized images")if style_file: stringio = style_file.getvalue() style_file_path = 'style_file/'+ style_file.name with open(style_file_path,'wb') as f: f.write(stringio)
After uploading a file using the File Upload component, you can use the code above to save the file to a specific path for use.
streamlit.image: image display component, see the following figure for details:
This component can display pictures in demo pages according to their path.
style_file_path = 'style_file/'+ style_file.namest.image(style_file_path)
streamlit.write: Text display component that displays some hints on a web page.
st.write ('high resolution stylized demo')
streamlit.button: button component, click to perform some tasks.
if st.button ('Start stylization '): style_func()
streamlit.progress: progress display component, which can be used to display the progress of tasks.
for i in range(0,100,10): st.progress(i + 1)
There are also some important components in streamlit, such as:
streamlit.cache: Data cache component, which can be used as a decorator to cache data and speed up data loading. It can be used in functions that require repeated loading of data or calculations.
@st.cachedef load_dataset(data_link): dataset = pd.read_csv(data_link) return dataset
streamlit.audio: Audio presentation component that plays audio based on audio address.
with open('audio.mp3','rb') as f: st.audio(f,format="audio/mp3")
streamlit.audio: A selection component that lets users select one of several options.
model_choose = st.radio ('Please select separate models',['Voice + Accompaniment',' Voice + Piano + Guitar + Drum + OTHERS '],0)
where parameter 0 indicates that the first item is selected by default.
Streamlit supports a lot of components, if interested, please refer to the official documentation.
item prepared
The main function of this demo page is to let users upload style images and content images respectively, and then perform stylization operations in the background, and display the result images after the stylization operation is completed. This allows users to quickly style actions and know the results.
Streamlit applications are written in Python. At the beginning of the python file, you need to import the streamlit package.
import streamlit as st
Then upload and preprocess the file:
style_file = st. file_uploader("Please upload stylized picture")content_file = st. file_uploader("Please upload picture to be processed")image_slot = st. empty()if style_file: stringio = style_file.getvalue() style_file_path = 'style_file/'+ style_file.name with open(style_file_path,'wb') as f: f.write(stringio) image_slot.image(style_file_path)if content_file: stringio = content_file.getvalue() content_file_path = 'content_file/'+ content_file.name with open(content_file_path,'wb') as f: f.write(stringio)if content_file and style_file: img1 = Image.open( style_file_path) img1 = img1.resize((640, 640)) img2 = Image.open( content_file_path) img2 = img2.resize((640, 640)) new_img = Image.new('RGB', (1280, 640), 255) new_img.paste(img1,(0,0)) new_img.paste(img2,(640,0)) new_img.save('concrate_file/' + os.path.basename(style_file_path)) image_slot.image('concrate_file/' + os.path.basename(style_file_path))
Finally, write a button to perform stylized actions and display the final result, and add a progress bar:
if st.button ('Start stylization '): my_bar = st.progress(10) UHD_content_folder_path = 'PytorchWCT/content/UHD_content' output_path = WCT_func.process(content_file_path,style_file_path) for i in range(0,100,10): my_bar.progress(i + 1) my_bar.progress(100) st.write ('stylized picture') st.image(output_path)
Project operation and deployment
The streamlit framework works very simply, directly from the command line:
$ streamlit run streamlit_demo.py
It can be accessed in the browser.
summary
Streamlit framework is very suitable for fast writing process is not too complex and need visual operation demo, the author from the start to write this demo time less than half an hour, write code less than 50 lines, and run deployment is very convenient, the page looks much more beautiful than using flask framework rendering, it is a tool for algorithm engineers.
At this point, the study of "how to install streamlit framework" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!
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.