Skip to content

Instantly share code, notes, and snippets.

View tvst's full-sized avatar
🦙

Thiago Teixeira tvst

🦙
View GitHub Profile
@tvst
tvst / streamlit_app.py
Last active May 4, 2024 08:48
Simple way to run heavy computations without slowing down other Streamlit users
import streamlit as st
import concurrent.futures # We'll do computations in separate processes!
import mymodule # This is where you'll do the computation
# Your st calls must go inside this IF block.
if __name__ == '__main__':
st.write("Starting a long computation on another process")
# Pick max number of concurrent processes. Depends on how heavy your computation is, and how
# powerful your machine is.
@tvst
tvst / state_class_patch.py
Last active July 30, 2023 22:51
An alternative API for st.session_state using a class decorator.
"""An alternative API for st.session_state using a class decorator.
So instead of doing this...
if "run_counter" in st.session_state:
st.session_state.run_counter = 0
st.session_state.run_counter += 1
st.write("Number of reruns:", st.session_state.run_counter)
@tvst
tvst / Code.gs
Last active October 21, 2022 22:21
Move folder to Shared Drive (AppsScript)
const FOLDER_ID_TO_MOVE = 'FOLDER ID GOES HERE'
const DESTINATION_FOLDER_ID = 'FOLDER ID GOES HERE'
function main() {
const folderToMove = DriveApp.getFolderById(FOLDER_ID_TO_MOVE)
const newParentFolder = DriveApp.getFolderById(DESTINATION_FOLDER_ID)
moveFolder(folderToMove, newParentFolder)
}
function moveFolder(folderToMove, newParentFolder) {
@tvst
tvst / video_compressor.py
Last active May 8, 2021 21:06
Streamlit app that I use when compression video for the Streamlit website. (NOTE: Doesn't currently support audio)
#!/usr/bin/python
import streamlit as st
import subprocess
import os
# Hack to make app runnable directly with "python scriptname.py"
if not st._is_running_with_streamlit:
import sys
import streamlit.bootstrap
@tvst
tvst / downloader.py
Created June 20, 2020 02:58
A simple file downloader for Python
import os
import requests
def download_file(url, folder, filename):
"""Downloads a file from the internet, but only if it doesn't already exist on disk.
Parameters
----------
url : str
import streamlit as st
import pandas as pd
from vega_datasets import data
"""
# Using different charting libraries
"""
@st.cache
import streamlit as st
# Grab SessionState.py from here:
# https://gist.github.com/tvst/036da038ab3e999a64497f42de966a92
# (This is a temporary solution until we provide an official API for this)
import SessionState
DEFAULT_FOO = ""
DEFAULT_BAR = ""
@tvst
tvst / is_running_in_streamlit.py
Created May 20, 2020 20:35
Function to detect if the current script is running inside Streamlit
import threading
def is_running_in_streamlit():
thread = threading.current_thread()
return type(thread).__module__.startswith('streamlit.')
"""Adds an st.rerun() command to Streamlit.
Usage:
import streamlit as st
import st_rerun_patch
# ...
st.rerun()
@tvst
tvst / st_state_patch.py
Last active January 21, 2024 18:31
DO NOT USE!!! Try st.session_state instead.
"""Another prototype of the State implementation.
Usage
-----
How to import this:
import streamlit as st
import st_state_patch