Spaces:
Sleeping
Sleeping
Restore Results as separate page with Accordions (fixes production bug)
Browse files1277 unmodified lines127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130812811282128311 unmodified lines129512961297132613271298132812991300130110 unmodified lines131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134535 unmodified lines138113821383138413851386138713881390139113921393139413891390139195 unmodified lines1487148814891496149014911492149373 unmodified lines15671568156915761570157115721579157315741575157615779 unmodified lines1587158815891595159015911592159333 unmodified lines16271628162916351630163116321633163456 unmodified lines1691169216931698169416951696169755 unmodified lines1753175417551760175617571758175917604 unmodified lines17651766176717711772177317741775177617771768176917701277 unmodified lines refresh_btn = gr.Button("π Refresh", variant="secondary") revert_btn = gr.Button("β©οΈ Revert to Original", variant="secondary") changes_diff_html = gr.HTML("") # ββ Results Tab (shown after Submit) ββββββββββββββββββ with gr.Tab("π Results", id=4): score_summary_html = gr.HTML("")
# Use Accordions instead of Tabs (more stable for dynamic updates) with gr.Accordion("π§ͺ Test Results", open=True): results_test_html = gr.HTML("")
with gr.Accordion("π Changes & Expected", open=False): results_changes_html = gr.HTML("")
with gr.Accordion("π‘ Hints Used", open=False): results_hints_html = gr.HTML("") # Debug console (collapsible) with gr.Accordion("π Debug Console", open=False): debug_console = gr.Textbox( label="Execution Logs", lines=15, max_lines=30, interactive=False, placeholder="Debug logs will appear here...", ) # ββ Simple Test Tab (for debugging navigation) ββββββββ with gr.Tab("π§ͺ Test Page", id=5): gr.Markdown("# π§ͺ Test Page\n\nThis tab was used for debugging. Results now use Accordions instead of nested Tabs!")
# ββ Right column: AI assistant + submit βββββββββββββββββββ with gr.Column(scale=2, elem_classes=["right-col"]):11 unmodified lines send_btn = gr.Button("Send", variant="secondary", scale=1)
gr.Markdown("---") with gr.Row(): submit_btn = gr.Button("π Submit Fix", variant="primary", scale=3) submit_btn = gr.Button("π Submit Fix", variant="primary") test_results_btn = gr.Button("π§ͺ Test Page", variant="secondary", scale=2) # Live Debug Console (always visible at bottom) gr.Markdown("---")10 unmodified lines # Hidden trigger for submit (ensures at least 1 UI input) submit_trigger = gr.Number(value=0, visible=False)
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ # PAGE 3 β Results (hidden until Submit clicked) # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ with gr.Column(visible=False) as results_page: gr.Markdown("## π Submission Results")
score_summary_html = gr.HTML("")
# Use Accordions instead of nested Tabs (more stable for dynamic updates) with gr.Accordion("π§ͺ Test Results", open=True): results_test_html = gr.HTML("")
with gr.Accordion("π Changes & Expected", open=False): results_changes_html = gr.HTML("")
with gr.Accordion("οΏ½ Hints Used", open=False): results_hints_html = gr.HTML("") # Debug console (collapsible) with gr.Accordion("π Debug Console", open=False): debug_console = gr.Textbox( label="Execution Logs", lines=15, max_lines=30, interactive=False, placeholder="Debug logs will appear here...", )
# ββ Login callback ββββββββββββββββββββββββββββββββββββββββββββββββ def on_login(name, api_key):35 unmodified lines gr.update(visible=True), # show login gr.update(visible=False), # hide setup gr.update(visible=False), # hide challenge gr.update(visible=False), # hide results gr.update(visible=False), # hide logout "", "", "", "", # clear textboxes "", "" # clear states ) def test_results_navigation(): """Test function - no longer needed but keeping for debugging.""" logger.info("π§ͺ Test button clicked") return gr.update(selected=5) # Switch to Test Page tab
# ββ Setup callback βββββββββββββββββββββββββββββββββββββββββββββββββ
95 unmodified lines logout_btn.click( on_logout, outputs=[ login_page, setup_page, challenge_page, logout_btn, login_page, setup_page, challenge_page, results_page, logout_btn, login_name, login_api_key, name_box, url_box, user_api_key_state, user_name_state ]73 unmodified lines logger.info(f"Trigger: {trigger}, User: {user_name}, Hints: {hints_used}, Submit#: {submit_count}") logger.info(f"Workspace: {workspace_path}") # First yield IMMEDIATELY: Show loading in Results tab # First yield IMMEDIATELY: Hide challenge, show results with loading _loading = '<p style="text-align:center;padding:40px;color:#888;font-size:1.2em;">β³ Running testsβ¦</p>' yield ( gr.update(selected=4), # Switch to Results tab gr.update(visible=False), # Hide challenge page gr.update(visible=True), # Show results page _loading, "", "", "", # Show loading message in results area submit_count, "", # debug console9 unmodified lines if not workspace_path: sys.stdout = original_stdout yield (gr.update(selected=4), "No challenge loaded.", "", "", "", submit_count, log_capture.getvalue(), "β No workspace loaded") yield (gr.update(visible=False), gr.update(visible=True), "No challenge loaded.", "", "", "", submit_count, log_capture.getvalue(), "β No workspace loaded") return print(f"[{datetime.now().strftime('%H:%M:%S')}] π Starting submission evaluation...")33 unmodified lines # Return results to user IMMEDIATELY yield ( gr.update(selected=4), # Stay on Results tab gr.update(visible=False), # Hide challenge page gr.update(visible=True), # Show results page score_html, combined_diff, test_html, hints_html, new_count, debug_logs,56 unmodified lines debug_logs = log_capture.getvalue() + f"\n\nβ ERROR:\n{error_details}" sys.stdout = original_stdout # Restore stdout err = f"<p style='color:#ef4444;padding:20px;font-family:monospace;'>β Error during evaluation:<br>{exc}</p>" yield (gr.update(selected=4), err, "", "", "", submit_count, debug_logs, debug_logs) yield (gr.update(visible=False), gr.update(visible=True), err, "", "", "", submit_count, debug_logs, debug_logs) finally: sys.stdout = original_stdout # Always restore stdout
55 unmodified lines inputs=[submit_trigger, hints_used_state, submission_count_state, workspace_state, hint_log_state, user_name_state], outputs=[ left_tabs, # Switch to Results tab challenge_page, # Hide challenge page results_page, # Show results page score_summary_html, results_changes_html, results_test_html,4 unmodified lines ], ) # Test button to navigate to simple Test Page tab test_results_btn.click( test_results_navigation, inputs=[], outputs=[left_tabs], ) send_btn.click( on_send, inputs=[chat_input, chatbot, hints_used_state, submission_count_state, workspace_state, hint_log_state, confirmation_pending_state],student_interface.py+40-50