Skip to content

Instantly share code, notes, and snippets.

View andfanilo's full-sized avatar
Crazy Streamlitin'

Fanilo Andrianasolo andfanilo

Crazy Streamlitin'
View GitHub Profile
@andfanilo
andfanilo / deploy_streamlit_cc.md
Last active May 19, 2022 04:35
Steps to release Streamlit Custom Component package
  1. Pass flag _release to True
  2. Rebuild frontend:
cd package/frontend
rm -rf build/
npm run build
cd ../../
  1. Rebuild Python:
@andfanilo
andfanilo / streamlit_3d_book_css_generator.py
Last active August 3, 2020 17:57
Streamlit version of 3D Book Image CSS Generator. Also test st.experimental_(get|set)_query_params !
import streamlit as st
import streamlit.components.v1 as components
app_state = st.experimental_get_query_params()
app_state = {k: v[0] if isinstance(v, list) else v for k, v in app_state.items()}
image_url = st.sidebar.text_input("Image URL", "https://d2sofvawe08yqg.cloudfront.net/outstanding-developer/hero2x?1595108679")
bg_color = st.sidebar.beta_color_picker("Book color", "#01060f")
app_state['rotate'] = st.sidebar.slider("Rotate (deg)", 0, 45, 30)
app_state['rotate_hover'] = st.sidebar.slider("Rotate (hover) (deg)", 0, 45, 0)
@andfanilo
andfanilo / data.json
Last active December 22, 2023 12:07
Lottie-web in Streamlit using Jinja
{"v":"4.6.3","fr":30,"ip":0,"op":73,"w":250,"h":275,"nm":"B","ddd":0,"assets":[{"id":"comp_5","layers":[{"ddd":0,"ind":1,"ty":4,"nm":"Shape Layer 1","ks":{"o":{"a":0,"k":100},"r":{"a":0,"k":0},"p":{"a":0,"k":[125,137.5,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":1,"k":[{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_0p833_0p167_0p167","t":1,"s":[{"i":[[0,0],[0,-39],[-1.736,-13.904],[0,0],[1,40],[0.816,16.41]],"o":[[0,0],[0,24.876],[1.461,0.915],[0,0],[-0.217,-8.687],[-0.948,-14.066]],"v":[[-50.5,-49],[-51.5,25],[-50.461,101.585],[-45,100.75],[-49.25,26.75],[-46.578,-23.525]],"c":true}],"e":[{"i":[[0,0],[0,-39],[-2.013,-13.914],[0,0],[-0.25,48.25],[1.394,16.184]],"o":[[0,0],[0,23.955],[1.122,3.104],[0,0],[0.588,-30.586],[-1.558,-14.417]],"v":[[-46,-48.875],[-46.75,23.25],[-45.721,99.703],[-36,95.375],[-41.875,27.875],[-35.594,-24.084]],"c":true}]},{"i":{"x":0.833,"y":0.833},"o":{"x":0.167,"y":0.167},"n":"0p833_
@andfanilo
andfanilo / streamlit_colornamer.py
Last active September 6, 2020 16:06
Streamlit color namer
import numpy as np
from PIL import Image
from colornamer import get_color_from_rgb
import streamlit as st
from streamlit_cropper import st_cropper
st.set_option('deprecation.showfileUploaderEncoding', False)
st.title("Color namer demo")
@andfanilo
andfanilo / streamlit_shap.py
Created September 17, 2020 14:38
SHAP in Streamlit
import shap
import streamlit as st
import streamlit.components.v1 as components
import xgboost
@st.cache
def load_data():
return shap.datasets.boston()
def st_shap(plot, height=None):
@andfanilo
andfanilo / les-miserables.json
Last active December 9, 2020 00:13
Force Layout example in Streamlit
{
"nodes": [
{
"id": "0",
"name": "Myriel",
"itemStyle": null,
"symbolSize": 10,
"x": null,
"y": null,
"attributes": {
@andfanilo
andfanilo / fastpi_share_models.md
Created November 12, 2020 09:00
FastAPI share models

I've been digging in Cortex, just storing this for later ref:

Also dumping a lot of info on async, asyncio, run_in_threadpool, shared objects in FastAPI

@andfanilo
andfanilo / subprocess_st.py
Created December 12, 2020 16:33
Output subprocess in Streamlit
import subprocess
import streamlit as st
def run_command(args):
"""Run command, transfer stdout/stderr back into Streamlit and manage error"""
st.info(f"Running '{' '.join(args)}'")
result = subprocess.run(args, capture_output=True, text=True)
try:
result.check_returncode()
st.info(result.stdout)
@andfanilo
andfanilo / app.py
Last active January 29, 2024 08:25
Pyspark Streamlit demo for university
from pyspark.rdd import RDD
from pyspark.sql import Row
import streamlit as st
from utils import _initialize_spark
st.write("# :tada: Hello Pyspark")
spark, sc = _initialize_spark()
st.write("[Link to Spark window](http://localhost:4040)")
import streamlit.components.v1 as components
mycomponent = components.declare_component(
"mycomponent",
path="./" # instead put index.html and __init__.py into mycomponent folder and put ./mycomponent. Gist does not like subdirectories
)