Spaces:
Running
Running
File size: 1,947 Bytes
cb5b71d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
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()
|