!pip install streamlit
!conda install streamlit
12 Streamlit, Recursion, Misc
լուսանկարի հղումը, Հեղինակ՝ Vazgen
Song reference - ToDo
🎦 Տեսադասեր + լրացուցիչ (ToDo)
ToDo 1. Տեսություն 2025
2. Տեսություն 2023 (ToDo)
3. Գործնական 2025
4. Գործնական 2023 (ToDo)
5. Որոշ տնայինների լուծումներ (ToDo)
Google Forms ToDo
📚 Նյութը
Streamlit
- Gallery (official) - https://streamlit.io/gallery
- Gallery (repo) - https://github.com/jrieke/best-of-streamlit
- Example - https://prettymapp.streamlit.app/?ref=streamlit-io-gallery-favorites
- Cheatsheet - https://luluwu-cheatsheet.streamlit.app/
- Reference - https://docs.streamlit.io/develop/api-reference
place the code below into file app.py
"""
streamlit run streamlit_app.py
- Gallery (official) - https://streamlit.io/gallery
- Gallery (repo) - https://github.com/jrieke/best-of-streamlit
- Example - https://prettymapp.streamlit.app/?ref=streamlit-io-gallery-favorites
- Cheatsheet - https://luluwu-cheatsheet.streamlit.app/
- Reference - https://docs.streamlit.io/develop/api-reference
pip install streamlit
conda install streamlit
"""
from time import sleep
import pandas as pd
import streamlit as st
import plotly.express as px
# with st.echo():
# # congrats
# st.balloons()
# st.snow()
with st.echo():
# ---------- Displaying Text ----------
# Title and Header
"My Streamlit App")
st.title("Welcome!")
st.header(
with st.echo():
# Text
"Text")
st.subheader("This is a text block.")
st.text(
with st.echo():
# Markdown
"Markdown")
st.subheader("This is a markdown block. You can write *italic*, **bold**, or even use [links](https://www.streamlit.io/).")
st.markdown(
st.divider()# Latex
"Latex")
st.subheader(with st.echo():
r"Y = \alpha + \beta X_i")
st.latex(
with st.echo():
"You can also use LaTeX for mathematical expressions like this: $E = mc^2$")
st.write(
st.divider()"Table")
st.subheader(with st.echo():
# ---------- Displaying DataFrames ----------
# Displaying a Table
'Name': "Գինի", 'Age': 3 }, { 'Name': "Պանիր", 'Age': 1 }])
st.dataframe([{
with st.echo():
# DataFrame
= {'Name': ['Մալխաս', 'Բարխուդարում', 'Մատատյան ու Մարոխյան'], 'Age': [3, 4, 1]}
data = pd.DataFrame(data)
df
st.dataframe(df)
with st.echo():
st.json({"Product": "Պանիր",
"Type": "Չանախ",
})
# Plotly
"Plotly Bar Chart")
st.subheader(
with st.echo():
st.divider()= px.bar(df, x='Name', y='Age')
fig
st.plotly_chart(fig)
with st.echo():
10, 14, 19, 20, 25, 30, 35, 40, 45, 50, 55, 60])
st.line_chart([
st.divider()"Interactive Widgets")
st.subheader(with st.echo():
# Interactive Widgets
# # # Button
if st.button("Click me!"):
"Button clicked!")
st.write(
with st.echo():
# Checkbox
= st.checkbox("Check me!")
checkbox_value if checkbox_value:
"Checkbox checked!")
st.write(
with st.echo():
# Selectbox
= st.selectbox("Choose an option", ['Option 1', 'Option 2', 'Option 3'])
option "You selected:", option)
st.write(
with st.echo():
# Slider
= st.slider("Slide me", 0, 100, step=5)
slider_value "Slider value:", slider_value)
st.write(
with st.echo():
= st.number_input("Num input", min_value=0.0, max_value=100., step=5.0) # պետքա float լինի
num_input_value "Number input value:", num_input_value)
st.write(
with st.echo():
= st.text_input("please input text")
text "Text input value:", text)
st.write(
with st.echo():
# File Uploader
= st.file_uploader("Upload a file")
uploaded_file if uploaded_file is not None:
"File uploaded!")
st.write(
st.divider()# Displaying Progress
"Progress")
st.subheader(
# with st.echo():
# progress_bar = st.progress(0)
# for i in range(100):
# sleep(0.1)
# progress_bar.progress(i + 1)
with st.echo():
# Sidebar
"Sidebar")
st.sidebar.header("This is a sidebar.")
st.sidebar.text(
with st.echo():
= st.feedback("stars")
rating1 = st.feedback("faces")
rating2 f"Rating 1: {rating1}")
st.write(f"Rating 2: {rating2}")
st.write(
with st.echo():
= st.color_picker("Pick a color")
color "Selected color:", color)
st.write(
with st.echo():
= st.checkbox("Enable camera")
enable = st.camera_input("Take a picture", disabled=not enable)
picture
if picture:
st.image(picture)
with st.echo():
= st.audio_input("Record a voice message")
audio_value
if audio_value:
st.audio(audio_value)
with st.echo():
= st.columns(3)
col1, col2, col3
with col1:
"A cat")
st.header("https://static.streamlit.io/examples/cat.jpg")
st.image(
with col2:
"A dog")
st.header("https://static.streamlit.io/examples/dog.jpg")
st.image(
with col3:
"An owl")
st.header("https://static.streamlit.io/examples/owl.jpg") st.image(
Recursion
https://xn–y9aa8b7a3an.xn–y9a3aq/%D5%8C%D5%A5%D5%AF%D5%B8%D6%82%D6%80%D5%BD%D5%AB%D5%A1
Նյութեր
https://realpython.com/python-recursion/
Ֆանտաստիկ վիդեո - https://www.youtube.com/watch?v=ngCos392W4w
Շատ հայտնի խնդիր (Հանոյի աշտարակ) ռեկուրսիայով լուծվող - https://www.youtube.com/watch?v=rf6uf3jNjbo
See https://github.com/HaykTarkhanyan/python_math_ml_course/blob/main/python/Recursion.ipynb
Memes
def function():
= 509
x
function()
function()
--------------------------------------------------------------------------- RecursionError Traceback (most recent call last) Input In [9], in <cell line: 5>() 2 x = 509 3 function() ----> 5 function() Input In [9], in function() 1 def function(): 2 x = 509 ----> 3 function() Input In [9], in function() 1 def function(): 2 x = 509 ----> 3 function() [... skipping similar frames: function at line 3 (2970 times)] Input In [9], in function() 1 def function(): 2 x = 509 ----> 3 function() RecursionError: maximum recursion depth exceeded
! Ֆակտորիալ
6! = 6 * 5! = 6 * (5 * 4!) =
def factiorial(n):
return ...
4! = 4 * 3! = 4 * 3 * 2! = 4 * 3 *
def factorial(n):
if n == 1:
return 1
else:
return n * factorial(n - 1)
4) factorial(
24
def factorial(n):
print(f"factorial() called with n = {n}")
if n == 1:
= 1
return_value else:
= n * factorial(n - 1)
return_value print(f"-> factorial({n}) returns {return_value}")
return return_value
4)
factorial(
4) = 4 * 6 | 3 * 2 | 2 * 1
f(
4) = 4 * f(3) = 4 * 3 * f(2) = 4 * 3 * 2 * f(1) = 4 * 3 * 2 * 1 = 24 f(
factorial() called with n = 4
factorial() called with n = 3
factorial() called with n = 2
factorial() called with n = 1
-> factorial(1) returns 1
-> factorial(2) returns 2
-> factorial(3) returns 6
-> factorial(4) returns 24
24
1-n թվերի գումարը
def sum_natural(n):
if n == 1:
return 1
else:
return n + sum_natural(n-1)
5) sum_natural(
15
Ֆիբոնաչի
1, 1, 2, 3, 5, 8, 13, 21, 34, 55
def fibonacci(n: int) -> int:
print(f"fibonacci() called with n = {n}")
if n == 2:
= 1
return_val else:
= fibonacci(n-2) + fibonacci(n-1)
return_val print(f"-> fibonacci({n}) returns {return_val}")
return return_val
4)
fibonacci(
# fibonacci(4-2) -> f(2)
1 + f(4-1)
def fibonacci(n: int) -> int:
assert n > 0, "n must be a positive integer"
print(f"fibonacci() called with n = {n}")
if n == 1:
= 1
return_val elif n == 2:
= 1
return_val else:
= fibonacci(n-2) + fibonacci(n-1)
return_val print(f"-> fibonacci({n}) returns {return_val}")
return return_val
-3)
fibonacci(
# fibonacci(4-2) -> f(2)
# 1 + f(4-1)
# 1 1 2 3
--------------------------------------------------------------------------- AssertionError Traceback (most recent call last) Input In [22], in <cell line: 14>() 11 print(f"-> fibonacci({n}) returns {return_val}") 12 return return_val ---> 14 fibonacci(-3) 16 # fibonacci(4-2) -> f(2) 17 18 # 1 + f(4-1) 19 # 1 1 2 3 Input In [22], in fibonacci(n) 1 def fibonacci(n: int) -> int: ----> 2 assert n > 0, "n must be a positive integer" 4 print(f"fibonacci() called with n = {n}") 5 if n == 1: AssertionError: n must be a positive integer
# 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
def fibonacci(n):
if n == 1:
return 1
elif n == 2:
return 1
else:
return fibonacci(n-1) + fibonacci(n-2)
4) fibonacci(
3
🛠️ Գործնական
🏡Տնային
🎲 12
- ▶️Half as Interesting
- ▶️Random link
- 🇦🇲🎶Carpet Jam
- 🌐🎶Oasis
- 🤌Կարգին