Skip to content

Instantly share code, notes, and snippets.

View tvst's full-sized avatar
🦙

Thiago Teixeira tvst

🦙
View GitHub Profile
@tvst
tvst / timeit.py
Last active October 11, 2019 07:21
An easy-to-use poor-man's profiler using Streamlit. See: https://discuss.streamlit.io/t/how-to-tell-which-variables-are-being-recomputed/359
import streamlit as st
import time
class TimeIt(object):
"""Simple timer for profiling Streamlit apps.
Usage
-----
@tvst
tvst / st_rerun.py
Last active January 13, 2022 20:42
DO NOT USE! There's an experimental API in Streamlit now, called st.experimental_rerun()
from streamlit.ScriptRequestQueue import RerunData
from streamlit.ScriptRunner import RerunException
from streamlit.server.Server import Server
import streamlit.ReportThread as ReportThread
def rerun():
"""Rerun a Streamlit app from the top!"""
widget_states = _get_widget_states()
raise RerunException(RerunData(widget_states))
const MEDIA_TYPE = "video/webm;codecs=vp9,opus"
//const MEDIA_TYPE = "video/webm;codecs=h264"
const BLOB_TYPE = "video/webm"
class ScreenCastRecorder {
constructor({ recordAudio }) {
this.recordAudio = recordAudio
this.inputStream = null
@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
"""Adds an st.rerun() command to Streamlit.
Usage:
import streamlit as st
import st_rerun_patch
# ...
st.rerun()
@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.')
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 = ""
import streamlit as st
import pandas as pd
from vega_datasets import data
"""
# Using different charting libraries
"""
@st.cache
@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
@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