亚洲视频二区_亚洲欧洲日本天天堂在线观看_日韩一区二区在线观看_中文字幕不卡一区

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.430618.com 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

1 說明:

===初探===

1.1 Streamlit

1.1.1 是一個開源Python庫,可輕松構建用于機器學習的漂亮應用程序。

1.1.2 是一款專為機器學習工程師創建的免費、開源 App 構建框架。

1.1.3 是一個簡單而強大的應用程序模型,可讓您快速構建豐富的UI。

1.1.4 是第一個專門針對機器學習和數據科學團隊的應用開發框架。

1.1.5 是開發自定義機器學習工具的最快的方法,它的目標是取代Flask在機器學習項目中的地位,可以幫助機器學習工程師快速開發用戶交互工具。

Streamlit是python的一個機器學習、數據科學、應用開發框架

 

1.2 環境:

華為筆記本電腦、深度deepin-linux操作系統、python3.8和微軟vscode編輯器。

1.3 官網:

https://www.streamlit.io/
https://github.com/streamlit/streamlit
https://docs.streamlit.io/en/latest/

2 安裝過程:

=====

2.1 安裝:

pip install streamlit
#本機安裝
sudo pip3.8 install streamlit  #慢
#推薦安裝方法
sudo pip3.8 install -i https://mirrors.aliyun.com/pypi/simple streamlit #超快

2.2 第一個報錯:

ERROR: chartify 2.7.0 has requirement bokeh<2.0.0,>=1.4.0, but you'll have bokeh 2.1.0 which is incompatible.
ERROR: chartify 2.7.0 has requirement pandas<1.0.0,>=0.21.0, but you'll have pandas 1.0.4 which is incompatible.

#提示bokeh和pandas的版本均太高了,暫時忽略看看行不行,因為我提前安裝bokeh和pandas

2.3 第二個提醒:

  WARNING: The script base58 is installed in '/usr/local/python3.8/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

  #解決辦法:建立軟連接,本機如下
sudo ln -s /usr/local/python3.8/bin/base58 /usr/bin/base58

2.4 第三個提醒:

  WARNING: The script streamlit is installed in '/usr/local/python3.8/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

#解決辦法:建立軟連接,本機如下
sudo ln -s /usr/local/python3.8/bin/streamlit /usr/bin/streamlit

2.5 驗證:查看版本,成功。

xgj@xgj-PC:~$ streamlit --version

Streamlit, version 0.61.0

3 查看demo

=========

3.1 第一次,打開終端輸入:

streamlit hello

3.2 需要輸入個人email:

   Welcome to Streamlit!

  If you're one of our development partners or you're interested in getting
  personal technical support or Streamlit updates, please enter your email
  address below. Otherwise, you may leave the field blank.

#需要輸入自己的email地址
  Email: xxx@xxx

#回車,出現下面,并自動打開瀏覽器
  Privacy Policy:
  As an open source project, we collect usage statistics. We cannot see and do
  not store information contained in Streamlit apps. You can find out more by
  reading our privacy policy at: https://streamlit.io/privacy-policy

  If you'd like to opt out of usage statistics, add the following to
  ~/.streamlit/config.toml, creating that file if necessary:

    [browser]
    gatherUsageStats = false

  You can now view your Streamlit app in your browser.

  Local URL: http://localhost:8501
  Network URL: http://192.168.12.106:8501
#按ctrl+c退出

3.3 第二次進入,如下操作和示意圖:

Streamlit是python的一個機器學習、數據科學、應用開發框架

 

4 st.image:

========

4.1 方法一:官方推薦法,缺點gif圖片顯示靜態的

import streamlit as st
#官方的顯示圖片法一
from PIL import Image #采用PIL讀取圖片
image = Image.open('/home/xgj/Desktop/Streamlit/20.jpeg')
#image = Image.open('/home/xgj/Desktop/Streamlit/21.jpg')
#image = Image.open('/home/xgj/Desktop/Streamlit/22.png')
#image = Image.open('/home/xgj/Desktop/Streamlit/23.gif')  #靜態的圖片

#caption='顯示圖片',圖片信息;width=300,指定圖片寬度,自動縮放;默認是圖片本身的大小
st.image(image, caption='顯示圖片',width=300)

4.2 方法二:

import streamlit as st
#顯示圖片法二,推薦這種方法
#pic_file = open('/home/xgj/Desktop/Streamlit/12.gif', 'rb')  #gif可以動態顯示
pic_file = open('/home/xgj/Desktop/Streamlit/21.jpg', 'rb') 

pic_bytes = pic_file.read()
st.image(pic_bytes)  

4.3 效果圖:

#注意代碼塊中采用#注釋,如果采用python的'''和'''大片狀注釋法會在網頁上顯示代碼塊,不建議。
Streamlit是python的一個機器學習、數據科學、應用開發框架

 

