Spaces:
Sleeping
Sleeping
import streamlit as st | |
import os | |
import json | |
from tools import time_ago, get_skill_datas | |
skills = get_skill_datas() | |
params = st.experimental_get_query_params() | |
st.session_state.skills = skills | |
params = st.experimental_get_query_params() | |
st.sidebar.link_button("Home", url="?page=main", use_container_width=True) | |
for skill in skills: | |
st.sidebar.link_button(f"{skill['skill_name']}", url=f"?page=detail_page&skill_name={skill['skill_name']}", use_container_width=True) | |
def main_page(skills): | |
for skill in skills: | |
with st.expander(f"{skill['skill_metadata']['author']}/{skill['skill_name']}", expanded=True): | |
tags = "`{}`".format("`\t\t`".join(skill['skill_tags'])) | |
st.markdown(f"{tags}") | |
st.markdown(f"**<a href='?page=detail_page&skill_name={skill['skill_name']}' style='font-size: 22px;' target='_self'>{skill['skill_metadata']['author']}/{skill['skill_name']}</a>**", unsafe_allow_html=True) | |
st.markdown(f">**{skill['skill_description']}**") | |
usage = f"from {skill['skill_metadata']['author']}.skill_library.skill_code import {skill['skill_name']}\n{skill['Usage']}" | |
st.code(usage, language=skill['skill_program_language']) | |
st.markdown(f"""```Updated {time_ago(skill['skill_metadata']['updated_at'])}```""") | |
def detail_page(skills): | |
skill = next((skill for skill in skills if skill['skill_name'] == st.session_state.selected_skill_name), None) | |
st.markdown("""<a href='?page=main' target='_self'> | |
<button style='color: #4CAF50; cursor: pointer; border: 1px solid #4CAF50; border-radius: 5px; width: 10%; '> | |
Home | |
</button> | |
</a>""" | |
, unsafe_allow_html=True) | |
st.title(skill['skill_name']) | |
tags = "`{}`".format("`\t\t`".join(skill['skill_tags'])) | |
st.markdown(f"{tags}") | |
st.markdown(f"""```Updated {time_ago(skill['skill_metadata']['updated_at'])}``` ```ver {skill['skill_metadata']['version']}```""") | |
st.markdown(f"## Description") | |
st.markdown(f"{skill['skill_description']}") | |
st.markdown("## Usage") | |
usage = f"from {skill['skill_metadata']['author']}.skill_library.skill_code import {skill['skill_name']}\n{skill['Usage']}" | |
st.code(usage, language=skill['skill_program_language']) | |
with st.expander(f"Parameters", expanded=False): | |
st.markdown("## Parameters") | |
st.code(f"{skill['Parameters']}", language=skill['skill_program_language']) | |
st.markdown("## Returns") | |
st.code(f"{skill['Returns']}", language=skill['skill_program_language']) | |
st.markdown("## Dependencies") | |
st.code(f"{skill['skill_dependencies']}", language=skill['skill_program_language']) | |
with st.expander(f"Code", expanded=False): | |
st.code(f"{skill['skill_code']}", language=skill['skill_program_language']) | |
if 'page' in params: | |
st.session_state.page = params['page'][0] | |
if st.session_state.page == 'detail_page' and 'skill_name' in params: | |
st.session_state.selected_skill_name = params['skill_name'][0] | |
else: | |
st.session_state.page = 'main' | |
if st.session_state.page == 'main': | |
main_page(skills) | |
elif st.session_state.page == 'detail_page': | |
detail_page(skills) | |