Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,49 +1,61 @@
|
|
1 |
import streamlit as st
|
2 |
import os
|
3 |
|
4 |
-
#
|
5 |
-
def local_css(file_name):
|
6 |
-
with open(file_name, "r") as f:
|
7 |
-
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
|
8 |
-
|
9 |
-
# Function to read markdown files
|
10 |
def load_markdown_file(path):
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
# Assuming you will create a style.css for custom styles
|
19 |
-
# Make sure to create a 'style.css' file in your project directory
|
20 |
-
local_css("style.css")
|
21 |
|
22 |
-
# Streamlit UI
|
23 |
-
st.title('π Documentation')
|
24 |
|
25 |
# Assuming your documentation is in the 'docs' folder
|
26 |
docs_base_path = './docs'
|
27 |
|
28 |
-
#
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import os
|
3 |
|
4 |
+
# Improved function to read markdown files with error handling
|
|
|
|
|
|
|
|
|
|
|
5 |
def load_markdown_file(path):
|
6 |
+
try:
|
7 |
+
with open(path, 'r', encoding='utf-8') as file:
|
8 |
+
content = file.read()
|
9 |
+
return content
|
10 |
+
except Exception as e:
|
11 |
+
return f"Error reading file: {e}"
|
|
|
|
|
|
|
|
|
12 |
|
13 |
+
# Streamlit UI Enhancements
|
14 |
+
st.title('π Documentation Viewer')
|
15 |
|
16 |
# Assuming your documentation is in the 'docs' folder
|
17 |
docs_base_path = './docs'
|
18 |
|
19 |
+
# Enhanced error handling for directory listing
|
20 |
+
if not os.path.exists(docs_base_path):
|
21 |
+
st.error('Documentation directory does not exist.')
|
22 |
+
else:
|
23 |
+
# List categories based on folder names with improved error handling
|
24 |
+
try:
|
25 |
+
categories = [d for d in os.listdir(docs_base_path) if os.path.isdir(os.path.join(docs_base_path, d))]
|
26 |
+
if not categories:
|
27 |
+
st.error('No categories found in the documentation directory.')
|
28 |
+
else:
|
29 |
+
category = st.sidebar.selectbox('Select a Category', categories)
|
30 |
+
|
31 |
+
# List pages based on markdown files in the selected category folder
|
32 |
+
pages_path = os.path.join(docs_base_path, category)
|
33 |
+
pages = [f for f in os.listdir(pages_path) if os.path.isfile(os.path.join(pages_path, f)) and f.endswith('.md')]
|
34 |
+
if not pages:
|
35 |
+
st.error('No markdown pages found in the selected category.')
|
36 |
+
else:
|
37 |
+
page = st.sidebar.selectbox('Select a Page', pages)
|
38 |
+
|
39 |
+
# Load and display the selected markdown file
|
40 |
+
markdown_path = os.path.join(pages_path, page)
|
41 |
+
markdown_content = load_markdown_file(markdown_path)
|
42 |
+
st.markdown(markdown_content, unsafe_allow_html=True)
|
43 |
+
except Exception as e:
|
44 |
+
st.error(f"Error listing categories or pages: {e}")
|
45 |
+
|
46 |
+
# Optional: Add a theme or custom CSS for styling
|
47 |
+
st.markdown(
|
48 |
+
"""
|
49 |
+
<style>
|
50 |
+
.css-18e3th9 {
|
51 |
+
background-color: #f0f2f6;
|
52 |
+
}
|
53 |
+
.css-1d391kg {
|
54 |
+
padding-top: 1rem;
|
55 |
+
padding-left: 1rem;
|
56 |
+
padding-right: 1rem;
|
57 |
+
}
|
58 |
+
</style>
|
59 |
+
""",
|
60 |
+
unsafe_allow_html=True,
|
61 |
+
)
|