Spaces:
Sleeping
Sleeping
Simple on_submit with return only - test page transition
Browse files1562 unmodified lines15631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981562 unmodified linesreturn cs.sabotaged_code, gr.update(selected=1)def on_submit(trigger, hints_used, submit_count, workspace_path, hint_log, user_name):logger.info(f"=== SUBMIT CHALLENGE ===")logger.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 console"Starting submission evaluation...", # live debug)# Capture all print statements for debug consolelog_capture = StringIO()original_stdout = sys.stdouttry:sys.stdout = log_captureif 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...")cs = ChallengeState(workspace_path)log = SubmissionLog(cs.workspace)print(f"[{datetime.now().strftime('%H:%M:%S')}] ๐ Reading submitted code...")submitted_code = cs.read_target()print(f"[{datetime.now().strftime('%H:%M:%S')}] ๐งช Running tests...")result = evaluate_submission(workspace_path=workspace_path,student_code=submitted_code,original_code=cs.original_code,bug_func_name=cs.bug_func_name,hints_used=hints_used,sabotaged_code=cs.sabotaged_code,target_file=str(cs.target_path),bug_func_names=cs.bug_func_names,)print(f"[{datetime.now().strftime('%H:%M:%S')}] ๐พ Saving submission...")log.save(submitted_code, result, hints_used)new_count = submit_count + 1print(f"[{datetime.now().strftime('%H:%M:%S')}] ๐ Generating results...")score_html = _score_summary_html(result)combined_diff = _combined_changes_html(cs, submitted_code)test_html = _colorise_test_output(result["test_output"] or "No test output.")hints_html = _hints_html(hint_log or [])print(f"[{datetime.now().strftime('%H:%M:%S')}] โ Results ready, returning to user...")# Get all captured logsdebug_logs = log_capture.getvalue()sys.stdout = original_stdout # Restore stdout# 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,debug_logs, # live debug (same))# Upload to cloud services in BACKGROUND THREAD (non-blocking)# TEMPORARILY DISABLED - Testing without cloud uploads"""def _background_upload():student_name = user_name.strip() if user_name else "Anonymous"# Google Sheets (fast summary)if GOOGLE_SHEETS_AVAILABLE:try:print("๐ Uploading to Google Sheets...")log_to_google_sheets(student_name=student_name,repo_url=cs.github_url,hints_used=hints_used,score=result["total_score"],total_tests=result["total_tests"],passed_tests=result["passed"],all_passed=result["all_passed"],chat_history=hint_log or [],)print(f"โ Logged to Google Sheets: {student_name}")except Exception as e:print(f"โ ๏ธ Google Sheets logging failed: {e}")# Git Submissions (detailed backup with all code)if GIT_SUBMISSIONS_AVAILABLE:try:print("๐ Pushing to Git repository...")push_submission_to_git(student_name=student_name,repo_url=cs.github_url,original_code=cs.original_code,buggy_code=cs.sabotaged_code,student_code=submitted_code,chat_history=hint_log or [],score=result["total_score"],total_tests=result["total_tests"],passed_tests=result["passed"],hints_used=hints_used,challenge_prompt=cs.readme(),target_file=cs.target_file,)print(f"โ Pushed to Git: {student_name}")except Exception as e:print(f"โ ๏ธ Git submission backup failed: {e}")# Start background upload (won't block UI)upload_thread = threading.Thread(target=_background_upload, daemon=True)upload_thread.start()"""except Exception as exc:import tracebackerror_details = traceback.format_exc()debug_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 stdoutdef on_send(message, history, hints_used, submit_count, workspace_path, hint_log, confirmation_pending):if not message.strip():1562 unmodified lines15631564156515661567156815691570157115721573157415751576157715781579158015811582158315841562 unmodified linesreturn cs.sabotaged_code, gr.update(selected=1)def on_submit(trigger, hints_used, submit_count, workspace_path, hint_log, user_name):"""SIMPLIFIED VERSION: Just change page visibility - no logic yet"""logger.info(f"=== SUBMIT (SIMPLE TEST) ===")logger.info(f"User: {user_name}, Submit#: {submit_count}")# Simple return - just change page visibilityreturn (gr.update(visible=False), # Hide challenge_pagegr.update(visible=True), # Show results_page"<h1 style='text-align:center;color:green;'>โ ืขืืื ืืชืืฆืืืช!</h1><p>ืื ืืชื ืจืืื ืืช ืื, ืืืขืืจ ืขืืื.</p>","<p>Diff will be here...</p>","<p>Tests will be here...</p>","<p>Hints will be here...</p>",submit_count + 1,"Debug console","Live debug",)def on_send(message, history, hints_used, submit_count, workspace_path, hint_log, confirmation_pending):if not message.strip():
student_interface.py+14-128