Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Python
Posted by: Surendra Reddy
Added: Nov 8, 2020 10:09 AM
Views: 7
Tags: streamlit
  1. import streamlit as st
  2. import urllib.request
  3. from PIL import Image
  4. import time
  5.  
  6. def videoUserDefined(src: str, width="100%", height=315):
  7.     """An extension of the video widget
  8.    Arguments:
  9.        src {str} -- url of the video Eg:- https://www.youtube.com/embed/B2iAodr0fOo
  10.    Keyword Arguments:
  11.        width {str} -- video width(By default: {"100%"})
  12.        height {int} -- video height (By default: {315})
  13.    """
  14.     st.write(
  15.         f'<iframe width="{width}" height="{height}" src="{src}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>',
  16.         unsafe_allow_html=True,
  17.     )
  18.  
  19. def main():
  20.  
  21.     # Test/Title
  22.     st.title('StreamLit basic Concepts')
  23.  
  24.     # Header/Subheader
  25.     st.header("To Create Header")
  26.     st.subheader("To Create subheader")    
  27.  
  28.     st.subheader("Do you want to build the GUI using web app")
  29.     st.code('pip install streamlit')
  30.  
  31.     #text
  32.     st.text("hello Streamlit")
  33.  
  34.     #Markdown
  35.     st.markdown("### This is a Markdown")
  36.  
  37.     #Will be used for displaying the Error Messages in a colourful format
  38.     st.success("Successful")
  39.     st.info("Information!")
  40.     st.warning('this is a warning')
  41.     st.error("this is an error Danger")
  42.    
  43.     # Exception handling
  44.     st.exception("IndexError('list out of index')")
  45.  
  46.     #help of the function
  47.     st.help(range)
  48.  
  49.     st.write("Text with write")
  50.  
  51.     st.write(range(10))
  52.  
  53.     #Image opening
  54.     img = Image.open("download.jfif") #open the image stored in specified location
  55.     #img = Image.open(urllib.request.urlopen("https://mms.businesswire.com/media/20200616005364/en/798639/22/Streamlit_Logo_%281%29.jpg")) # Opens the image from the url
  56.     st.image(img, width=300, caption="Simple Image")
  57.  
  58.     # Video playing
  59.     #vid_file = open("sample-mp4-file.mp4","rb").read() #play the video stored in specified location
  60.     #st.video(vid_file)
  61.     videoUserDefined("https://www.youtube.com/embed/B2iAodr0fOo")
  62.  
  63.     #widgets
  64.     if st.checkbox("Show/hide"):
  65.         st.text("Showing or Hiding Widget")
  66.  
  67.     # Radio
  68.     status = st.radio("What is your status",("Married","Single"))
  69.     if status == 'Married':
  70.         st.success("You are Married")
  71.  
  72.     # Add a selectbox to the sidebar:
  73.     add_selectbox = st.sidebar.selectbox(
  74.         'Navigation',
  75.         ('Home', 'About', 'Help')
  76.     )
  77.  
  78.     if add_selectbox == 'About':
  79.         st.write('You have selected about page')
  80.     elif add_selectbox == 'Home':
  81.         st.write('you have selected Home page')
  82.     else:
  83.         st.write('you have selected help page')
  84.  
  85.     # Sample Progress bar
  86.     my_bar = st.progress(0)
  87.  
  88.     for percent_complete in range(100):
  89.         time.sleep(0.1)
  90.         my_bar.progress(percent_complete + 1)
  91.  
  92.     st.balloons()
  93.  
  94.    
  95. ##########################################################################
  96. # @brief Entry point of the python
  97. ##########################################################################
  98. if __name__ == '__main__':
  99.     main()