Skip to content

Commit

Permalink
Tasks from day 21 to 30 (#5)
Browse files Browse the repository at this point in the history
Last set of days from 30 days challenge from streamlit with some days
skipped for speed.

And again some updates and changes had to be made to make code run in
2024 (the repo is from 2023 and there are some glitches with versions)

1. **e067b6b** Tasks from day 21 - Progress bar
1. **447f1a5** Task of day 22: Forms - with notation and object notation
1. **4e42ad6** Task from day 23 - Get query params from URL
-
https://docs.streamlit.io/develop/api-reference/caching-and-state/st.query_params
- Some changes had to be performed since it is not experimental since a
while
1. **ffb1885** Task from day 24 - Caching of data
1. **f2eefd2** Task of day 25 - Session state
1. **9de8075** Tasks of day 26 - Getting data from external API
   - With some minor changes around the parsing of API response
1. **db1d581** Task of day 27 - Draggable components
1. **65d83af** Task of day 28: Showing charts of explainability
algorithm - SHAP
1. **8b99269** Task of day 30: extracting thumnbnail from YouTube videos
  • Loading branch information
disouzam authored Oct 14, 2024
2 parents f00eed8 + 8b99269 commit a0a21fc
Show file tree
Hide file tree
Showing 29 changed files with 12,173 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@
"8501"
],
"cwd": "${workspaceFolder}/day17"
},
{
"name": "Streamlit - Day26",
"type": "debugpy",
"request": "launch",
"module": "streamlit",
"args": [
"run",
"${workspaceFolder}/day26/day26.py",
"--server.port",
"8501"
],
"cwd": "${workspaceFolder}/day26"
}
]
}
15 changes: 15 additions & 0 deletions day21/day21.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import streamlit as st
import time

st.title('st.progress')

with st.expander('About this app'):
st.write('You can now display the progress of your calculations in a Streamlit app with the `st.progress` command.')

my_bar = st.progress(0)

for percent_complete in range(100):
time.sleep(0.05)
my_bar.progress(percent_complete + 1)

st.balloons()
1,173 changes: 1,173 additions & 0 deletions day21/poetry.lock

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions day21/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[tool.poetry]
name = "day21"
version = "0.1.0"
description = ""
authors = ["Dickson Souza <[email protected]>"]
package-mode = false

[tool.poetry.dependencies]
python = "^3.12"
streamlit = "^1.39.0"
44 changes: 44 additions & 0 deletions day22/day22.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import streamlit as st

st.title('st.form')

# Full example of using the with notation
st.header('1. Example of using `with` notation')
st.subheader('Coffee machine')

with st.form('my_form'):
st.subheader('**Order your coffee**')

# Input widgets
coffee_bean_val = st.selectbox('Coffee bean', ['Arabica', 'Robusta'])
coffee_roast_val = st.selectbox('Coffee roast', ['Light', 'Medium', 'Dark'])
brewing_val = st.selectbox('Brewing method', ['Aeropress', 'Drip', 'French press', 'Moka pot', 'Siphon'])
serving_type_val = st.selectbox('Serving format', ['Hot', 'Iced', 'Frappe'])
milk_val = st.select_slider('Milk intensity', ['None', 'Low', 'Medium', 'High'])
owncup_val = st.checkbox('Bring own cup')

# Every form must have a submit button
submitted = st.form_submit_button('Perform Calculation')

if submitted:
st.markdown(f'''
☕ You have ordered:
- Coffee bean: `{coffee_bean_val}`
- Coffee roast: `{coffee_roast_val}`
- Brewing: `{brewing_val}`
- Serving type: `{serving_type_val}`
- Milk: `{milk_val}`
- Bring own cup: `{owncup_val}`
''')
else:
st.write('☝️ Place your order!')


# Short example of using an object notation
st.header('2. Example of object notation')

form = st.form('my_form_2')
selected_val = form.slider('Select a value')
form.form_submit_button('Submit')

st.write('Selected value: ', selected_val)
1,173 changes: 1,173 additions & 0 deletions day22/poetry.lock

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions day22/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[tool.poetry]
name = "day22"
version = "0.1.0"
description = ""
authors = ["Dickson Souza <[email protected]>"]
package-mode = false

[tool.poetry.dependencies]
python = "^3.12"
streamlit = "^1.39.0"
29 changes: 29 additions & 0 deletions day23/day23.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import streamlit as st

st.title('st.experimental_get_query_params')

with st.expander('About this app'):
st.write("`st.experimental_get_query_params` allows the retrieval of query parameters directly from the URL of the user's browser.")

# 1. Instructions
st.header('1. Instructions')
st.markdown('''
In the above URL bar of your internet browser, append the following:
`?firstname=Jack&surname=Beanstalk`
after the base URL `http://share.streamlit.io/dataprofessor/st.experimental_get_query_params/`
such that it becomes
`http://share.streamlit.io/dataprofessor/st.experimental_get_query_params/?firstname=Jack&surname=Beanstalk`
''')

# 2. Contents of st.experimental_get_query_params
st.header('2. Contents of st.experimental_get_query_params')
st.write(st.query_params)


# 3. Retrieving and displaying information from the URL
st.header('3. Retrieving and displaying information from the URL')

firstname = st.query_params['firstname']
surname = st.query_params['surname']

st.write(f'Hello **{firstname} {surname}**, how are you?')
1,173 changes: 1,173 additions & 0 deletions day23/poetry.lock

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions day23/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[tool.poetry]
name = "day23"
version = "0.1.0"
description = ""
authors = ["Dickson Souza <[email protected]>"]
package-mode = false

[tool.poetry.dependencies]
python = "^3.12"
streamlit = "^1.39.0"
37 changes: 37 additions & 0 deletions day24/day24.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import streamlit as st
import numpy as np
import pandas as pd
from time import time

st.title('st.cache')

# Using cache
a0 = time()
st.subheader('Using st.cache')

@st.cache_data
def load_data_a():
df = pd.DataFrame(
np.random.rand(2000000, 5),
columns=['a', 'b', 'c', 'd', 'e']
)
return df

st.write(load_data_a())
a1 = time()
st.info(a1-a0)

# Not using cache
b0 = time()
st.subheader('Not using st.cache')

def load_data_b():
df = pd.DataFrame(
np.random.rand(2000000, 5),
columns=['a', 'b', 'c', 'd', 'e']
)
return df

st.write(load_data_b())
b1 = time()
st.info(b1-b0)
Loading

0 comments on commit a0a21fc

Please sign in to comment.