Spaces:
Running
Running
hide/show sidebar
Browse files
app.py
CHANGED
@@ -146,12 +146,26 @@ def update_ui_with_sections(sections_dict):
|
|
146 |
with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
147 |
gr.Markdown("# Wikipedia Translator")
|
148 |
|
149 |
-
# State
|
150 |
sections_state = gr.State({})
|
|
|
151 |
|
152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
# Sidebar for configuration
|
154 |
-
with gr.Column(scale=1):
|
|
|
|
|
|
|
155 |
gr.Markdown("### Configuration")
|
156 |
|
157 |
with gr.Group():
|
@@ -196,8 +210,12 @@ with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
|
196 |
""")
|
197 |
|
198 |
# Main content area
|
199 |
-
with gr.Column(scale=2):
|
200 |
-
|
|
|
|
|
|
|
|
|
201 |
|
202 |
wiki_url = gr.Textbox(
|
203 |
label="Wikipedia URL",
|
@@ -279,7 +297,20 @@ with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
|
279 |
inputs=[sections_state],
|
280 |
outputs=section_components
|
281 |
)
|
282 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
283 |
# Launch the app
|
284 |
if __name__ == "__main__":
|
285 |
demo.launch()
|
|
|
146 |
with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
147 |
gr.Markdown("# Wikipedia Translator")
|
148 |
|
149 |
+
# State variables
|
150 |
sections_state = gr.State({})
|
151 |
+
sidebar_expanded = gr.State(True) # Track sidebar state, default is expanded
|
152 |
|
153 |
+
def toggle_sidebar(expanded):
|
154 |
+
"""Toggle the sidebar visibility"""
|
155 |
+
new_expanded = not expanded
|
156 |
+
return (
|
157 |
+
new_expanded,
|
158 |
+
gr.update(visible=new_expanded),
|
159 |
+
gr.update(scale=3 if not new_expanded else 2),
|
160 |
+
gr.update(visible=not new_expanded) # Control visibility of the show button
|
161 |
+
)
|
162 |
+
|
163 |
+
with gr.Row() as main_layout:
|
164 |
# Sidebar for configuration
|
165 |
+
with gr.Column(scale=1, visible=True) as sidebar:
|
166 |
+
# Add a toggle button at the top of the sidebar with updated icon
|
167 |
+
sidebar_toggle = gr.Button("« Hide Sidebar", scale=0)
|
168 |
+
|
169 |
gr.Markdown("### Configuration")
|
170 |
|
171 |
with gr.Group():
|
|
|
210 |
""")
|
211 |
|
212 |
# Main content area
|
213 |
+
with gr.Column(scale=2) as main_content:
|
214 |
+
# Show sidebar toggle button when sidebar is hidden (updated icon)
|
215 |
+
with gr.Row():
|
216 |
+
sidebar_show_btn = gr.Button("» Show Sidebar", visible=False, scale=0)
|
217 |
+
with gr.Column(scale=1):
|
218 |
+
gr.Markdown("### Wikipedia Article")
|
219 |
|
220 |
wiki_url = gr.Textbox(
|
221 |
label="Wikipedia URL",
|
|
|
297 |
inputs=[sections_state],
|
298 |
outputs=section_components
|
299 |
)
|
300 |
+
|
301 |
+
# Connect the sidebar toggle buttons
|
302 |
+
sidebar_toggle.click(
|
303 |
+
fn=toggle_sidebar,
|
304 |
+
inputs=[sidebar_expanded],
|
305 |
+
outputs=[sidebar_expanded, sidebar, main_content, sidebar_show_btn]
|
306 |
+
)
|
307 |
+
|
308 |
+
sidebar_show_btn.click(
|
309 |
+
fn=toggle_sidebar,
|
310 |
+
inputs=[sidebar_expanded],
|
311 |
+
outputs=[sidebar_expanded, sidebar, main_content, sidebar_show_btn]
|
312 |
+
)
|
313 |
+
|
314 |
# Launch the app
|
315 |
if __name__ == "__main__":
|
316 |
demo.launch()
|