Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,56 +1,146 @@
|
|
1 |
import streamlit as st
|
2 |
-
import streamlit.components.v1 as components
|
3 |
|
4 |
-
#
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
#
|
8 |
-
st.
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
# Sidebar menu
|
26 |
st.sidebar.title("메뉴")
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
# Main content
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
st.markdown("""
|
41 |
<script>
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
var iframes = document.getElementsByTagName('iframe');
|
51 |
-
for (var i = 0; i < iframes.length; i++) {
|
52 |
-
iframes[i].style.height = window.innerHeight + 'px';
|
53 |
-
}
|
54 |
-
});
|
55 |
</script>
|
56 |
""", unsafe_allow_html=True)
|
|
|
1 |
import streamlit as st
|
|
|
2 |
|
3 |
+
# CSS styles
|
4 |
+
css = """
|
5 |
+
body {
|
6 |
+
background-color: #000000;
|
7 |
+
color: #FFFFFF;
|
8 |
+
}
|
9 |
+
.main {
|
10 |
+
background-color: #000000;
|
11 |
+
}
|
12 |
+
.main .block-container {
|
13 |
+
padding: 0rem;
|
14 |
+
background-color: #000000;
|
15 |
+
}
|
16 |
+
.sidebar .sidebar-content {
|
17 |
+
background-color: #D9D9D9 !important;
|
18 |
+
padding: 1rem;
|
19 |
+
}
|
20 |
+
header, #MainMenu, footer {visibility: hidden;}
|
21 |
+
.category-button {
|
22 |
+
background-color: #D9D9D9;
|
23 |
+
color: #333333;
|
24 |
+
border: none;
|
25 |
+
text-align: left;
|
26 |
+
font-size: 1.1rem;
|
27 |
+
font-weight: bold;
|
28 |
+
padding: 10px;
|
29 |
+
width: 100%;
|
30 |
+
margin-bottom: 5px;
|
31 |
+
transition: background-color 0.3s;
|
32 |
+
}
|
33 |
+
.category-button:hover {
|
34 |
+
background-color: #C0C0C0;
|
35 |
+
}
|
36 |
+
.category-button:focus {
|
37 |
+
outline: none;
|
38 |
+
}
|
39 |
+
.selected-category {
|
40 |
+
background-color: #C0C0C0 !important;
|
41 |
+
color: #000000 !important;
|
42 |
+
}
|
43 |
+
.submenu-button {
|
44 |
+
background-color: #E6E6E6;
|
45 |
+
color: #333333;
|
46 |
+
border: none;
|
47 |
+
text-align: left;
|
48 |
+
font-size: 1rem;
|
49 |
+
padding: 6px 20px;
|
50 |
+
width: 100%;
|
51 |
+
margin-bottom: 3px;
|
52 |
+
transition: background-color 0.3s;
|
53 |
+
}
|
54 |
+
.submenu-button:hover {
|
55 |
+
background-color: #D0D0D0;
|
56 |
+
}
|
57 |
+
.submenu-button:focus {
|
58 |
+
outline: none;
|
59 |
+
}
|
60 |
+
.selected-submenu {
|
61 |
+
background-color: #C0C0C0 !important;
|
62 |
+
color: #000000 !important;
|
63 |
+
font-weight: bold;
|
64 |
+
}
|
65 |
+
"""
|
66 |
|
67 |
+
# Set page config
|
68 |
+
st.set_page_config(
|
69 |
+
layout="wide",
|
70 |
+
page_title="Web UI",
|
71 |
+
page_icon=":ghost:",
|
72 |
+
initial_sidebar_state="expanded"
|
73 |
+
)
|
74 |
+
|
75 |
+
# Apply CSS
|
76 |
+
st.markdown(f"<style>{css}</style>", unsafe_allow_html=True)
|
77 |
+
|
78 |
+
# Menu structure (can be easily extended for multi-language support)
|
79 |
+
menu_structure = {
|
80 |
+
"A 카테고리": ["a", "b"],
|
81 |
+
"B 카테고리": ["c", "d"]
|
82 |
+
}
|
83 |
+
|
84 |
+
# Initialize session state
|
85 |
+
if 'expanded_category' not in st.session_state:
|
86 |
+
st.session_state.expanded_category = None
|
87 |
+
if 'selected_item' not in st.session_state:
|
88 |
+
st.session_state.selected_item = None
|
89 |
+
|
90 |
+
# Functions
|
91 |
+
def toggle_category(category):
|
92 |
+
if st.session_state.expanded_category == category:
|
93 |
+
st.session_state.expanded_category = None
|
94 |
+
else:
|
95 |
+
st.session_state.expanded_category = category
|
96 |
+
|
97 |
+
def select_item(item):
|
98 |
+
st.session_state.selected_item = item
|
99 |
|
100 |
# Sidebar menu
|
101 |
st.sidebar.title("메뉴")
|
102 |
+
|
103 |
+
for category, items in menu_structure.items():
|
104 |
+
is_expanded = st.session_state.expanded_category == category
|
105 |
+
category_label = f"{'▼' if is_expanded else '▶'} {category}"
|
106 |
+
if st.sidebar.button(category_label, key=f"category_{category}", on_click=toggle_category, args=(category,)):
|
107 |
+
pass
|
108 |
+
|
109 |
+
if is_expanded:
|
110 |
+
for item in items:
|
111 |
+
is_selected = st.session_state.selected_item == item
|
112 |
+
if st.sidebar.button(item, key=f"submenu_{item}", on_click=select_item, args=(item,)):
|
113 |
+
pass
|
114 |
|
115 |
# Main content
|
116 |
+
main_content = st.empty()
|
117 |
+
|
118 |
+
# Content mapping
|
119 |
+
content_map = {
|
120 |
+
"a": "https://seawolf2357-flxloraexp.hf.space",
|
121 |
+
"b": "https://seawolf2357-timer2.hf.space",
|
122 |
+
"c": "https://seawolf2357-timer3.hf.space",
|
123 |
+
"d": "https://seawolf2357-timer4.hf.space"
|
124 |
+
}
|
125 |
+
|
126 |
+
if st.session_state.selected_item in content_map:
|
127 |
+
main_content.markdown(
|
128 |
+
f'<iframe src="{content_map[st.session_state.selected_item]}" width="100%" height="800" frameborder="0"></iframe>',
|
129 |
+
unsafe_allow_html=True
|
130 |
+
)
|
131 |
+
else:
|
132 |
+
main_content.markdown("<h2>메뉴에서 항목을 선택하세요.</h2>")
|
133 |
+
|
134 |
+
# Add JavaScript for dynamic iframe resizing
|
135 |
st.markdown("""
|
136 |
<script>
|
137 |
+
function resizeIframe() {
|
138 |
+
var iframe = document.querySelector('iframe');
|
139 |
+
if (iframe) {
|
140 |
+
iframe.style.height = window.innerHeight + 'px';
|
141 |
+
}
|
142 |
+
}
|
143 |
+
window.addEventListener('resize', resizeIframe);
|
144 |
+
resizeIframe();
|
|
|
|
|
|
|
|
|
|
|
145 |
</script>
|
146 |
""", unsafe_allow_html=True)
|