Skip to content

Instantly share code, notes, and snippets.

@kcarnold
Last active April 30, 2024 12:08
Show Gist options
  • Save kcarnold/d212d23d32080b996bed23c4db1e3283 to your computer and use it in GitHub Desktop.
Save kcarnold/d212d23d32080b996bed23c4db1e3283 to your computer and use it in GitHub Desktop.
Streamlit buttons-to-insert-words (predictive text) demo
import streamlit as st
import random
words = ['hello', 'world', 'goodbye', 'moon']
random.shuffle(words)
essay = st.text_area("Essay", "", key="essay")
def append_word(word):
st.session_state['essay'] = (
st.session_state['essay'] + " " + word
)
columns = st.columns(len(words))
for col, word in zip(columns, words):
with col:
st.button(word, on_click=append_word, args=(word,))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment