Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Streamlit button example
import streamlit as st
import requests
st.subheader('existing letters')
letters = requests.get('http://127.0.0.1:8000/letters').json()
for letter in letters:
st.write(letter)
st.subheader('add new letters')
new_candidates = []
for new_letter in ['d', 'e', 'f']:
st.write(f'add {new_letter}')
add_letter = st.checkbox(f'add {new_letter}')
if add_letter:
new_candidates.append(new_letter)
submit = st.button('submit new letters')
if submit:
requests.post('http://127.0.0.1:8000/letters', json=new_candidates)
from fastapi import FastAPI
from typing import List
app = FastAPI()
LETTERS = []
@app.get("/letters")
def list_letters():
return LETTERS
@app.post("/letters")
def add_letters(letters: List[str]):
LETTERS.extend(letters)
return {'added': len(letters)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment