This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use the official Python 3.10 image as the base image | |
FROM python:3.10 | |
# Set the working directory in the container | |
WORKDIR /app | |
# Install the "uv" package | |
RUN curl -Ls https://astral.sh/uv/install.sh | sh | |
# Initialize the mcp-server using "uv" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from contextlib import contextmanager | |
import re | |
@contextmanager | |
def streamlit_focus(tab_id, snippet_id): | |
''' | |
This is a context manager that will focus the widget with the given widget_key | |
''' | |
def make_valid_identifier_string(text: str, char_prefix='A') -> str: | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# This gist solves 2 problems | |
# 1. Streamlit selectbox sometimes does not return correct value correpsonding to what user selected. | |
# This is a very finicky behavior where the user-selected option, occasionally, reverts back to older option | |
# and thus violating WYSIWYG. This function fixed it | |
# 2. In multi-page apps, the user-selected values in selectbox gets lost when user switches to another page. | |
# This function saves the state and helps these widget maintain state even in multi-page apps | |
# | |
def stateful_selectbox( | |
name, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ngram | |
def fuzzy_match_list_of_strings( | |
l1, | |
l2, | |
common_words=[], | |
verbose=True | |
): | |
''' | |
Accepts 2 lists of strings as arguments and optionally "common_words" as 3rd argument. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def st_select_rows_from_df(pdf, widget_base_key, exclusive=False, ignore_columns=[]): | |
''' | |
This function displays each row with a selectable checkbox | |
Users can select only one of them (or) any number of them depending on the argument "exclusive" | |
Function returns a list of booleans indicating whether the corresponding row was selected or not | |
''' | |
valid_cols = [col for col in pdf.columns if col not in ignore_columns] | |
# Write header | |
view_cols = st.columns(1+len(valid_cols)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import streamlit as st | |
import pandas as pd | |
from pandas.api.types import ( | |
is_categorical_dtype, | |
is_datetime64_any_dtype, | |
is_numeric_dtype, | |
is_object_dtype, | |
) | |
from datetime import datetime |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import streamlit as st | |
from streamlit.components.v1 import html | |
#### HEADER: Start a new div | |
st.markdown('<div id="my-section-{tab_id}"></div>'.format(tab_id = "<your-tab-id>"), unsafe_allow_html=True) | |
#### PLACEHOLDER: BODY: Render the section as per your app using streamlit primitives (st.plotly_chart | |
# | |
# Your Streamlit code rendering whatever you want goes here. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import plotly | |
import plotly.graph_objects as go | |
def plotly_display_number(n, what_is_n, color='Black'): | |
''' | |
Use this display big numbers in plotly | |
Automatically recognizes Thousands/million/Billion and displays with a suitable prefix | |
''' | |
if n > 1e9: | |
n /= 1e9 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Basket iterator class | |
class tagged_basket_iterator: | |
def __init__(self, tb): | |
self._df = tb._df | |
self._index = 0 | |
def __next__(self): | |
total_len = len(self._df) | |
if self._index >= total_len: | |
#print("Raising after {}".format(total_len)) |