File size: 1,687 Bytes
9575d55
 
9d6439d
9575d55
 
 
 
 
 
d4943e2
87dcf1f
9575d55
d4943e2
 
 
 
9575d55
d4943e2
cb6a8d4
9575d55
 
b86a896
9d6439d
 
 
9575d55
9d6439d
 
 
b86a896
 
9d6439d
d4943e2
 
9d6439d
9575d55
b86a896
d4943e2
 
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
from functools import partial
from pathlib import Path
import os

import kangas as kg
import streamlit as st
import streamlit.components.v1 as components
from datasets import load_dataset

# If you duplicate this space, change this to match your space:
servername = 'comet-team-kangas-demo.hf.space'
st.set_page_config(layout="wide")
proj_dir = Path(__file__).parent

if 'iframe_source' not in st.session_state:
    st.session_state['iframe_source'] = f"https://{servername}/kangas/?datagrid=.%2Fdatagrids%2Fcoco-500.datagrid"

st.markdown("# HuggingFace Spaces + Streamlit + Kangas")
st.markdown("1. Enter the name of a HuggingFace dataset and Download, or select one below in Kangas")

def kangas_fn(dataset_repo):
    global src
    dg_file_name = dataset_repo.replace('/', '__') + '.datagrid'
    dg_full_path = str(proj_dir / 'datagrids' / dg_file_name)
    with st.spinner("2. Loading Dataset..."):
        dataset = load_dataset(dataset_repo, split="train")
    with st.spinner("3. Creating Kangas..."):
        if not os.path.exists(dg_full_path):
            dg = kg.DataGrid(dataset)
    with st.spinner("4. Saving Kangas..."):
        if not os.path.exists(dg_full_path):
            dg.save(dg_full_path)
    with st.spinner("5. Loading Kangas..."):
        st.session_state['iframe_source'] = f"https://{servername}/kangas/?datagrid=.%2Fdatagrids%2F" + dg_file_name
        
hf_dataset = st.text_input("HuggingFace Dataset", value='beans')
st.button("Download", on_click=partial(kangas_fn, hf_dataset))
st.markdown("""Click the dropdown in Kangas to select a previously-downloaded dataset""")
components.iframe(st.session_state['iframe_source'], None, 1000, scrolling=True)