Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -881,6 +881,15 @@ def create_interface():
|
|
| 881 |
session_token = gr.State(value=generate_session_token())
|
| 882 |
profile_manager.set_session(session_token.value)
|
| 883 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 884 |
# Custom CSS for better styling
|
| 885 |
app.css = """
|
| 886 |
.gradio-container {
|
|
@@ -915,6 +924,29 @@ def create_interface():
|
|
| 915 |
.chatbot {
|
| 916 |
min-height: 500px;
|
| 917 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 918 |
"""
|
| 919 |
|
| 920 |
gr.Markdown("""
|
|
@@ -923,18 +955,24 @@ def create_interface():
|
|
| 923 |
Complete each step to get customized learning recommendations.
|
| 924 |
""")
|
| 925 |
|
| 926 |
-
# Progress tracker
|
| 927 |
with gr.Row():
|
| 928 |
with gr.Column(scale=1):
|
| 929 |
-
step1 = gr.Button("1. Upload Transcript",
|
| 930 |
with gr.Column(scale=1):
|
| 931 |
-
step2 = gr.Button("2. Learning Style Quiz")
|
| 932 |
with gr.Column(scale=1):
|
| 933 |
-
step3 = gr.Button("3. Personal Questions")
|
| 934 |
with gr.Column(scale=1):
|
| 935 |
-
step4 = gr.Button("4. Save & Review")
|
| 936 |
with gr.Column(scale=1):
|
| 937 |
-
step5 = gr.Button("5. AI Assistant")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 938 |
|
| 939 |
# Main tabs
|
| 940 |
with gr.Tabs() as tabs:
|
|
@@ -966,10 +1004,22 @@ def create_interface():
|
|
| 966 |
)
|
| 967 |
transcript_data = gr.State()
|
| 968 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 969 |
upload_btn.click(
|
| 970 |
-
fn=
|
| 971 |
-
inputs=transcript_file,
|
| 972 |
-
outputs=[transcript_output, transcript_data]
|
| 973 |
)
|
| 974 |
|
| 975 |
# ===== TAB 2: Learning Style Quiz =====
|
|
@@ -1011,13 +1061,28 @@ def create_interface():
|
|
| 1011 |
outputs=progress
|
| 1012 |
)
|
| 1013 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1014 |
quiz_submit.click(
|
| 1015 |
-
fn=
|
| 1016 |
-
inputs=quiz_components,
|
| 1017 |
-
outputs=learning_output
|
| 1018 |
-
).then(
|
| 1019 |
-
fn=lambda: gr.Markdown(visible=True),
|
| 1020 |
-
outputs=learning_output
|
| 1021 |
)
|
| 1022 |
|
| 1023 |
# ===== TAB 3: Personal Questions =====
|
|
@@ -1064,6 +1129,31 @@ def create_interface():
|
|
| 1064 |
inputs=blog_checkbox,
|
| 1065 |
outputs=blog_text
|
| 1066 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1067 |
|
| 1068 |
# ===== TAB 4: Save & Review =====
|
| 1069 |
with gr.Tab("Save Profile", id=3) as tab4:
|
|
@@ -1094,14 +1184,29 @@ def create_interface():
|
|
| 1094 |
)
|
| 1095 |
|
| 1096 |
# Save profile
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1097 |
save_btn.click(
|
| 1098 |
-
fn=
|
| 1099 |
inputs=[
|
| 1100 |
name, age, interests, transcript_data, learning_output,
|
| 1101 |
movie, movie_reason, show, show_reason,
|
| 1102 |
-
book, book_reason, character, character_reason, blog_text
|
|
|
|
| 1103 |
],
|
| 1104 |
-
outputs=output_summary
|
| 1105 |
).then(
|
| 1106 |
fn=lambda: profile_manager.list_profiles(session_token.value),
|
| 1107 |
outputs=load_profile_dropdown
|
|
@@ -1159,6 +1264,15 @@ def create_interface():
|
|
| 1159 |
book, book_reason, character, character_reason,
|
| 1160 |
blog_text
|
| 1161 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1162 |
)
|
| 1163 |
|
| 1164 |
# ===== TAB 5: AI Teaching Assistant =====
|
|
@@ -1179,29 +1293,42 @@ def create_interface():
|
|
| 1179 |
title=""
|
| 1180 |
)
|
| 1181 |
|
| 1182 |
-
# Tab navigation logic
|
| 1183 |
-
def navigate_to_tab(tab_index: int):
|
| 1184 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1185 |
|
| 1186 |
step1.click(
|
| 1187 |
-
fn=lambda: navigate_to_tab(
|
| 1188 |
-
|
|
|
|
| 1189 |
)
|
| 1190 |
step2.click(
|
| 1191 |
-
fn=lambda: navigate_to_tab(
|
| 1192 |
-
|
|
|
|
| 1193 |
)
|
| 1194 |
step3.click(
|
| 1195 |
-
fn=lambda: navigate_to_tab(
|
| 1196 |
-
|
|
|
|
| 1197 |
)
|
| 1198 |
step4.click(
|
| 1199 |
-
fn=lambda: navigate_to_tab(
|
| 1200 |
-
|
|
|
|
| 1201 |
)
|
| 1202 |
step5.click(
|
| 1203 |
-
fn=lambda: navigate_to_tab(
|
| 1204 |
-
|
|
|
|
| 1205 |
)
|
| 1206 |
|
| 1207 |
return app
|
|
|
|
| 881 |
session_token = gr.State(value=generate_session_token())
|
| 882 |
profile_manager.set_session(session_token.value)
|
| 883 |
|
| 884 |
+
# Track completion status for each tab
|
| 885 |
+
tab_completed = gr.State({
|
| 886 |
+
0: False, # Transcript Upload
|
| 887 |
+
1: False, # Learning Style Quiz
|
| 888 |
+
2: False, # Personal Questions
|
| 889 |
+
3: False, # Save & Review
|
| 890 |
+
4: False # AI Assistant
|
| 891 |
+
})
|
| 892 |
+
|
| 893 |
# Custom CSS for better styling
|
| 894 |
app.css = """
|
| 895 |
.gradio-container {
|
|
|
|
| 924 |
.chatbot {
|
| 925 |
min-height: 500px;
|
| 926 |
}
|
| 927 |
+
.completed-tab {
|
| 928 |
+
background: #2196F3 !important;
|
| 929 |
+
color: white !important;
|
| 930 |
+
}
|
| 931 |
+
.incomplete-tab {
|
| 932 |
+
background: #E0E0E0 !important;
|
| 933 |
+
}
|
| 934 |
+
.alert-box {
|
| 935 |
+
padding: 15px;
|
| 936 |
+
margin-bottom: 20px;
|
| 937 |
+
border: 1px solid transparent;
|
| 938 |
+
border-radius: 4px;
|
| 939 |
+
color: #31708f;
|
| 940 |
+
background-color: #d9edf7;
|
| 941 |
+
border-color: #bce8f1;
|
| 942 |
+
}
|
| 943 |
+
.nav-message {
|
| 944 |
+
padding: 10px;
|
| 945 |
+
margin: 10px 0;
|
| 946 |
+
border-radius: 4px;
|
| 947 |
+
background-color: #ffebee;
|
| 948 |
+
color: #c62828;
|
| 949 |
+
}
|
| 950 |
"""
|
| 951 |
|
| 952 |
gr.Markdown("""
|
|
|
|
| 955 |
Complete each step to get customized learning recommendations.
|
| 956 |
""")
|
| 957 |
|
| 958 |
+
# Progress tracker - now with dynamic styling
|
| 959 |
with gr.Row():
|
| 960 |
with gr.Column(scale=1):
|
| 961 |
+
step1 = gr.Button("1. Upload Transcript", elem_classes="incomplete-tab")
|
| 962 |
with gr.Column(scale=1):
|
| 963 |
+
step2 = gr.Button("2. Learning Style Quiz", elem_classes="incomplete-tab", interactive=False)
|
| 964 |
with gr.Column(scale=1):
|
| 965 |
+
step3 = gr.Button("3. Personal Questions", elem_classes="incomplete-tab", interactive=False)
|
| 966 |
with gr.Column(scale=1):
|
| 967 |
+
step4 = gr.Button("4. Save & Review", elem_classes="incomplete-tab", interactive=False)
|
| 968 |
with gr.Column(scale=1):
|
| 969 |
+
step5 = gr.Button("5. AI Assistant", elem_classes="incomplete-tab", interactive=False)
|
| 970 |
+
|
| 971 |
+
# Alert box for quiz submission
|
| 972 |
+
quiz_alert = gr.HTML(visible=False)
|
| 973 |
+
|
| 974 |
+
# Navigation message
|
| 975 |
+
nav_message = gr.HTML(elem_classes="nav-message", visible=False)
|
| 976 |
|
| 977 |
# Main tabs
|
| 978 |
with gr.Tabs() as tabs:
|
|
|
|
| 1004 |
)
|
| 1005 |
transcript_data = gr.State()
|
| 1006 |
|
| 1007 |
+
def process_transcript_and_update(file_obj, current_tab_status):
|
| 1008 |
+
output_text, data = parse_transcript(file_obj)
|
| 1009 |
+
if "Error" not in output_text:
|
| 1010 |
+
new_status = current_tab_status.copy()
|
| 1011 |
+
new_status[0] = True
|
| 1012 |
+
return output_text, data, new_status, \
|
| 1013 |
+
gr.update(elem_classes="completed-tab"), \
|
| 1014 |
+
gr.update(interactive=True), \
|
| 1015 |
+
gr.update(visible=False)
|
| 1016 |
+
return output_text, data, current_tab_status, \
|
| 1017 |
+
gr.update(), gr.update(), gr.update()
|
| 1018 |
+
|
| 1019 |
upload_btn.click(
|
| 1020 |
+
fn=process_transcript_and_update,
|
| 1021 |
+
inputs=[transcript_file, tab_completed],
|
| 1022 |
+
outputs=[transcript_output, transcript_data, tab_completed, step1, step2, nav_message]
|
| 1023 |
)
|
| 1024 |
|
| 1025 |
# ===== TAB 2: Learning Style Quiz =====
|
|
|
|
| 1061 |
outputs=progress
|
| 1062 |
)
|
| 1063 |
|
| 1064 |
+
def submit_quiz_and_update(*args):
|
| 1065 |
+
# The first argument is the tab_completed state, followed by answers
|
| 1066 |
+
current_tab_status = args[0]
|
| 1067 |
+
answers = args[1:]
|
| 1068 |
+
|
| 1069 |
+
result = learning_style_quiz.evaluate_quiz(*answers)
|
| 1070 |
+
|
| 1071 |
+
new_status = current_tab_status.copy()
|
| 1072 |
+
new_status[1] = True
|
| 1073 |
+
|
| 1074 |
+
return result, \
|
| 1075 |
+
gr.update(visible=True), \
|
| 1076 |
+
new_status, \
|
| 1077 |
+
gr.update(elem_classes="completed-tab"), \
|
| 1078 |
+
gr.update(interactive=True), \
|
| 1079 |
+
gr.update(value="<div class='alert-box'>Quiz submitted successfully! Scroll down to view your results.</div>", visible=True), \
|
| 1080 |
+
gr.update(visible=False)
|
| 1081 |
+
|
| 1082 |
quiz_submit.click(
|
| 1083 |
+
fn=submit_quiz_and_update,
|
| 1084 |
+
inputs=[tab_completed] + quiz_components,
|
| 1085 |
+
outputs=[learning_output, learning_output, tab_completed, step2, step3, quiz_alert, nav_message]
|
|
|
|
|
|
|
|
|
|
| 1086 |
)
|
| 1087 |
|
| 1088 |
# ===== TAB 3: Personal Questions =====
|
|
|
|
| 1129 |
inputs=blog_checkbox,
|
| 1130 |
outputs=blog_text
|
| 1131 |
)
|
| 1132 |
+
|
| 1133 |
+
# Check if required fields are filled to mark as complete
|
| 1134 |
+
def check_personal_info_complete(name, age, interests, current_tab_status):
|
| 1135 |
+
if name.strip() and age and interests.strip():
|
| 1136 |
+
new_status = current_tab_status.copy()
|
| 1137 |
+
new_status[2] = True
|
| 1138 |
+
return new_status, gr.update(elem_classes="completed-tab"), gr.update(interactive=True), gr.update(visible=False)
|
| 1139 |
+
return current_tab_status, gr.update(), gr.update(), gr.update()
|
| 1140 |
+
|
| 1141 |
+
# Monitor changes to required fields
|
| 1142 |
+
name.change(
|
| 1143 |
+
fn=check_personal_info_complete,
|
| 1144 |
+
inputs=[name, age, interests, tab_completed],
|
| 1145 |
+
outputs=[tab_completed, step3, step4, nav_message]
|
| 1146 |
+
)
|
| 1147 |
+
age.change(
|
| 1148 |
+
fn=check_personal_info_complete,
|
| 1149 |
+
inputs=[name, age, interests, tab_completed],
|
| 1150 |
+
outputs=[tab_completed, step3, step4, nav_message]
|
| 1151 |
+
)
|
| 1152 |
+
interests.change(
|
| 1153 |
+
fn=check_personal_info_complete,
|
| 1154 |
+
inputs=[name, age, interests, tab_completed],
|
| 1155 |
+
outputs=[tab_completed, step3, step4, nav_message]
|
| 1156 |
+
)
|
| 1157 |
|
| 1158 |
# ===== TAB 4: Save & Review =====
|
| 1159 |
with gr.Tab("Save Profile", id=3) as tab4:
|
|
|
|
| 1184 |
)
|
| 1185 |
|
| 1186 |
# Save profile
|
| 1187 |
+
def save_profile_and_update(*args):
|
| 1188 |
+
# Extract inputs
|
| 1189 |
+
inputs = args[:-1] # All except the last which is tab_completed
|
| 1190 |
+
current_tab_status = args[-1]
|
| 1191 |
+
|
| 1192 |
+
# Call the original save function
|
| 1193 |
+
summary = profile_manager.save_profile(*inputs)
|
| 1194 |
+
|
| 1195 |
+
# Update completion status
|
| 1196 |
+
new_status = current_tab_status.copy()
|
| 1197 |
+
new_status[3] = True
|
| 1198 |
+
|
| 1199 |
+
return summary, new_status, gr.update(elem_classes="completed-tab"), gr.update(interactive=True), gr.update(visible=False)
|
| 1200 |
+
|
| 1201 |
save_btn.click(
|
| 1202 |
+
fn=save_profile_and_update,
|
| 1203 |
inputs=[
|
| 1204 |
name, age, interests, transcript_data, learning_output,
|
| 1205 |
movie, movie_reason, show, show_reason,
|
| 1206 |
+
book, book_reason, character, character_reason, blog_text,
|
| 1207 |
+
tab_completed
|
| 1208 |
],
|
| 1209 |
+
outputs=[output_summary, tab_completed, step4, step5, nav_message]
|
| 1210 |
).then(
|
| 1211 |
fn=lambda: profile_manager.list_profiles(session_token.value),
|
| 1212 |
outputs=load_profile_dropdown
|
|
|
|
| 1264 |
book, book_reason, character, character_reason,
|
| 1265 |
blog_text
|
| 1266 |
]
|
| 1267 |
+
).then(
|
| 1268 |
+
fn=lambda: gr.update(value=""),
|
| 1269 |
+
outputs=output_summary
|
| 1270 |
+
).then(
|
| 1271 |
+
fn=lambda: gr.update(value=False),
|
| 1272 |
+
outputs=blog_checkbox
|
| 1273 |
+
).then(
|
| 1274 |
+
fn=lambda: gr.update(visible=False),
|
| 1275 |
+
outputs=blog_text
|
| 1276 |
)
|
| 1277 |
|
| 1278 |
# ===== TAB 5: AI Teaching Assistant =====
|
|
|
|
| 1293 |
title=""
|
| 1294 |
)
|
| 1295 |
|
| 1296 |
+
# Tab navigation logic with completion check
|
| 1297 |
+
def navigate_to_tab(tab_index: int, tab_completed_status):
|
| 1298 |
+
# Always allow going back to previous tabs
|
| 1299 |
+
current_tab = tabs.selected
|
| 1300 |
+
if current_tab is not None and tab_index > current_tab:
|
| 1301 |
+
# Check if current tab is completed
|
| 1302 |
+
if not tab_completed_status.get(current_tab, False):
|
| 1303 |
+
return gr.Tabs(selected=current_tab), \
|
| 1304 |
+
gr.update(value=f"<div class='nav-message'>Please complete the current tab before proceeding to tab {tab_index + 1}</div>", visible=True)
|
| 1305 |
+
|
| 1306 |
+
return gr.Tabs(selected=tab_index), gr.update(visible=False)
|
| 1307 |
|
| 1308 |
step1.click(
|
| 1309 |
+
fn=lambda idx, status: navigate_to_tab(idx, status),
|
| 1310 |
+
inputs=[gr.State(0), tab_completed],
|
| 1311 |
+
outputs=[tabs, nav_message]
|
| 1312 |
)
|
| 1313 |
step2.click(
|
| 1314 |
+
fn=lambda idx, status: navigate_to_tab(idx, status),
|
| 1315 |
+
inputs=[gr.State(1), tab_completed],
|
| 1316 |
+
outputs=[tabs, nav_message]
|
| 1317 |
)
|
| 1318 |
step3.click(
|
| 1319 |
+
fn=lambda idx, status: navigate_to_tab(idx, status),
|
| 1320 |
+
inputs=[gr.State(2), tab_completed],
|
| 1321 |
+
outputs=[tabs, nav_message]
|
| 1322 |
)
|
| 1323 |
step4.click(
|
| 1324 |
+
fn=lambda idx, status: navigate_to_tab(idx, status),
|
| 1325 |
+
inputs=[gr.State(3), tab_completed],
|
| 1326 |
+
outputs=[tabs, nav_message]
|
| 1327 |
)
|
| 1328 |
step5.click(
|
| 1329 |
+
fn=lambda idx, status: navigate_to_tab(idx, status),
|
| 1330 |
+
inputs=[gr.State(4), tab_completed],
|
| 1331 |
+
outputs=[tabs, nav_message]
|
| 1332 |
)
|
| 1333 |
|
| 1334 |
return app
|