Update app.py
Browse files
app.py
CHANGED
|
@@ -2,21 +2,30 @@ import gradio as gr
|
|
| 2 |
from spoken_module import spoken_dashboard
|
| 3 |
from written_module import written_dashboard
|
| 4 |
from file_dashboard import file_based_learning_router
|
|
|
|
| 5 |
|
| 6 |
def main_app():
|
| 7 |
with gr.Blocks(css="light_mode_chatter_owl.css") as app:
|
| 8 |
current_mode = gr.State("spoken")
|
| 9 |
-
nickname = gr.State(
|
| 10 |
|
| 11 |
with gr.Row():
|
| 12 |
-
# ===
|
| 13 |
with gr.Column(scale=1, min_width=220, elem_id="sidebar"):
|
| 14 |
gr.Markdown("### π Educare")
|
| 15 |
-
gr.Markdown("---")
|
| 16 |
|
| 17 |
-
nickname_input = gr.Textbox(label="π€ Your Nickname", placeholder="Enter your name")
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
|
|
|
| 20 |
btn_spoken = gr.Button("π£ Spoken Communication")
|
| 21 |
btn_written = gr.Button("βοΈ Written Communication")
|
| 22 |
gr.Markdown("### π File-Based Learning")
|
|
@@ -27,6 +36,7 @@ def main_app():
|
|
| 27 |
|
| 28 |
# === Main View Panels ===
|
| 29 |
with gr.Column(scale=4):
|
|
|
|
| 30 |
with gr.Column(visible=True, elem_id="module-wrapper") as spoken_panel:
|
| 31 |
spoken_dashboard()
|
| 32 |
|
|
@@ -35,7 +45,7 @@ def main_app():
|
|
| 35 |
|
| 36 |
file_router, switch_view, study_panel, file_panel = file_based_learning_router(nickname)
|
| 37 |
|
| 38 |
-
# === Mode Visibility
|
| 39 |
def switch_mode(mode):
|
| 40 |
return (
|
| 41 |
gr.update(visible=(mode == "spoken")),
|
|
@@ -45,7 +55,7 @@ def main_app():
|
|
| 45 |
mode
|
| 46 |
)
|
| 47 |
|
| 48 |
-
# ===
|
| 49 |
btn_spoken.click(fn=switch_mode, inputs=[gr.State("spoken")],
|
| 50 |
outputs=[spoken_panel, written_panel, study_panel, file_panel, current_mode])
|
| 51 |
|
|
|
|
| 2 |
from spoken_module import spoken_dashboard
|
| 3 |
from written_module import written_dashboard
|
| 4 |
from file_dashboard import file_based_learning_router
|
| 5 |
+
from file_utils import save_nickname_to_db, load_latest_nickname
|
| 6 |
|
| 7 |
def main_app():
|
| 8 |
with gr.Blocks(css="light_mode_chatter_owl.css") as app:
|
| 9 |
current_mode = gr.State("spoken")
|
| 10 |
+
nickname = gr.State(load_latest_nickname()) # Load from DB on start
|
| 11 |
|
| 12 |
with gr.Row():
|
| 13 |
+
# === Sidebar ===
|
| 14 |
with gr.Column(scale=1, min_width=220, elem_id="sidebar"):
|
| 15 |
gr.Markdown("### π Educare")
|
|
|
|
| 16 |
|
| 17 |
+
nickname_input = gr.Textbox(value=load_latest_nickname(), label="π€ Your Nickname", placeholder="Enter your name")
|
| 18 |
+
nickname_display = gr.Markdown(visible=False)
|
| 19 |
+
|
| 20 |
+
def handle_nickname(name):
|
| 21 |
+
save_nickname_to_db(name)
|
| 22 |
+
return gr.update(value=f"β
Hi, {name}!", visible=True), name
|
| 23 |
+
|
| 24 |
+
nickname_input.change(fn=handle_nickname, inputs=[nickname_input], outputs=[nickname_display, nickname])
|
| 25 |
+
|
| 26 |
+
gr.Markdown("---")
|
| 27 |
|
| 28 |
+
# Navigation
|
| 29 |
btn_spoken = gr.Button("π£ Spoken Communication")
|
| 30 |
btn_written = gr.Button("βοΈ Written Communication")
|
| 31 |
gr.Markdown("### π File-Based Learning")
|
|
|
|
| 36 |
|
| 37 |
# === Main View Panels ===
|
| 38 |
with gr.Column(scale=4):
|
| 39 |
+
nickname_display # Render at top
|
| 40 |
with gr.Column(visible=True, elem_id="module-wrapper") as spoken_panel:
|
| 41 |
spoken_dashboard()
|
| 42 |
|
|
|
|
| 45 |
|
| 46 |
file_router, switch_view, study_panel, file_panel = file_based_learning_router(nickname)
|
| 47 |
|
| 48 |
+
# === Mode Visibility Logic ===
|
| 49 |
def switch_mode(mode):
|
| 50 |
return (
|
| 51 |
gr.update(visible=(mode == "spoken")),
|
|
|
|
| 55 |
mode
|
| 56 |
)
|
| 57 |
|
| 58 |
+
# === Button Hooks ===
|
| 59 |
btn_spoken.click(fn=switch_mode, inputs=[gr.State("spoken")],
|
| 60 |
outputs=[spoken_panel, written_panel, study_panel, file_panel, current_mode])
|
| 61 |
|