Kamanda commited on
Commit
23328c2
1 Parent(s): 4f7e359

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -305
app.py CHANGED
@@ -58,308 +58,3 @@ import time
58
  #with st.spinner('Please wait...'):
59
  #time.sleep(5)
60
  #st.write('Complete!')
61
-
62
-
63
- #Displaying an image using Streamlit
64
- from PIL import Image
65
- image = Image.open('media/ann-savchenko-H0h_89iFsWs-unsplash.jpg')
66
-
67
- #st.image(image, caption='Sunset grass backgrounds')
68
-
69
- #plotly
70
- import plotly.express as px
71
- # This dataframe has 244 rows, but 4 unique entries for the `day` variable
72
- df = px.data.tips()
73
- figx = px.pie(df, values='tip', names='day', title='Tips per day')
74
- # Plot!
75
- st.plotly_chart(figx, use_container_width=True)
76
-
77
- #Altair
78
- import altair as alt
79
- import streamlit as st
80
- import numpy as np
81
-
82
- df = pd.DataFrame(
83
- np.random.randn(300, 4),
84
- columns=['a', 'b', 'c', 'd'])
85
-
86
- chrt = alt.Chart(df).mark_circle().encode(
87
- x='a', y='b', size='c', color='c', tooltip=['a', 'b', 'c', 'd'])
88
-
89
- st.altair_chart(chrt, use_container_width=True)
90
-
91
- #Matplotlib
92
- import matplotlib.pyplot as plt
93
- import numpy as np
94
-
95
- arr = np.random.normal(1, 1, size=1000)
96
- fig, ax = plt.subplots()
97
- ax.hist(arr, bins=30)
98
- plt.grid()
99
- st.pyplot(fig)
100
-
101
- #Interactive widgets
102
- st.button("Click here")
103
- #st.download_button("Download audio", file)
104
- selected = st.checkbox("Accept terms")
105
- choice = st.radio("Select one", ["Apples", "Oranges"])
106
-
107
-
108
- option = st.selectbox(
109
- 'How would you like to receive your package?',
110
- ('By air', 'By sea', 'By rail'))
111
-
112
- st.write('You selected:', option)
113
- import datetime
114
- day = st.date_input(
115
- "When is your birthday?",
116
- datetime.date(2022, 7, 6))
117
- st.write('Your birthday is:', day)
118
-
119
- color = st.color_picker('Choose A Color', '#00FFAA')
120
- st.write('The selected color is', color)
121
-
122
-
123
- @st.cache
124
- def fetch_data():
125
- df = pd.read_csv("students.csv")
126
- return df
127
-
128
- #data = fetch_data()
129
-
130
- #Visualization
131
-
132
- import matplotlib.pyplot as plt
133
- import numpy as np
134
-
135
- #Matplotlib
136
-
137
- import matplotlib.pyplot as plt
138
- import numpy as np
139
- fig = plt.figure()
140
- ax = fig.add_axes([0,0,1,1])
141
- animals = ["Zebras", "Elephants", "Rhinos", "Leopards"]
142
- number = [65, 72, 77, 59]
143
- ax.bar(animals, number)
144
- fig = plt.show()
145
- st.pyplot(fig)
146
- #Seaborn
147
- import seaborn as sns
148
- fig = plt.figure()
149
- ax = sns.barplot(x = animals, y = number)
150
- fig = plt.show()
151
- st.pyplot(fig)
152
-
153
- #Altair
154
- #define data
155
- df = pd.DataFrame()
156
-
157
- df["Animals"] = animals
158
- df["Number"] = number
159
- #create chart
160
- chrt = alt.Chart(df, title="Ploting using Altair in Streamlit").mark_bar().encode(
161
- x='Animals',
162
- y='Number'
163
- )
164
- #render with Streamlit
165
- st.altair_chart(chrt, use_container_width=True)
166
- #Plotly
167
- #define data
168
- df = pd.DataFrame()
169
- df["Animals"] = animals
170
- df["Number"] = number
171
- #create plot
172
- fig1 = px.bar(df, x='Animals', y='Number', title="Ploting using Plotly in Streamlit")
173
- # Plot!
174
- st.plotly_chart(fig1, use_container_width=True)
175
-
176
- #data
177
- df = pd.DataFrame()
178
- df["Animals"] = animals
179
- df["Number"] = number
180
- #visualization
181
- st.vega_lite_chart(df, {
182
- 'mark': {'type': 'bar', 'tooltip': True},
183
- 'encoding': {
184
- 'x': {'field': 'Animals', 'type': 'nominal'},
185
- 'y': {'field': 'Number', 'type': 'quantitative'},
186
- },
187
- }, use_container_width=True)
188
-
189
- #Maps
190
- import pandas as pd
191
- states = pd.read_html('https://developers.google.com/public-data/docs/canonical/states_csv')[0]
192
- states.columns = ['state', 'lat', 'lon', 'name']
193
- states = states.drop(['state', 'name'], axis = 1)
194
-
195
- st.map(states)
196
-
197
- #Components
198
- from st_aggrid import AgGrid
199
- AgGrid(df)
200
-
201
- #Statefulnness
202
- import streamlit as st
203
-
204
- st.title('Streamlit Counter Example')
205
- count = 0
206
-
207
- add = st.button('Addition')
208
- if add:
209
- count += 1
210
-
211
- st.write('Count = ', count)
212
-
213
-
214
- import streamlit as st
215
-
216
- st.title('Counter Session State')
217
- if 'count' not in st.session_state:
218
- st.session_state.count = 0
219
-
220
- increment = st.button('Add')
221
- if increment:
222
- st.session_state.count += 1
223
-
224
- st.write('Count = ', st.session_state.count)
225
-
226
- #Layout
227
- col1, col2 = st.columns(2)
228
-
229
- with col1:
230
- st.altair_chart(chrt)
231
- with col2:
232
- st.plotly_chart(fig1, use_container_width=True)
233
- with st.beta_container():
234
- st.plotly_chart(figx, use_container_width=True)
235
-
236
-
237
-
238
- #Add side widget
239
-
240
- def your_widget(key):
241
- st.subheader('Hi! Welcome')
242
- return st.button(key + "Step")
243
-
244
- # Displayed in the main area
245
- clicked = your_widget("First")
246
-
247
- # Shown within an expander
248
- your_expander = st.expander("Expand", expanded=True)
249
- with your_expander:
250
- clicked = your_widget("Second")
251
-
252
- # Shown in the st.sidebar!
253
- with st.sidebar:
254
- clicked = your_widget("Last")
255
- #Session State
256
- # Initialization
257
- if 'key' not in st.session_state:
258
- st.session_state['key'] = 'value'
259
-
260
-
261
-
262
- # Session State also supports attribute based syntax
263
- if 'key' not in st.session_state:
264
- st.session_state.key = 'value'
265
-
266
- st.session_state.key = 'value x' # New Attribute API
267
- st.session_state['key'] = 'value x' # New Dictionary like API
268
-
269
- st.write(st.session_state)
270
-
271
- #Uploading files
272
-
273
- import streamlit as st
274
-
275
- #upload single file
276
- file = st.file_uploader("Please select a file to upload")
277
- if file is not None:
278
- #Can be used wherever a "file-like" object is accepted:
279
- df= pd.read_csv(file)
280
- st.dataframe(df)
281
-
282
- #Multiple files
283
- #adding a file uploader to accept multiple CSV file
284
- uploaded_files = st.file_uploader("Please select a CSV file", accept_multiple_files=True)
285
- for file in uploaded_files:
286
- df = pd.read_csv(file)
287
- st.write("File uploaded:", file.name)
288
- st.dataframe(df)
289
- #Uploading and Processing
290
- #upload single file
291
- from PIL import Image
292
- from PIL import ImageEnhance
293
- def load_image(image):
294
- img = Image.open(image)
295
- return img
296
-
297
- file = st.file_uploader("Please select image to upload and process")
298
- if file is not None:
299
- image = Image.open(file)
300
- fig = plt.figure()
301
- st.subheader("Original Image")
302
- plt.imshow(image)
303
- st.pyplot(fig)
304
- fig = plt.figure()
305
- contrast = ImageEnhance.Contrast(image).enhance(12)
306
- plt.imshow(contrast)
307
- st.subheader("Preprocessed Image")
308
- st.pyplot(fig)
309
-
310
-
311
- #Image classification
312
- import keras
313
- from PIL import Image, ImageOps
314
- import numpy as np
315
-
316
-
317
-
318
- import streamlit as st
319
- import streamlit as st
320
- from transformers import pipeline
321
-
322
- '''Hugging Face'''
323
-
324
- import streamlit as st
325
- from transformers import pipeline
326
-
327
- if __name__ == "__main__":
328
-
329
- # Define the title of the and its description
330
- st.title("Answering questions using NLP through Streamlit interface")
331
- st.write("Pose questions, get answers")
332
-
333
- # Load file
334
-
335
- raw_text = st.text_area(label="Enter a text here")
336
- if raw_text != None and raw_text != '':
337
-
338
- # Display text
339
- with st.expander("Show question"):
340
- st.write(raw_text)
341
-
342
- # Conduct question answering using the pipeline
343
- question_answerer = pipeline('question-answering')
344
-
345
- answer = ''
346
- question = st.text_input('Ask a question')
347
-
348
- if question != '' and raw_text != '':
349
- answer = question_answerer({
350
- 'question': question,
351
- 'context': raw_text
352
- })
353
-
354
- st.write(answer)
355
-
356
-
357
-
358
-
359
-
360
-
361
-
362
-
363
-
364
-
365
-
58
  #with st.spinner('Please wait...'):
59
  #time.sleep(5)
60
  #st.write('Complete!')