Spaces:
Sleeping
Sleeping
Rename Maps to change_view for clarity
Browse files
app.py
CHANGED
|
@@ -1066,42 +1066,47 @@ with gr.Blocks(title="AnatomyBot - MBBS Anatomy Tutor") as demo:
|
|
| 1066 |
|
| 1067 |
# Event Handlers
|
| 1068 |
|
| 1069 |
-
# Navigation Logic -
|
| 1070 |
-
def
|
| 1071 |
"""
|
| 1072 |
Handle navigation between views with mutual exclusivity.
|
| 1073 |
-
|
| 1074 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1075 |
"""
|
| 1076 |
-
if
|
| 1077 |
return (
|
| 1078 |
gr.update(visible=True), # learning_col
|
| 1079 |
gr.update(visible=False), # viva_col
|
| 1080 |
gr.update(visible=False), # book_col
|
| 1081 |
gr.update(visible=False) # admin_col
|
| 1082 |
)
|
| 1083 |
-
elif
|
| 1084 |
return (
|
| 1085 |
gr.update(visible=False), # learning_col
|
| 1086 |
gr.update(visible=True), # viva_col
|
| 1087 |
gr.update(visible=False), # book_col
|
| 1088 |
gr.update(visible=False) # admin_col
|
| 1089 |
)
|
| 1090 |
-
elif
|
| 1091 |
return (
|
| 1092 |
gr.update(visible=False), # learning_col
|
| 1093 |
gr.update(visible=False), # viva_col
|
| 1094 |
gr.update(visible=True), # book_col
|
| 1095 |
gr.update(visible=False) # admin_col
|
| 1096 |
)
|
| 1097 |
-
elif
|
| 1098 |
return (
|
| 1099 |
gr.update(visible=False), # learning_col
|
| 1100 |
gr.update(visible=False), # viva_col
|
| 1101 |
gr.update(visible=False), # book_col
|
| 1102 |
gr.update(visible=True) # admin_col
|
| 1103 |
)
|
| 1104 |
-
# Default to learning mode
|
| 1105 |
return (
|
| 1106 |
gr.update(visible=True), # learning_col
|
| 1107 |
gr.update(visible=False), # viva_col
|
|
@@ -1109,24 +1114,24 @@ with gr.Blocks(title="AnatomyBot - MBBS Anatomy Tutor") as demo:
|
|
| 1109 |
gr.update(visible=False) # admin_col
|
| 1110 |
)
|
| 1111 |
|
| 1112 |
-
# Bind Navigation Buttons
|
| 1113 |
nav_learning_btn.click(
|
| 1114 |
-
fn=lambda:
|
| 1115 |
outputs=[learning_col, viva_col, book_col, admin_col]
|
| 1116 |
)
|
| 1117 |
|
| 1118 |
nav_viva_btn.click(
|
| 1119 |
-
fn=lambda:
|
| 1120 |
outputs=[learning_col, viva_col, book_col, admin_col]
|
| 1121 |
)
|
| 1122 |
|
| 1123 |
nav_book_btn.click(
|
| 1124 |
-
fn=lambda:
|
| 1125 |
outputs=[learning_col, viva_col, book_col, admin_col]
|
| 1126 |
)
|
| 1127 |
|
| 1128 |
nav_admin_btn.click(
|
| 1129 |
-
fn=lambda:
|
| 1130 |
outputs=[learning_col, viva_col, book_col, admin_col]
|
| 1131 |
)
|
| 1132 |
|
|
@@ -1204,7 +1209,7 @@ with gr.Blocks(title="AnatomyBot - MBBS Anatomy Tutor") as demo:
|
|
| 1204 |
student_name_state # Return student name (unchanged)
|
| 1205 |
]
|
| 1206 |
).then(
|
| 1207 |
-
fn=lambda:
|
| 1208 |
outputs=[learning_col, viva_col, book_col, admin_col]
|
| 1209 |
).then(
|
| 1210 |
fn=lambda: gr.update(value="🎯 Start VIVA Training", interactive=True), # Reset button
|
|
@@ -1297,7 +1302,7 @@ with gr.Blocks(title="AnatomyBot - MBBS Anatomy Tutor") as demo:
|
|
| 1297 |
question_audio, viva_greeting, student_name_state
|
| 1298 |
]
|
| 1299 |
).then(
|
| 1300 |
-
fn=lambda:
|
| 1301 |
outputs=[learning_col, viva_col, book_col, admin_col]
|
| 1302 |
).then(
|
| 1303 |
fn=lambda: 0,
|
|
|
|
| 1066 |
|
| 1067 |
# Event Handlers
|
| 1068 |
|
| 1069 |
+
# Navigation Logic - change_view function returns exactly 4 values for 4 columns
|
| 1070 |
+
def change_view(target_view):
|
| 1071 |
"""
|
| 1072 |
Handle navigation between views with mutual exclusivity.
|
| 1073 |
+
|
| 1074 |
+
Args:
|
| 1075 |
+
target_view: The view to display ("learning", "viva", "book", or "admin")
|
| 1076 |
+
|
| 1077 |
+
Returns:
|
| 1078 |
+
Tuple of 4 gr.update() objects for [learning_col, viva_col, book_col, admin_col]
|
| 1079 |
+
Exactly ONE will have visible=True, the rest will have visible=False
|
| 1080 |
"""
|
| 1081 |
+
if target_view == "learning":
|
| 1082 |
return (
|
| 1083 |
gr.update(visible=True), # learning_col
|
| 1084 |
gr.update(visible=False), # viva_col
|
| 1085 |
gr.update(visible=False), # book_col
|
| 1086 |
gr.update(visible=False) # admin_col
|
| 1087 |
)
|
| 1088 |
+
elif target_view == "viva":
|
| 1089 |
return (
|
| 1090 |
gr.update(visible=False), # learning_col
|
| 1091 |
gr.update(visible=True), # viva_col
|
| 1092 |
gr.update(visible=False), # book_col
|
| 1093 |
gr.update(visible=False) # admin_col
|
| 1094 |
)
|
| 1095 |
+
elif target_view == "book":
|
| 1096 |
return (
|
| 1097 |
gr.update(visible=False), # learning_col
|
| 1098 |
gr.update(visible=False), # viva_col
|
| 1099 |
gr.update(visible=True), # book_col
|
| 1100 |
gr.update(visible=False) # admin_col
|
| 1101 |
)
|
| 1102 |
+
elif target_view == "admin":
|
| 1103 |
return (
|
| 1104 |
gr.update(visible=False), # learning_col
|
| 1105 |
gr.update(visible=False), # viva_col
|
| 1106 |
gr.update(visible=False), # book_col
|
| 1107 |
gr.update(visible=True) # admin_col
|
| 1108 |
)
|
| 1109 |
+
# Default to learning mode if invalid target
|
| 1110 |
return (
|
| 1111 |
gr.update(visible=True), # learning_col
|
| 1112 |
gr.update(visible=False), # viva_col
|
|
|
|
| 1114 |
gr.update(visible=False) # admin_col
|
| 1115 |
)
|
| 1116 |
|
| 1117 |
+
# Bind Navigation Buttons - Apply change_view logic to all four top buttons
|
| 1118 |
nav_learning_btn.click(
|
| 1119 |
+
fn=lambda: change_view("learning"),
|
| 1120 |
outputs=[learning_col, viva_col, book_col, admin_col]
|
| 1121 |
)
|
| 1122 |
|
| 1123 |
nav_viva_btn.click(
|
| 1124 |
+
fn=lambda: change_view("viva"),
|
| 1125 |
outputs=[learning_col, viva_col, book_col, admin_col]
|
| 1126 |
)
|
| 1127 |
|
| 1128 |
nav_book_btn.click(
|
| 1129 |
+
fn=lambda: change_view("book"),
|
| 1130 |
outputs=[learning_col, viva_col, book_col, admin_col]
|
| 1131 |
)
|
| 1132 |
|
| 1133 |
nav_admin_btn.click(
|
| 1134 |
+
fn=lambda: change_view("admin"),
|
| 1135 |
outputs=[learning_col, viva_col, book_col, admin_col]
|
| 1136 |
)
|
| 1137 |
|
|
|
|
| 1209 |
student_name_state # Return student name (unchanged)
|
| 1210 |
]
|
| 1211 |
).then(
|
| 1212 |
+
fn=lambda: change_view("viva"),
|
| 1213 |
outputs=[learning_col, viva_col, book_col, admin_col]
|
| 1214 |
).then(
|
| 1215 |
fn=lambda: gr.update(value="🎯 Start VIVA Training", interactive=True), # Reset button
|
|
|
|
| 1302 |
question_audio, viva_greeting, student_name_state
|
| 1303 |
]
|
| 1304 |
).then(
|
| 1305 |
+
fn=lambda: change_view("viva"),
|
| 1306 |
outputs=[learning_col, viva_col, book_col, admin_col]
|
| 1307 |
).then(
|
| 1308 |
fn=lambda: 0,
|