seawolf2357 commited on
Commit
c04dd6c
·
verified ·
1 Parent(s): 07a4b41

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +134 -44
app.py CHANGED
@@ -1,56 +1,146 @@
1
  import streamlit as st
2
- import streamlit.components.v1 as components
3
 
4
- # Set page config for dark theme
5
- st.set_page_config(layout="wide", page_title="Web UI", page_icon=":ghost:", initial_sidebar_state="expanded")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
- # Apply dark theme and maximize iframe
8
- st.markdown("""
9
- <style>
10
- #root > div:nth-child(1) > div > div > div > div > section > div {padding-top: 0rem;}
11
- .reportview-container {background-color: #000000;}
12
- .sidebar .sidebar-content {background-color: #262730;}
13
- .Widget>label {color: white;}
14
- .stRadio>div{color: white;}
15
- .stCheckbox>div{color: white;}
16
- .stSelectbox>div{color: white;}
17
- .main .block-container {background-color: #000000; padding: 0rem;}
18
- iframe {width: 100vw; height: 100vh; border: none;}
19
- header {visibility: hidden;}
20
- #MainMenu {visibility: hidden;}
21
- footer {visibility: hidden;}
22
- </style>
23
- """, unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  # Sidebar menu
26
  st.sidebar.title("메뉴")
27
- menu = st.sidebar.radio("선택하세요:", ("A", "B"))
 
 
 
 
 
 
 
 
 
 
 
28
 
29
  # Main content
30
- if menu == "A":
31
- components.iframe("https://seawolf2357-flxloraexp.hf.space", height=1000, scrolling=True)
32
- elif menu == "B":
33
- try:
34
- components.iframe("http://hugpu.ai:7897", height=1000, scrolling=True)
35
- except Exception as e:
36
- st.error(f"B 메뉴 로딩 중 오류 발생: {str(e)}")
37
- st.info("http://hugpu.ai:8000 에 접근할 수 없습니다. URL이 올바른지, 그리고 공개적으로 접근 가능한지 확인해 주세요.")
38
-
39
- # Make the layout responsive and ensure iframes are loaded correctly
 
 
 
 
 
 
 
 
 
40
  st.markdown("""
41
  <script>
42
- window.addEventListener('load', function() {
43
- var iframes = document.getElementsByTagName('iframe');
44
- for (var i = 0; i < iframes.length; i++) {
45
- iframes[i].style.height = window.innerHeight + 'px';
46
- iframes[i].style.width = '100%';
47
- }
48
- });
49
- window.addEventListener('resize', function() {
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)