File size: 1,101 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
import os

from etils import epath
import streamlit as st

from core.past_projects import save_current_project
from core.state import CurrentStep
from core.state import Metadata
import mlcroissant as mlc
from utils import jump_to


def render_load():
    file = st.file_uploader("Select a JSON-LD", type="json")
    if file is not None:
        try:
            file_cont = file.read()
            newfile_name = (
                epath.Path("~").expanduser()
                / ".cache"
                / "croissant"
                / "loaded_croissant"
            )
            os.makedirs(os.path.dirname(newfile_name), exist_ok=True)
            with open(newfile_name, mode="wb+") as outfile:
                outfile.write(file_cont)
            dataset = mlc.Dataset(newfile_name)
            st.session_state[Metadata] = Metadata.from_canonical(dataset.metadata)
            jump_to(CurrentStep.editor)
            save_current_project()
            st.rerun()
        except mlc.ValidationError as e:
            st.warning(e)
            st.toast(body="Invalid Croissant File!", icon="🔥")