app.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. '''
  4. @Contact : liuyuqi.gov@msn.cn
  5. @Time : 2024/03/28 02:01:09
  6. @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
  7. @Desc :
  8. '''
  9. from datetime import datetime
  10. from numpy import empty, not_equal
  11. import streamlit as st
  12. import streamlit.components.v1 as components
  13. import time
  14. import pandas as pd
  15. import numpy as np
  16. st.set_page_config(
  17. page_title="Streamlit example",
  18. page_icon="./icon/android-chrome-192x192.png",
  19. layout="wide",
  20. initial_sidebar_state="collapsed",
  21. menu_items={
  22. 'Get Help': 'https://www.baidu.com/',
  23. 'Report a bug': None,
  24. 'About': '''
  25. # About
  26. ## testing!
  27. :smile:
  28. '''
  29. }
  30. )
  31. st.image("./icon/android-chrome-192x192.png")
  32. #t1函数,用于测试 on_change或 on_click
  33. def t1():
  34. st.text("t1-ing!")
  35. '''# 组件'''
  36. #勾选框
  37. a = st.checkbox('test_checkbox', value=False, key=None, help="testing", on_change=None, args=None, kwargs=None)
  38. #按钮
  39. b = st.button(label="button", key=None, help="testing!", on_click=None)
  40. #下载按钮
  41. c = st.download_button(label="download_button", data='testttt', file_name='test_.md', help='testing!', on_click=None)
  42. #单选框
  43. d = st.radio(label="What's your favorite movie genre",options=('Comedy', 'Drama', 'Documentary'),index=2, help='testing!')
  44. #下拉选项
  45. e = st.selectbox('slectbox',('Comedy', 'Drama', 'Documentary'),index=2, help='testing!')
  46. #多选
  47. f = st.multiselect('multiselect',('Comedy', 'Drama', 'Documentary'), default=['Drama'], help='testing!')
  48. #滑动条
  49. g = st.slider(label="slider", min_value=-10, max_value=10, value=-2, step=1, help="testing!", on_change=t1)
  50. #选择滑动条
  51. h = st.select_slider(label='select_slider', options=[1,'test2',3], value=3, help="testing!")
  52. #文本框
  53. i = st.text_input(label='text_input', max_chars=30, value='test1', help='testing!', placeholder='请输入')
  54. #数字选择框
  55. j = st.number_input("number_input", min_value=-10, max_value=10, value=2, step=2, help="testing")
  56. #文本区域
  57. k = st.text_area("text_area", value="test1",max_chars=60, help="testing!", placeholder="请输入")
  58. #时间选择
  59. dt1 = datetime.today()
  60. dt2 = datetime.today()
  61. l = st.date_input(label="date_input", value=(dt1,dt2))
  62. #时间选择
  63. m = st.time_input("time_input", value=None, help="testing!")
  64. #上传按钮
  65. n = st.file_uploader(label='file_uploader', accept_multiple_files=True, help="testing!")
  66. #拾色器
  67. o = st.color_picker('color_picker', '#00f900')
  68. #图片
  69. p = st.image(image=['https://i.bmp.ovh/imgs/2021/10/3fd6c4674301c708.jpg',"./data/testimage.jpg"])
  70. #音频
  71. q = st.audio("http://music.163.com/song/media/outer/url?id=1901371647.mp3")
  72. #视频
  73. #html外链
  74. #arg = "<iframe src=\"//player.bilibili.com/player.html?aid=376524564&bvid=BV1wo4y1X7Tk&cid=365010431&page=1\" scrolling=\"yes\" border=\"100\" frameborder=\"yes\" framespacing=\"0\" allowfullscreen=\"true\"> </iframe>"
  75. #r = st.markdown(unsafe_allow_html=True, body=arg)
  76. #iframe conponent
  77. components.iframe(src="//player.bilibili.com/player.html?aid=376524564&bvid=BV1wo4y1X7Tk&cid=365010431&page=1", width=1080, height=720, scrolling=False)
  78. #video
  79. r = st.video("./data/testybb.mp4")
  80. #边栏
  81. add_selectbox = st.sidebar.selectbox(
  82. label="How would you like to be contacted?",
  83. options=("Email", "Home phone", "Mobile phone"),
  84. key="t1"
  85. )
  86. add_selectbox2 = st.sidebar.selectbox(
  87. label="How would you like to be contacted?",
  88. options=("Email", "Home phone", "Mobile phone"),
  89. key="t2"
  90. )
  91. #列布局
  92. col1, col2, col3 = st.columns(3)
  93. with col1:
  94. st.header("A cat")
  95. st.image("https://static.streamlit.io/examples/cat.jpg")
  96. with col2:
  97. st.header("A dog")
  98. st.image("https://static.streamlit.io/examples/dog.jpg")
  99. with col3:
  100. st.header("An owl")
  101. st.image("https://static.streamlit.io/examples/owl.jpg")
  102. #展开框
  103. with st.expander(label="expander", expanded=False):
  104. st.write("tesing")
  105. #container
  106. with st.container():
  107. st.write("container")
  108. container = st.container()
  109. container.write("containertext1")
  110. st.write("not container")
  111. #在container中继续调用组件
  112. container.write("containertext2")
  113. #empty
  114. #with st.empty():
  115. # st.write("not empty here")
  116. #
  117. #empty = st.empty()
  118. #empty.text("still not empty")
  119. #time.sleep(3) #替换
  120. #empty.text("change")
  121. #time.sleep(1) #清除
  122. #empty.empty()
  123. #progress
  124. #my_bar = st.progress(100)
  125. #for percent_complete in range(100).__reversed__():
  126. # time.sleep(0.01)
  127. # my_bar.progress(percent_complete)
  128. #spinner
  129. #with st.spinner('Wait for it...'):
  130. # time.sleep(3)
  131. #st.success('Done!')
  132. #放气球
  133. #st.balloons()
  134. #错误信息
  135. st.error('error!💀')
  136. #警告信息
  137. st.warning("warning! :warning:")
  138. #信息
  139. st.info('message ℹ')
  140. #成功
  141. st.success("success 🎉")
  142. #exception
  143. e = RuntimeError("an exception")
  144. st.exception(e)
  145. #stop
  146. name = st.text_input('Name')
  147. if not name:
  148. st.warning('Please input a name.')
  149. st.stop()
  150. st.success('Thank you for inputting a name.')
  151. #form表单
  152. #with st.form(key="my_form1"):
  153. # st.write("Inside the form")
  154. # slider_val = st.slider("Form slider")
  155. # checkbox_val = st.checkbox("Form checkbox")
  156. #提交
  157. # submitted = st.form_submit_button("Submit")
  158. # if submitted:
  159. # st.write("slider", slider_val, "checkbox", checkbox_val)
  160. #st.write("Outside the form")
  161. form = st.form(key="my_form2")
  162. form.slider("Inside the form")
  163. form.form_submit_button("Submit")
  164. #echo
  165. with st.echo("below"):
  166. st.write('This code will be printed')
  167. #help
  168. st.help(st.help)
  169. #add_rows
  170. df1 = pd.DataFrame(
  171. np.random.randn(1, 5),
  172. columns=('col %d' % i for i in range(5)))
  173. my_table = st.table(df1)
  174. df2 = pd.DataFrame(
  175. np.random.randn(2, 5),
  176. columns=('col %d' % i for i in range(5)))
  177. my_table.add_rows(df2)
  178. #emoji
  179. st.markdown(":smile:😁")
  180. st.text("😁")
  181. st.text(type(r))