#如果修改代碼塊,保存后,因為終端啟動服務器,所以只需要網頁刷新即可看到效果
#圖片顯示默認的是默認大小,也可以自定義顯示大小:width設置即可。
#采用微軟的vscode編輯器的run,沒反應,估計沒設置好,所以本文采用官方推薦的方法,就是終端
#輸入:streamlit run xxx.py運行

5 st.video和st.audio

===============

5.1 代碼:

import streamlit as st

#播放動畫
#video_file = open('/home/xgj/Desktop/Streamlit/11.mp4', 'rb') #mp4成功
#用st.video播放mp3可以,但是無效視頻框太大,占空間
#video_file = open('/home/xgj/Desktop/Streamlit/sn.mp3', 'rb')  #不推薦

#video_bytes = video_file.read()
#st.video(video_bytes)

#播放mp3,推薦用audio法,包括ogg、wav格式
audio_file = open('/home/xgj/Desktop/Streamlit/sn.mp3', 'rb')   #推薦
audio_bytes = audio_file.read()
st.audio(audio_bytes)  

5.2 操作效果圖:

Streamlit是python的一個機器學習、數據科學、應用開發框架

 

6 文本輸出:

========

6.1 代碼:

import streamlit as st

st.title('Helloworld,你好,世界')
st.header('Helloworld,你好,世界')
st.write('Helloworld,你好,世界')
#在終端輸入
#streamlit run 1.py

6.2 效果圖:

Streamlit是python的一個機器學習、數據科學、應用開發框架

注意字體特點

7 信息提示框:

==========

7.1 代碼:

import streamlit as st

st.error('This is error!')
st.info('welcome to the streamlit!')
st.warning('This is warning!')
e = RuntimeError('This is an exception of type RuntimeError')
st.exception(e)

7.2 圖:

Streamlit是python的一個機器學習、數據科學、應用開發框架

 

8 input輸入框:

===========

8.1 代碼:

import streamlit as st
#注意自動依次布局
#文本輸入
url = st.text_input('Enter URL')
st.write('The Entered URL is', url)
#數字輸入
num = st.number_input('Enter NUMBER')
st.write('You enter number is',num)
#當前日期選擇器
todaydate=st.date_input('Today is ')
st.write('Today is :',todaydate)
#當前時間獲取
nowtime=st.time_input('Nowtime is:')
st.write('Nowtime is :',nowtime)

8.2 操作效果圖:

Streamlit是python的一個機器學習、數據科學、應用開發框架

 

9 進度條:

=======

9.1 學習st.sidebar=側邊欄,st.empty,st.success和python的格式化輸出知識復習:比如顯示%=%%。

9.2 代碼:

import streamlit as st
import time
#正文的進度條
my_bar = st.progress(0)
#進度數字顯示
frame_text = st.empty()
#sidebar 側邊欄的進度條
xx_bar=st.sidebar.progress(0)
#側邊欄進度數字顯示
frame_textxx = st.sidebar.empty()

for i in range(100):
    my_bar.progress(i + 1)
    frame_text.text("Frame %i%%/100%%" % (i+ 1))
    xx_bar.progress(i + 1)
    frame_textxx.text("Frame %i%%/100%%" % (i+ 1))
    time.sleep(0.1)
#清空顯示進度條的百分比文本
#frame_text.empty()
#frame_textxx.empty()
#提示成功和完成信息框
st.sidebar.success("done")
st.success("done")

#在腳本所在的目錄下的終端輸入
#streamlit run 2-progres.py

9.3 操作和效果圖:

Streamlit是python的一個機器學習、數據科學、應用開發框架

 

10 st.spinner,st.balloons和st.help用法:

==============================

10.1 代碼:

import streamlit as st
#導入時間
import time
with st.spinner('Please wait for it...'):
    time.sleep(5)
st.success('Done!')
#彩蛋
st.balloons()  #放慶祝氣球
#調出pandas.DataFrame的幫助信息
import pandas
st.help(pandas.DataFrame)
#運行腳本
#streamlit run 9.py

10.2 操作和效果圖:

#注意st.help
Streamlit是python的一個機器學習、數據科學、應用開發框架

 

11 st.slider滑動條:

===============

11.1 代碼:

import streamlit as st
#滑動條1
x = st.slider('x')
st.write(x, 'squared is', x * x)
#滑動條2
age = st.slider('How old are you?', 0, 130, 25)
st.write("I'm ", age, 'years old')
#滑動條3
values = st.slider(
     'Select a range of values',
     0.0, 100.0, (25.0, 75.0))
st.write('Values:', values)

#終端輸入
#streamlit run 5-slider.py

11.2 操作和效果圖:

#比官方還仔細
Streamlit是python的一個機器學習、數據科學、應用開發框架

 

 

分享到:
標簽:機器 學習
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定