Spaces:
Sleeping
Sleeping
Refactor to Maps function with exact 4-value returns
Browse files
app.py
CHANGED
|
@@ -1019,56 +1019,68 @@ with gr.Blocks(title="AnatomyBot - MBBS Anatomy Tutor") as demo:
|
|
| 1019 |
|
| 1020 |
# Event Handlers
|
| 1021 |
|
| 1022 |
-
# Navigation Logic
|
| 1023 |
-
def
|
| 1024 |
-
"""
|
| 1025 |
-
|
| 1026 |
-
|
| 1027 |
-
|
| 1028 |
-
|
|
|
|
| 1029 |
return (
|
| 1030 |
-
gr.update(visible=True),
|
| 1031 |
-
gr.update(
|
|
|
|
|
|
|
| 1032 |
)
|
| 1033 |
-
elif
|
| 1034 |
return (
|
| 1035 |
-
gr.update(visible=False),
|
| 1036 |
-
gr.update(
|
|
|
|
|
|
|
| 1037 |
)
|
| 1038 |
-
elif
|
| 1039 |
return (
|
| 1040 |
-
gr.update(visible=False),
|
| 1041 |
-
gr.update(
|
|
|
|
|
|
|
| 1042 |
)
|
| 1043 |
-
elif
|
| 1044 |
return (
|
| 1045 |
-
gr.update(visible=False),
|
| 1046 |
-
gr.update(
|
|
|
|
|
|
|
| 1047 |
)
|
|
|
|
| 1048 |
return (
|
| 1049 |
-
gr.update(visible=True),
|
| 1050 |
-
gr.update(
|
|
|
|
|
|
|
| 1051 |
)
|
| 1052 |
|
| 1053 |
# Bind Navigation Buttons
|
| 1054 |
nav_learning_btn.click(
|
| 1055 |
-
fn=lambda:
|
| 1056 |
-
outputs=[learning_col, viva_col, book_col, admin_col
|
| 1057 |
)
|
| 1058 |
|
| 1059 |
nav_viva_btn.click(
|
| 1060 |
-
fn=lambda:
|
| 1061 |
-
outputs=[learning_col, viva_col, book_col, admin_col
|
| 1062 |
)
|
| 1063 |
|
| 1064 |
nav_book_btn.click(
|
| 1065 |
-
fn=lambda:
|
| 1066 |
-
outputs=[learning_col, viva_col, book_col, admin_col
|
| 1067 |
)
|
| 1068 |
|
| 1069 |
nav_admin_btn.click(
|
| 1070 |
-
fn=lambda:
|
| 1071 |
-
outputs=[learning_col, viva_col, book_col, admin_col
|
| 1072 |
)
|
| 1073 |
|
| 1074 |
# Welcome Screen Handler (now for modal)
|
|
@@ -1145,8 +1157,8 @@ with gr.Blocks(title="AnatomyBot - MBBS Anatomy Tutor") as demo:
|
|
| 1145 |
student_name_state # Return student name (unchanged)
|
| 1146 |
]
|
| 1147 |
).then(
|
| 1148 |
-
fn=lambda:
|
| 1149 |
-
outputs=[learning_col, viva_col, book_col, admin_col
|
| 1150 |
).then(
|
| 1151 |
fn=lambda: gr.update(value="🎯 Start VIVA Training", interactive=True), # Reset button
|
| 1152 |
outputs=[start_viva_btn]
|
|
@@ -1238,8 +1250,8 @@ with gr.Blocks(title="AnatomyBot - MBBS Anatomy Tutor") as demo:
|
|
| 1238 |
question_audio, viva_greeting, student_name_state
|
| 1239 |
]
|
| 1240 |
).then(
|
| 1241 |
-
fn=lambda:
|
| 1242 |
-
outputs=[learning_col, viva_col, book_col, admin_col
|
| 1243 |
).then(
|
| 1244 |
fn=lambda: 0,
|
| 1245 |
outputs=[current_question_idx]
|
|
|
|
| 1019 |
|
| 1020 |
# Event Handlers
|
| 1021 |
|
| 1022 |
+
# Navigation Logic - Maps function returns exactly 4 values for 4 columns
|
| 1023 |
+
def Maps(mode):
|
| 1024 |
+
"""
|
| 1025 |
+
Handle navigation between views with mutual exclusivity.
|
| 1026 |
+
Returns exactly 4 gr.update() objects for:
|
| 1027 |
+
[learning_col, viva_col, book_col, admin_col]
|
| 1028 |
+
"""
|
| 1029 |
+
if mode == "learning":
|
| 1030 |
return (
|
| 1031 |
+
gr.update(visible=True), # learning_col
|
| 1032 |
+
gr.update(visible=False), # viva_col
|
| 1033 |
+
gr.update(visible=False), # book_col
|
| 1034 |
+
gr.update(visible=False) # admin_col
|
| 1035 |
)
|
| 1036 |
+
elif mode == "viva":
|
| 1037 |
return (
|
| 1038 |
+
gr.update(visible=False), # learning_col
|
| 1039 |
+
gr.update(visible=True), # viva_col
|
| 1040 |
+
gr.update(visible=False), # book_col
|
| 1041 |
+
gr.update(visible=False) # admin_col
|
| 1042 |
)
|
| 1043 |
+
elif mode == "book":
|
| 1044 |
return (
|
| 1045 |
+
gr.update(visible=False), # learning_col
|
| 1046 |
+
gr.update(visible=False), # viva_col
|
| 1047 |
+
gr.update(visible=True), # book_col
|
| 1048 |
+
gr.update(visible=False) # admin_col
|
| 1049 |
)
|
| 1050 |
+
elif mode == "admin":
|
| 1051 |
return (
|
| 1052 |
+
gr.update(visible=False), # learning_col
|
| 1053 |
+
gr.update(visible=False), # viva_col
|
| 1054 |
+
gr.update(visible=False), # book_col
|
| 1055 |
+
gr.update(visible=True) # admin_col
|
| 1056 |
)
|
| 1057 |
+
# Default to learning mode
|
| 1058 |
return (
|
| 1059 |
+
gr.update(visible=True), # learning_col
|
| 1060 |
+
gr.update(visible=False), # viva_col
|
| 1061 |
+
gr.update(visible=False), # book_col
|
| 1062 |
+
gr.update(visible=False) # admin_col
|
| 1063 |
)
|
| 1064 |
|
| 1065 |
# Bind Navigation Buttons
|
| 1066 |
nav_learning_btn.click(
|
| 1067 |
+
fn=lambda: Maps("learning"),
|
| 1068 |
+
outputs=[learning_col, viva_col, book_col, admin_col]
|
| 1069 |
)
|
| 1070 |
|
| 1071 |
nav_viva_btn.click(
|
| 1072 |
+
fn=lambda: Maps("viva"),
|
| 1073 |
+
outputs=[learning_col, viva_col, book_col, admin_col]
|
| 1074 |
)
|
| 1075 |
|
| 1076 |
nav_book_btn.click(
|
| 1077 |
+
fn=lambda: Maps("book"),
|
| 1078 |
+
outputs=[learning_col, viva_col, book_col, admin_col]
|
| 1079 |
)
|
| 1080 |
|
| 1081 |
nav_admin_btn.click(
|
| 1082 |
+
fn=lambda: Maps("admin"),
|
| 1083 |
+
outputs=[learning_col, viva_col, book_col, admin_col]
|
| 1084 |
)
|
| 1085 |
|
| 1086 |
# Welcome Screen Handler (now for modal)
|
|
|
|
| 1157 |
student_name_state # Return student name (unchanged)
|
| 1158 |
]
|
| 1159 |
).then(
|
| 1160 |
+
fn=lambda: Maps("viva"),
|
| 1161 |
+
outputs=[learning_col, viva_col, book_col, admin_col]
|
| 1162 |
).then(
|
| 1163 |
fn=lambda: gr.update(value="🎯 Start VIVA Training", interactive=True), # Reset button
|
| 1164 |
outputs=[start_viva_btn]
|
|
|
|
| 1250 |
question_audio, viva_greeting, student_name_state
|
| 1251 |
]
|
| 1252 |
).then(
|
| 1253 |
+
fn=lambda: Maps("viva"),
|
| 1254 |
+
outputs=[learning_col, viva_col, book_col, admin_col]
|
| 1255 |
).then(
|
| 1256 |
fn=lambda: 0,
|
| 1257 |
outputs=[current_question_idx]
|