croissant-editor / utils.py
marcenacp's picture
Initial commit
cb5b71d
raw
history blame
1.95 kB
import streamlit as st
from core.state import CurrentProject
from core.state import CurrentStep
from core.state import Metadata
from core.state import SelectedRecordSet
from core.state import SelectedResource
import mlcroissant as mlc
def needed_field(text: str) -> str:
return f"{text}:red[*]"
def jump_to(step: str):
"""Maintains the user's location within the editor."""
if step is not None:
st.session_state[CurrentStep] = step
def init_state(force=False):
"""Initializes the session state. `force=True` to force re-initializing it."""
if Metadata not in st.session_state or force:
st.session_state[Metadata] = Metadata()
if mlc.Dataset not in st.session_state or force:
st.session_state[mlc.Dataset] = None
if CurrentStep not in st.session_state or force:
st.session_state[CurrentStep] = CurrentStep.splash
if SelectedResource not in st.session_state or force:
st.session_state[SelectedResource] = None
if SelectedResource not in st.session_state or force:
st.session_state[SelectedRecordSet] = None
if CurrentProject not in st.session_state or force:
st.session_state[CurrentProject] = CurrentProject.create_new()
# Uncomment those lines if you work locally in order to avoid clicks at each reload.
# And comment all previous lines in `init_state`.
# if mlc.Dataset not in st.session_state or force:
# st.session_state[mlc.Dataset] = mlc.Dataset("../datasets/titanic/metadata.json")
# if Metadata not in st.session_state or force:
# st.session_state[Metadata] = Metadata.from_canonical(
# st.session_state[mlc.Dataset].metadata
# )
# if CurrentStep not in st.session_state or force:
# st.session_state[CurrentStep] = CurrentStep.editor
# if CurrentProject not in st.session_state or force:
# st.session_state[CurrentProject] = CurrentProject.create_new()