Spaces:
Runtime error
Runtime error
Commit ·
dc8961d
1
Parent(s): 6d77908
Create streamlitapp.py
Browse files- streamlitapp.py +43 -0
streamlitapp.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from functools import partial
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
|
| 4 |
+
#import kangas as kg
|
| 5 |
+
import streamlit as st
|
| 6 |
+
import streamlit.components.v1 as components
|
| 7 |
+
from datasets import load_dataset
|
| 8 |
+
import socket
|
| 9 |
+
|
| 10 |
+
proj_dir = Path(__file__).parent
|
| 11 |
+
|
| 12 |
+
hostname = socket.gethostname()
|
| 13 |
+
ip_address = socket.gethostbyname(hostname)
|
| 14 |
+
|
| 15 |
+
servername = 'calebcometml-kangas-demo.hf.space'
|
| 16 |
+
src = f"https://{servername}:80/kangas"
|
| 17 |
+
|
| 18 |
+
st.set_page_config(layout="wide")
|
| 19 |
+
|
| 20 |
+
st.markdown("1. Select dataset of your choice")
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def kangas_fn(dataset_repo):
|
| 24 |
+
repo_wo_slash = dataset_repo.replace('/', '__') + '.datagrid'
|
| 25 |
+
dg_file_name = repo_wo_slash + '.datagrid'
|
| 26 |
+
with st.spinner("Loading Dataset..."):
|
| 27 |
+
dataset = load_dataset(dataset_repo, split="train")
|
| 28 |
+
with st.spinner("Creating Kangas..."):
|
| 29 |
+
dg = kg.DataGrid(dataset)
|
| 30 |
+
with st.spinner("Saving Kangas..."):
|
| 31 |
+
dg.save(str(proj_dir / 'datagrids' / dg_file_name))
|
| 32 |
+
#kg.show(
|
| 33 |
+
# port=7640,
|
| 34 |
+
# host=servername,
|
| 35 |
+
# protocol="https"
|
| 36 |
+
#)
|
| 37 |
+
height = st.sidebar.slider("iFrame Height", 200, 1500, 900, 100)
|
| 38 |
+
scrolling = st.sidebar.checkbox("iFrame Scrolling")
|
| 39 |
+
|
| 40 |
+
hf_dataset = st.text_input("HuggingFace Dataset", value='beans')
|
| 41 |
+
st.button("Download and Run", on_click=partial(kangas_fn, hf_dataset))
|
| 42 |
+
st.markdown("""Click the dropdown in Kangas to see pre-loaded datasets""")
|
| 43 |
+
st.components.v1.iframe(src, None, height, scrolling=True)
|