Spaces:
Runtime error
Runtime error
import streamlit as st | |
import logging | |
# Render Streamlit page | |
st.title("Anonymise your text!") | |
st.markdown( | |
"This mini-app anonymises text using Bert. You can find the code on [GitHub(WIP)](#)" | |
) | |
# Configure logger | |
logging.basicConfig(format="\n%(asctime)s\n%(message)s", level=logging.INFO, force=True) | |
def anonymise_text(text: str, metadata: str = "", white_listed_words: str = ""): | |
st.session_state.text_anon = "this is anonymised" | |
if "text" not in st.session_state: | |
st.session_state.text = "" | |
if "text_error" not in st.session_state: | |
st.session_state.text_error = "" | |
if "text_anon" not in st.session_state: | |
st.session_state.text_anon = "" | |
if "n_requests" not in st.session_state: | |
st.session_state.n_requests = 0 | |
text = st.text_input(label="Text to be anonymised", placeholder="Write your text here") | |
metadata = st.text_input( | |
label="Data to be redacted (optional)", | |
placeholder="inspirational", | |
) | |
white_listed_words = st.text_input( | |
label="Data to be ignored (optional)", | |
placeholder="inspirational", | |
) | |
# button return true when clicked | |
anonymise_now = st.button( | |
label="Anonymise text", | |
type="primary", | |
on_click=anonymise_text, | |
args=(text, metadata, white_listed_words), | |
) | |
text_spinner_placeholder = st.empty() | |
if st.session_state.text_error: | |
st.error(st.session_state.text_error) | |
if st.session_state.text_anon: | |
st.markdown("""---""") | |
st.text_area(label="Text anonymised", value=st.session_state.text_anon, height=100) |