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 / app_leaflet_fasthtml.py
Created September 15, 2024 18:45
Discovering FastHTML with Leaflet
from fasthtml.common import *
leaflet_css = Link(rel="stylesheet", href="https://unpkg.com/[email protected]/dist/leaflet.css", type='text/css')
leaflet_js = Script(src="https://unpkg.com/[email protected]/dist/leaflet.js")
app, rt = fast_app(hdrs=(leaflet_css, leaflet_js), live=True)
@dataclass
class Coords:
latitude:str
@andfanilo
andfanilo / streamlit_app_next_routing.py
Created July 13, 2024 09:32
Pseudo Next.js file-based routing with Streamlit Multipage v2
"""
File-system based router inspired from Next.js, where folders are used to define routes.
Each folder with a page.py maps to a URL segment.
The title for the page in the navigation menu is the argument of the first `st.title` call.
Example Directory Structure:
├── app
│ ├── page.py <- @/
@andfanilo
andfanilo / st_counter_timer_fragments.py
Created April 8, 2024 07:56
Playing with Streamlit Fragments (v1.33) - Timer + Counter
import streamlit as st
##### Initialize Session State
if "counter" not in st.session_state:
st.session_state.counter = 0
if "timer" not in st.session_state:
st.session_state.timer = 0
##### Build Logic into Fragments
@andfanilo
andfanilo / streamlit_app_vega_datasets.py
Last active June 30, 2023 08:08
Vega Datasets Streamlit Explorer
import streamlit as st
from vega_datasets import data
st.title("Vega Datasets Explorer")
all_datasets = data.list_datasets()
selected_dataset = st.selectbox("Select data:", all_datasets)
df = getattr(data, selected_dataset.replace("-", "_"))()
st.dataframe(df, use_container_width=True)
@andfanilo
andfanilo / search_asr_models.py
Created February 18, 2023 07:45
Streamlit + HfAPI to test ASR models
import streamlit as st
from transformers import pipeline
from huggingface_hub import HfApi
from huggingface_hub import ModelFilter
st.set_page_config(page_title="Huggingface Course", page_icon="🤗")
@st.cache_resource
def load_hf_model(model: str):
import streamlit as st
from streamlit.delta_generator import DeltaGenerator
from streamlit.proto.Markdown_pb2 import Markdown as MarkdownProto
from streamlit.string_util import clean_text
def markdown_but_yelling(body, unsafe_allow_html=False):
body = f"# {body.upper()}!!!!"
markdown_proto = MarkdownProto()
markdown_proto.body = clean_text(body)
{
"editor.fontSize": 16, // 16 on demo, 14 otherwise
"editor.lineHeight": 22, // 22 on demo, 18 otherwise
"window.zoomLevel": 1.5, // 1.5 on demo, 1.2 otherwise
"editor.formatOnSave": false,
"editor.formatOnPaste": false,
"editor.lineNumbers": "off",
"editor.quickSuggestionsDelay": 3000,
"editor.quickSuggestions": {
"other": false,
@andfanilo
andfanilo / streamlit_app_stars_per_component.py
Created November 30, 2022 14:36
Scrape Components Tracker wiki
"""
pip install beautifulsoup4 ghapi requests streamlit
Add [github] > key value of your Github API Token in .streamlit/secrets.toml
streamlit run streamlit_app.py
"""
from typing import Tuple
import pandas as pd
import requests
import streamlit as st
@andfanilo
andfanilo / st_intersect_animation.py
Created July 23, 2022 15:32
Intersection Observer API + CSS Transition
import base64
import streamlit as st
import streamlit.components.v1 as components
import plotly.express as px
df = px.data.iris()
@st.experimental_memo
def get_img_as_base64(file):
@andfanilo
andfanilo / st_jspdf.py
Last active September 1, 2022 05:04
Frontend no bundler JSPDF Streamlit app
"""https://www.freakyjolly.com/multipage-canvas-pdf-using-jspdf/"""
import requests
import plotly.express as px
import streamlit as st
import streamlit.components.v1 as components
@st.experimental_memo
def load_unpkg(src: str) -> str:
return requests.get(src).text