import streamlit as st import pandas as pd import os from pathlib import Path from streamlit.errors import DuplicateWidgetID main_content, right_sidebar = st.columns([5, 2]) @st.cache_data() def toggle_state(): return {"toggled": False} if 'onthology' not in st.session_state: st.session_state['onthology'] = "No onthology selected" def get_similar_meta_file(path): return path.parent / (str(path.stem) + "_meta.csv") def projects(): with main_content: projects = ["my_project", "make_it_meta"] st.markdown("# Project Creation and Naming") markdown = "" for project in projects: markdown += f"- {project}\n" st.markdown(markdown) def datasets(): with main_content: try: datasets = list((Path(".").resolve() / "samples").glob("*")) datasets_not_meta = [x for x in datasets if ("csv" in str(x) or "tsv" in str(x)) and "_meta" not in str(x)] datasets_meta = [x for x in datasets if ("csv" in str(x) or "tsv" in str(x)) and "_meta" in str(x)] st.markdown("# Data selection and Uploading") selected_option = st.selectbox("Select a dataset", set([x.stem for x in datasets_not_meta if get_similar_meta_file(x) in datasets_meta])) selected_mode = st.selectbox("Select mode", ["Causual", "Makeitmeta"]) for file in datasets: if selected_option == file.stem: sep = "," if "csv" in file.stem else "\t" if selected_mode == "Makeitmeta": file = get_similar_meta_file(file) sep = "," df = pd.read_csv(str(file), sep=sep) st.experimental_data_editor(df, key="data_editor_" + str(selected_mode)) st.markdown("### If you want to upload a dataset you can do it below:") uploaded_file = st.file_uploader("Upload a file", type=["csv", "tsv", "pk", "gz"]) if uploaded_file is not None: # Do something with the uploaded file, e.g., display its name st.write(uploaded_file.name) except DuplicateWidgetID as e: pass def labeling(): with main_content: st.markdown("# Labeling selection and Uploading") if st.session_state.onthology: st.markdown(f"### Current onthologdy: {st.session_state.onthology}") with right_sidebar: query = st.text_input('Search bar', '') if query == "": st.write("Search results") else: st.write(f"Printing results for query: {query}") def ontologies(): with main_content: onthologies = ["caDSR", "UMLS"] st.markdown("# Ontology Selection") onthology = st.selectbox( 'Select your onthology', tuple(onthologies) ) st.session_state.onthology = onthology st.write('You selected:', onthology) pages = { "Datasets": datasets, "Projects": projects, "Labeling": labeling, "Ontologies": ontologies } # st.sidebar.title("Navigation") # selection1 = st.sidebar.button("Projects") # if selection1: # projects() # selection2 = st.sidebar.button("Datasets") # if selection2: # datasets() # selection3 = st.sidebar.button("Labeling") # if selection3: # labeling() # selection4 = st.sidebar.button("Ontologies") # if selection4: # ontologies() selected_page = st.sidebar.selectbox("Select a page", pages.keys()) pages[selected_page]()