Spaces:
Sleeping
Sleeping
Restore Results as separate page with Accordions (fixes production bug)
Browse files1277 unmodified lines127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131111 unmodified lines13231324132513261327132813291330133110 unmodified lines13421343134413451346134735 unmodified lines13831384138513861387138813891390139113921393139413951396139795 unmodified lines149314941495149614971498149973 unmodified lines15731574157515761577157815791580158115829 unmodified lines159215931594159515961597159833 unmodified lines163216331634163516361637163856 unmodified lines169516961697169816991700170155 unmodified lines17571758175917601761176217634 unmodified lines17681769177017711772177317741775177617771778177917801277 unmodified linesrefresh_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 linessend_btn = gr.Button("Send", variant="secondary", scale=1)gr.Markdown("---")with gr.Row():submit_btn = gr.Button("π Submit Fix", variant="primary", scale=3)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)# ββ Login callback ββββββββββββββββββββββββββββββββββββββββββββββββdef on_login(name, api_key):35 unmodified linesgr.update(visible=True), # show logingr.update(visible=False), # hide setupgr.update(visible=False), # hide challengegr.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 lineslogout_btn.click(on_logout,outputs=[login_page, setup_page, challenge_page, logout_btn,login_name, login_api_key, name_box, url_box,user_api_key_state, user_name_state]73 unmodified lineslogger.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_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_loading, "", "", "", # Show loading message in results areasubmit_count,"", # debug console9 unmodified linesif not workspace_path:sys.stdout = original_stdoutyield (gr.update(selected=4), "No challenge loaded.", "", "", "", submit_count, log_capture.getvalue(), "β No workspace loaded")returnprint(f"[{datetime.now().strftime('%H:%M:%S')}] π Starting submission evaluation...")33 unmodified lines# Return results to user IMMEDIATELYyield (gr.update(selected=4), # Stay on Results tabscore_html, combined_diff, test_html, hints_html,new_count,debug_logs,56 unmodified linesdebug_logs = log_capture.getvalue() + f"\n\nβ ERROR:\n{error_details}"sys.stdout = original_stdout # Restore stdouterr = 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)finally:sys.stdout = original_stdout # Always restore stdout55 unmodified linesinputs=[submit_trigger, hints_used_state, submission_count_state,workspace_state, hint_log_state, user_name_state],outputs=[left_tabs, # Switch to Results tabscore_summary_html,results_changes_html,results_test_html,4 unmodified lines],)# Test button to navigate to simple Test Page tabtest_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],1277 unmodified lines12781279128012811282128311 unmodified lines129512961297129812991300130110 unmodified lines131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134535 unmodified lines1381138213831384138513861387138813891390139195 unmodified lines148714881489149014911492149373 unmodified lines156715681569157015711572157315741575157615779 unmodified lines158715881589159015911592159333 unmodified lines1627162816291630163116321633163456 unmodified lines169116921693169416951696169755 unmodified lines175317541755175617571758175917604 unmodified lines1765176617671768176917701277 unmodified linesrefresh_btn = gr.Button("π Refresh", variant="secondary")revert_btn = gr.Button("β©οΈ Revert to Original", variant="secondary")changes_diff_html = gr.HTML("")# ββ Right column: AI assistant + submit βββββββββββββββββββwith gr.Column(scale=2, elem_classes=["right-col"]):11 unmodified linessend_btn = gr.Button("Send", variant="secondary", scale=1)gr.Markdown("---")submit_btn = gr.Button("π Submit Fix", variant="primary")# 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 linesgr.update(visible=True), # show logingr.update(visible=False), # hide setupgr.update(visible=False), # hide challengegr.update(visible=False), # hide resultsgr.update(visible=False), # hide logout"", "", "", "", # clear textboxes"", "" # clear states)# ββ Setup callback βββββββββββββββββββββββββββββββββββββββββββββββββ95 unmodified lineslogout_btn.click(on_logout,outputs=[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 lineslogger.info(f"Trigger: {trigger}, User: {user_name}, Hints: {hints_used}, Submit#: {submit_count}")logger.info(f"Workspace: {workspace_path}")# 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(visible=False), # Hide challenge pagegr.update(visible=True), # Show results page_loading, "", "", "", # Show loading message in results areasubmit_count,"", # debug console9 unmodified linesif not workspace_path:sys.stdout = original_stdoutyield (gr.update(visible=False), gr.update(visible=True), "No challenge loaded.", "", "", "", submit_count, log_capture.getvalue(), "β No workspace loaded")returnprint(f"[{datetime.now().strftime('%H:%M:%S')}] π Starting submission evaluation...")33 unmodified lines# Return results to user IMMEDIATELYyield (gr.update(visible=False), # Hide challenge pagegr.update(visible=True), # Show results pagescore_html, combined_diff, test_html, hints_html,new_count,debug_logs,56 unmodified linesdebug_logs = log_capture.getvalue() + f"\n\nβ ERROR:\n{error_details}"sys.stdout = original_stdout # Restore stdouterr = f"<p style='color:#ef4444;padding:20px;font-family:monospace;'>β Error during evaluation:<br>{exc}</p>"yield (gr.update(visible=False), gr.update(visible=True), err, "", "", "", submit_count, debug_logs, debug_logs)finally:sys.stdout = original_stdout # Always restore stdout55 unmodified linesinputs=[submit_trigger, hints_used_state, submission_count_state,workspace_state, hint_log_state, user_name_state],outputs=[challenge_page, # Hide challenge pageresults_page, # Show results pagescore_summary_html,results_changes_html,results_test_html,4 unmodified lines],)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