forked from SurendraRedd/StreamlitProjects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
247 lines (181 loc) · 11.3 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!/usr/bin/env python
# coding: utf-8
# #### ![streamlit.png](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAASCSURBVGhD7Zi5axRRHMe/82Z2NfFWFLyvKMYLLQSvQkTExsZGQQubYCMSRETTBf8AQ0rBQlS008JGxELRxhNFCxUrtVATNR7RZHdm/X3nvSVjdq5NsjCG+cCw+46ded/3u96sVREwDlDm878nF5I1ciFZIxeSNXIhWSMXkjVyIWn5I5envzaUhgqhgAknTsDr6oKruxpGQ4W4167BmjkTTm8v8OyZ6W0MDRNS6ulB4f59MckEYPp0qIsXG2qVGiH9p0+j/Pu3aY0MvqnZZ88Cc+fqDsGaMweV7m5/bDS437+j7+VL0xqiRkjTvXtwVq1C6ej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TMWMxhQtR3XI4dTPbmItV17G0pLKIoST3P374dy5M1QXGgGXI642cPIkivIulCY+SGohVRjy9bwYjQR6AE8W9VC3kKwiTjo+yIVkjVxI1siFZI1cSNbIhWSNcSIE+Av1IpficT+iFQAAAABJRU5ErkJggg==) **Run streamlit code exists in the jupyter notebook** ![Jupyter.png](data:image/png;base64,/9j/4AAQSkZJRgABAQEAeAB4AAD/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAEAAAAAAAD/2wBDAAIBAQIBAQICAgICAgICAwUDAwMDAwYEBAMFBwYHBwcGBwcICQsJCAgKCAcHCg0KCgsMDAwMBwkODw0MDgsMDAz/2wBDAQICAgMDAwYDAwYMCAcIDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAz/wAARCAA/AC8DASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD9391G6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MR/9k=)
# ---
#
# - 1) Write Streamlit code in jupyter Notebook.
# - 2) Run the below commands in the command prompt,
# - jupyter nbconvert --to script Streamlit_Jupyter.ipynb # convert jupyter notebook to script
# - streamlit run app.py
# In[ ]:
# Import all the packages
import streamlit as st
import urllib.request
from PIL import Image
import time
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# In[ ]:
def videoUserDefined(src: str, width="100%", height=315):
"""An extension of the video widget
Arguments:
src {str} -- url of the video Eg:- https://www.youtube.com/embed/B2iAodr0fOo
Keyword Arguments:
width {str} -- video width(By default: {"100%"})
height {int} -- video height (By default: {315})
"""
st.write(
f'<iframe width="{width}" height="{height}" src="{src}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>',
unsafe_allow_html=True,
)
# In[ ]:
# @cache
@st.cache
def load_data():
df = pd.read_csv("https://github.com/SurendraRedd/StreamlitProjects/raw/master/lang.csv")
return df
# In[ ]:
def main():
# Test/Title
st.title('StreamLit Concepts')
# Header/Subheader
st.header("To Create Header")
st.subheader("To Create subheader")
st.subheader("Do you want to build the GUI using web app")
st.code('pip install streamlit')
#text
st.text("hello Streamlit")
html_temp = """
<div style="background-color:tomato;padding:10px">
<h2 style="color:white;text-align:center;">Streamlit ML App </h2>
</div>
"""
st.markdown(html_temp,unsafe_allow_html=True)
st.markdown('<i class="material-icons">{}</i>'.format("people"), unsafe_allow_html=True)
st.latex(r''' e^{i\pi} + 1 = 0 ''')
st.latex(r'''
... a + ar + a r^2 + a r^3 + \cdots + a r^{n-1} =
... \sum_{k=0}^{n-1} ar^k =
... a \left(\frac{1-r^{n}}{1-r}\right)
... ''')
st.write(['st', 'is <', 3])
st.write("✔️ Time up!")
st.code('s="Happy" for i in range(0,10): print(s)')
df1 = pd.DataFrame(
np.random.randn(50, 5),
columns=('col %d' % i for i in range(5)))
my_table = st.table(df1)
df = st.cache(pd.read_csv)("https://github.com/SurendraRedd/StreamlitProjects/raw/master/lang.csv")
is_check = st.checkbox("Display Data")
if is_check:
st.write(df)
st.write('Dataframe example')
st.dataframe(df1)
#Markdown
st.markdown("### This is a Markdown")
st.markdown("### 🎲 Demo on streamlit")
st.markdown("Streamlit python package is used to develop applications"
"with out knowing much web application concepts.")
st.markdown("**♟ Examples ♟**")
st.markdown("* Happly learning!.")
#Will be used for displaying the Error Messages in a colourful format
st.success("Successful")
st.info("Information!")
st.warning('this is a warning')
st.error("this is an error Danger")
data = {'1':"True",'2':"True",'3':"False"}
st.json(data)
# Exception handling
st.exception("IndexError('list out of index')")
place_holder = st.empty()
place_holder.text('Replaced!')
#help of the function
st.help(range)
st.write("Text with write")
st.write(range(10))
st.line_chart({"data": [1, 5, 2, 6, 2, 1]})
st.area_chart({"data": [1, 5, 2, 6, 2, 1]})
st.bar_chart({"data": [1, 5, 2, 6, 2, 1]})
arr = np.random.normal(1, 1, size=100)
fig, ax = plt.subplots()
ax.hist(arr, bins=20)
st.pyplot(fig)
'''
# Markdown magic
This is some _**text**_.
'''
df = pd.DataFrame({'col1': [1,2,3]})
df # <-- Draw the dataframe
x = 10
'x', x # <-- Draw the string 'x' and then the value of x
# Select box
exp = st.selectbox("Select your experience: ", np.arange(1, 40, 1))
# Slider
exp = st.slider("Select your experience: ", min_value=1,
max_value=40, value=1, step=1)
# Multiselect
movies = st.multiselect("Select Balayya Favourite movies?",
["SamaraSimhaReddy", "Simha",
"NarasimhaNaidu", "Legend"])
# Will only run once if already cached
df = load_data()
st.write(df)
st.button('Click')
st.checkbox('Check the checkbox')
st.radio('Radio Button',[1,2,3])
st.selectbox('Select', [1,2,3])
st.multiselect('Multiselect', [1,2,3])
st.slider('slide',min_value=0, max_value=10)
st.text_input('Enter Username')
st.number_input('Enter a Number')
st.text_area('Enter Text Here!')
st.date_input('Date Input')
st.time_input('Time entry')
st.file_uploader('File Uploader')
st.beta_color_picker('Select color')
st.echo()
with st.echo():
text = 's="Happy Learning!" for i in range(0,10): print(s)'
st.write(text)
#Image opening
#img = Image.open("download.jfif") #open the image stored in specified location
img = Image.open(urllib.request.urlopen("https://github.com/SurendraRedd/ChallengeDeploy/raw/main/singlefile/Solution.png")) # Opens the image from the url
#response = requests.get("https://github.com/SurendraRedd/Techgig/blob/main/images/Solution.png")
#img = Image.open(BytesIO(response.content))
#img = Image.open(urllib.request.urlopen("https://github.com/SurendraRedd/Techgig/blob/main/images/Solution.png"))
st.image(img, width=300, caption="Simple Image")
# Video playing
vid_file = open("sample-mp4-file.mp4","rb").read() #play the video stored in specified location
st.video(vid_file)
#videoUserDefined("https://www.youtube.com/embed/B2iAodr0fOo")
#widgets
if st.checkbox("Show/hide"):
st.text("Showing or Hiding Widget")
# Radio
status = st.radio("What is your status",("Married","Single"))
if status == 'Married':
st.success("You are Married")
# Add a selectbox to the sidebar:
add_selectbox = st.sidebar.selectbox(
'Navigation',
('Home', 'About', 'Help')
)
if add_selectbox == 'About':
st.write('You have selected about page')
elif add_selectbox == 'Home':
st.write('you have selected Home page')
else:
st.write('you have selected help page')
# Sample Progress bar
my_bar = st.progress(0)
for percent_complete in range(100):
time.sleep(0.1)
my_bar.progress(percent_complete + 1)
with st.spinner('Wait for it...'):
time.sleep(5)
st.success('Done!')
st.balloons()
st.write('Happy Stream Lite App Learning')
# In[ ]:
main()