Spaces:
Sleeping
Sleeping
Convert Results page to tab within Challenge
Browse files1277 unmodified lines12781279128012811282128328 unmodified lines131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134535 unmodified lines138113821383138413851386138799 unmodified lines148714881489149014911492149373 unmodified lines156715681569157015711572157315741575157615779 unmodified lines158715881589159015911592159333 unmodified lines162716281629163016311632163356 unmodified lines169016911692169316941695169655 unmodified lines17521753175417551756175717581277 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"]):28 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("")with gr.Tabs():with gr.Tab("π§ͺ Test Results"):results_test_html = gr.HTML("")with gr.Tab("π Changes & Expected"):results_changes_html = gr.HTML("")with gr.Tab("π‘ Hints Used"):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 states99 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 (like on_start): Show loading WITHOUT changing visibility_loading = '<p style="text-align:center;padding:40px;color:#888;font-size:1.2em;">β³ Running testsβ¦</p>'yield (gr.update(), # challenge_page - no change yetgr.update(), # results_page - no change yet_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), gr.update(visible=True),score_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, results_page,score_summary_html,results_changes_html,results_test_html,1277 unmodified lines12781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130728 unmodified lines13361337133813391340134135 unmodified lines13771378137913801381138299 unmodified lines148214831484148514861487148873 unmodified lines15621563156415651566156715681569157015719 unmodified lines158115821583158415851586158733 unmodified lines162116221623162416251626162756 unmodified lines168416851686168716881689169055 unmodified lines17461747174817491750175117521277 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("")with gr.Tabs():with gr.Tab("π§ͺ Test Results"):results_test_html = gr.HTML("")with gr.Tab("π Changes & Expected"):results_changes_html = gr.HTML("")with gr.Tab("π‘ Hints Used"):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...",)# ββ Right column: AI assistant + submit βββββββββββββββββββwith gr.Column(scale=2, elem_classes=["right-col"]):28 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 states99 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.Tabs(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.Tabs(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.Tabs(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.Tabs(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,
student_interface.py+31-37