Skip to content

Instantly share code, notes, and snippets.

View asehmi's full-sized avatar

Arvindra Sehmi asehmi

View GitHub Profile
@asehmi
asehmi / mplfinance_streamlit_demo.py
Last active June 2, 2025 07:02
How to use mplfinance in Streamlit
from datetime import date, datetime
import streamlit as st
import pandas as pd
import mplfinance as mpf
from pandas_datareader import data as pdr
@st.experimental_memo(persist='disk')
def get_historical_data(symbol, start_date = None):
df = pdr.get_data_yahoo(symbol, start=start_date, end=datetime.now())
for col in df.columns:
@asehmi
asehmi / mapping-the-parallels.md
Created February 3, 2025 23:09
medium Post: Journey Through a Recent AI Project
Project Stage Project Storyline Hiking Analogy Storyline
Project Initiation Started a machine vision and Gen-AI solution for an e-commerce company, expecting a straightforward implementation. Embarked on a hike to a renowned Grenadian waterfall, expecting an easy journey based on initial guidance.
Embarking on a journey to develop a machine vision and Gen-AI based solution for auto-tagging and recommending relat
@asehmi
asehmi / embedded_flask_server_app.py
Created September 27, 2022 17:24
Embedding Flask in Streamlit
import requests
import streamlit as st
state = st.session_state
if 'flask_started' not in state:
state.flask_started = False
def start_flask():
if state.flask_started:
return
@asehmi
asehmi / stqdm-demo.py
Last active October 14, 2024 06:38
STqdm: A tqdm-like progress bar for Streamlit
# UPDATED: 5-MAY-2023
from multiprocessing import Pool, freeze_support
from time import sleep
import streamlit as st
# https://discuss.streamlit.io/t/stqdm-a-tqdm-like-progress-bar-for-streamlit/10097
# pip install stqdm
from stqdm import stqdm
@asehmi
asehmi / session_state_callback_demos.py
Last active September 19, 2024 12:20
Streamlit widget session state and callbacks mini-tutorial
#
# This seems to be a common issue amongst new Streamlit users, so I wrote a mini-tutorial app to explain how widgets
# are used with initialized values and how to make them stick using session state and callbacks.
#
# There are three ways:
#
# (1) The most basic where the initial value is not given but the widget is always reset,
# (2) Where it’s initialized but there are issues getting the return value to stick, and finally
# (3) Overcoming all issues with session state and callbacks.
#
@asehmi
asehmi / st-option-menu.py
Last active August 13, 2024 04:59
streamlit_option_menu component for Streamlit
# UPDATED: 2 May 2022
import streamlit as st
# https://discuss.streamlit.io/t/streamlit-option-menu-is-a-simple-streamlit-component-that-allows-users-to-select-a-single-item-from-a-list-of-options-in-a-menu
# https://icons.getbootstrap.com/
from streamlit_option_menu import option_menu
st.set_page_config(page_title='Muti-page app example', layout='wide')
def do_upload_tasks():
@asehmi
asehmi / streamlit_debug.py
Last active August 7, 2024 13:13
Handy script I made to help streamline Streamlit debugging
# How to use:
#
# [1] Ensure you have `debugpy` installed:
#
# > pip install debugpy
#
# [2] In your main streamlit app:
#
# import streamlit_debug
# streamlit_debug.set(flag=True, wait_for_client=True, host='localhost', port=8765)
@asehmi
asehmi / st_server_runtime_client_cookies_tests.py
Created October 7, 2022 01:35
Streamlit hack to get current server and client session info (Streamlit >= v1.12.0)
# See discussion: https://github.com/streamlit/streamlit/pull/5457
import re
import streamlit as st
try:
# Streamlit >= 1.12.0
from streamlit.web.server.server import Server
from streamlit.runtime.runtime import Runtime, SessionInfo
from streamlit.runtime.scriptrunner import add_script_run_ctx
# from streamlit.runtime.scriptrunner import get_script_run_ctx
@asehmi
asehmi / multithreaded_processing_of_queued_data.py
Created November 27, 2023 19:14
Streamlit multi-threaded task execution, with queues
import time
import random
from queue import Queue
import threading
import streamlit as st
from streamlit.runtime.scriptrunner import add_script_run_ctx
pre_msgs = []
result_msgs = []
post_msgs = []
@asehmi
asehmi / st_fixed_container.py
Created April 1, 2024 16:19 — forked from toolittlecakes/st_fixed_container.py
Sticky/fixed container for streamlit apps. Supports dynamic width change as well as dynamic color updates. Both top/bottom positions are available.
from typing import Literal
import streamlit as st
from streamlit.components.v1 import html
FIXED_CONTAINER_CSS = """
div[data-testid="stVerticalBlockBorderWrapper"]:has(div.fixed-container-{id}):not(:has(div.not-fixed-container)) {{
position: {mode};
width: inherit;