Spaces:
Sleeping
Sleeping
Save selected file from code editor
Browse files91 unmodified lines92939495969753 unmodified lines15115215315415515640 unmodified lines19719819920020120220320420520620720820921021121221321421521621757 unmodified lines275276277278279280159 unmodified lines440441442443444445576 unmodified lines102210231024102510261027424 unmodified lines145214531454145514561457145814591460146114621463146414651 unmodified line14671468146914701471147214732 unmodified lines14761477147814791480148114821 unmodified line14841485148614871488148914906 unmodified lines149714981499150015011502150324 unmodified lines15281529153015311532153310 unmodified lines154415451546154715481549155015516 unmodified lines1558155915601561156215639 unmodified lines1573157415751576157715788 unmodified lines158715881589159015911592159315941595159612 unmodified lines160916101611161216131614161516161617161852 unmodified lines16711672167316741675167616771678167916801681168216831684168516861687168816891690154 unmodified lines18451846184718481849185018511852185318541855185618571858185911 unmodified lines187118721873187418751876187712 unmodified lines1890189118921893189418959 unmodified lines190519061907190819091910191119126 unmodified lines19191920192119221923192494 unmodified lines20192020202120222023202420252026202720282 unmodified lines203120322033203420352036203791 unmodified lines)self.bug_func_sources_list: list = data.get("bug_func_sources_list", [])self.original_bug_func_sources_list: list = data.get("original_bug_func_sources_list", [])self.nesting_level: int = data.get("nesting_level", 3)self.refactoring_enabled: bool = data.get("refactoring_enabled", False)self.debug_mode: bool = data.get("debug_mode", False)53 unmodified linesdef write_target(self, code: str) -> None:self.target_path.write_text(code, encoding="utf-8")def reset_target(self) -> None:self.write_target(self.sabotaged_code)40 unmodified linesself.log_dir = workspace / "submissions"self.log_dir.mkdir(exist_ok=True)def save(self, student_code: str, result: dict, hints_used: int) -> None:ts = datetime.now().strftime("%Y%m%d_%H%M%S_%f")entry = {"timestamp": ts,"hints_used": hints_used,"llm_score": result.get("llm_score", result.get("total_score", 0)),"llm_explanation": result.get("llm_explanation", ""),"hint_penalty": result["hint_penalty"],"total_score": result["total_score"],"passed": result["passed"],"total_tests": result["total_tests"],"all_passed": result["all_passed"],"student_code": student_code,}path = self.log_dir / f"{ts}.json"with open(path, "w", encoding="utf-8") as f:json.dump(entry, f, indent=2, ensure_ascii=False)57 unmodified lineschallenge_state = {"github_url": github_url,"workspace_path": workspace_path,"target_file": target_file_rel,"original_code": result.get("original_code", ""),"sabotaged_code": actual_sabotaged_code,159 unmodified linesreturn "\n".join(line.rstrip() for line in code.replace("\r\n", "\n").replace("\r", "\n").splitlines())def _workspace_diff_html(cs: "ChallengeState") -> str:"""Show a unified diff for the target file the student changed.576 unmodified lines"""# โโ Full two-page interface โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโdef create_full_interface() -> gr.Blocks:424 unmodified linescontent = cs.read_py_file(rel_path)return gr.update(value=content, interactive=True, label=rel_path)def on_save(code, workspace_path):if not workspace_path:return "โ ๏ธ No challenge loaded."cs = ChallengeState(workspace_path)cs.write_target(code)return "โ Saved"def on_run_tests(code, workspace_path):loading = '<p style="text-align:center;padding:20px;color:#888;">โณ Running testsโฆ</p>'yield (gr.update(selected=2), loading)if not workspace_path:1 unmodified linereturn# Auto-save before running testscs_temp = ChallengeState(workspace_path)cs_temp.write_target(code)try:from orchestrator.scoring import run_testsr = run_tests(workspace_path)2 unmodified linesexcept Exception as exc:yield (gr.update(selected=2), f"<p style='color:#ef4444;font-family:monospace;'>โ Error: {exc}</p>")def on_show_changes(code, workspace_path):if not workspace_path:diff = "<p style='color:#888'>No challenge loaded.</p>"else:1 unmodified line# Save code from editor, then read from disk for comparison# (Gradio code_editor doesn't always pass updated content reliably)cs = ChallengeState(workspace_path)cs.write_target(code)diff = _workspace_diff_html(cs)except Exception as e:diff = f"<p style='color:#ef4444;'>Error generating diff: {str(e)[:200]}</p>"6 unmodified linescs.reset_target()return 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}")24 unmodified linesprint(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()10 unmodified linesbug_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...")6 unmodified lines# Get all captured logsdebug_logs = log_capture.getvalue()sys.stdout = original_stdout # Restore stdout# Return results to user IMMEDIATELY9 unmodified lines# Upload to cloud services in BACKGROUND THREAD (non-blocking)def _background_upload():student_name = user_name.strip() if user_name else "Anonymous"# Google Sheets (fast summary)if GOOGLE_SHEETS_AVAILABLE:8 unmodified linespassed_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:12 unmodified lineshints_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)52 unmodified linesinputs=[file_dropdown, workspace_state],outputs=[code_editor],)save_btn.click(on_save, inputs=[code_editor, workspace_state], outputs=[save_status])btn_tests.click(on_run_tests, inputs=[code_editor, workspace_state], outputs=[left_tabs, test_output])run_tests_tab_btn.click(on_run_tests, inputs=[code_editor, workspace_state], outputs=[left_tabs, test_output])btn_changes.click(on_show_changes, inputs=[code_editor, workspace_state], outputs=[left_tabs, changes_diff_html])refresh_btn.click(on_show_changes, inputs=[code_editor, workspace_state], outputs=[left_tabs, changes_diff_html])revert_btn.click(on_revert, inputs=[workspace_state], outputs=[code_editor, left_tabs])submit_btn.click(on_submit,inputs=[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 page154 unmodified linescontent = cs.read_py_file(rel_path)return gr.update(value=content, interactive=True, label=rel_path)def on_save(code):cs.write_target(code)return "โ Saved"def on_run_tests(code):loading = '<p style="text-align:center;padding:20px;color:#888;">โณ Running testsโฆ</p>'yield (gr.update(selected=2), loading)# Auto-save before running testscs.write_target(code)try:from orchestrator.scoring import run_testsr = run_tests(workspace_path)11 unmodified linescs.reset_target()return cs.sabotaged_code, gr.update(selected=1)def on_submit(hints_used, submit_count, hint_log):# Capture all print statements for debug consolelog_capture = StringIO()original_stdout = sys.stdout12 unmodified linessys.stdout = log_capture # Capture againprint(f"[{datetime.now().strftime('%H:%M:%S')}] ๐ Starting submission evaluation (standalone mode)...")print(f"[{datetime.now().strftime('%H:%M:%S')}] ๐ Reading submitted code...")submitted_code = cs.read_target()9 unmodified linesbug_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...")6 unmodified lines# Get all captured logsdebug_logs = log_capture.getvalue()sys.stdout = original_stdout # Restore stdout# Return results to user IMMEDIATELY94 unmodified linesfile_dropdown.change(on_file_select, inputs=[file_dropdown], outputs=[code_editor])save_btn.click(on_save, inputs=[code_editor], outputs=[save_status])btn_tests.click(on_run_tests, inputs=[code_editor], outputs=[left_tabs, test_output])run_tests_tab_btn.click(on_run_tests, inputs=[code_editor], outputs=[left_tabs, test_output])btn_changes.click(on_show_changes, outputs=[left_tabs, changes_diff_html])refresh_btn.click(on_show_changes, outputs=[left_tabs, changes_diff_html])2 unmodified linessubmit_btn.click(on_submit,inputs=[hints_used_state, submission_count_state, hint_log_state],outputs=[challenge_col, results_col,score_summary_html,91 unmodified lines929394959697989910010153 unmodified lines15515615715815916016116216316416540 unmodified lines20620720820921021121221321421521621721821922022122222322457 unmodified lines282283284285286287288159 unmodified lines448449450451452453454455456457458459460461462463464465466467576 unmodified lines10441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168424 unmodified lines159315941595159615971598159916001601160216031604160516061607160816091 unmodified line16111612161316141615161616171618161916202 unmodified lines16231624162516261627162816291 unmodified line16311632163316341635163616371638163916406 unmodified lines164716481649165016511652165324 unmodified lines1678167916801681168216831684168510 unmodified lines1696169716981699170017016 unmodified lines17081709171017111712171317141715171617171718171917201721172217231724172517269 unmodified lines17361737173817391740174117428 unmodified lines17511752175317541755175617571758175917601761176217631764176512 unmodified lines1778177917801781178217831784178517861787178817891790179117921793179452 unmodified lines18471848184918501851185218531854185518561857185818591860186118621863186418651866154 unmodified lines20212022202320242025202620272028202920302031203220332034203520362037203820392040204111 unmodified lines205320542055205620572058205912 unmodified lines207220732074207520762077207820799 unmodified lines2089209020912092209320946 unmodified lines210121022103210421052106210721082109211021112112211321142115211621172118211994 unmodified lines22142215221622172218221922202221222222232 unmodified lines222622272228222922302231223291 unmodified lines)self.bug_func_sources_list: list = data.get("bug_func_sources_list", [])self.original_bug_func_sources_list: list = data.get("original_bug_func_sources_list", [])self.public_tests: list = data.get("public_tests", [])self.secret_tests: list = data.get("secret_tests", [])self.bug_description: str = data.get("bug_description", "")self.challenge_created_at: str = data.get("challenge_created_at", "")self.nesting_level: int = data.get("nesting_level", 3)self.refactoring_enabled: bool = data.get("refactoring_enabled", False)self.debug_mode: bool = data.get("debug_mode", False)53 unmodified linesdef write_target(self, code: str) -> None:self.target_path.write_text(code, encoding="utf-8")def write_py_file(self, rel_path: str, code: str) -> None:file_path = self.workspace / rel_pathfile_path.parent.mkdir(parents=True, exist_ok=True)file_path.write_text(code, encoding="utf-8")def reset_target(self) -> None:self.write_target(self.sabotaged_code)40 unmodified linesself.log_dir = workspace / "submissions"self.log_dir.mkdir(exist_ok=True)def save(self, entry: dict) -> Path:submission_id = entry.get("submission_id") or datetime.now().strftime("%Y%m%d_%H%M%S_%f")path = self.log_dir / f"{submission_id}.json"with open(path, "w", encoding="utf-8") as f:json.dump(entry, f, indent=2, ensure_ascii=False)return pathdef update(self, path: Path, updates: dict) -> None:if not path.exists():returnwith open(path, encoding="utf-8") as f:entry = json.load(f)_deep_merge_dict(entry, updates)with open(path, "w", encoding="utf-8") as f:json.dump(entry, f, indent=2, ensure_ascii=False)57 unmodified lineschallenge_state = {"github_url": github_url,"workspace_path": workspace_path,"challenge_created_at": datetime.now().isoformat(),"target_file": target_file_rel,"original_code": result.get("original_code", ""),"sabotaged_code": actual_sabotaged_code,159 unmodified linesreturn "\n".join(line.rstrip() for line in code.replace("\r\n", "\n").replace("\r", "\n").splitlines())def _plain_diff_text(a: str, b: str, from_label: str, to_label: str) -> str:a_lines = _normalize(a).splitlines(keepends=True)b_lines = _normalize(b).splitlines(keepends=True)return "".join(difflib.unified_diff(a_lines, b_lines, fromfile=from_label, tofile=to_label, lineterm=""))def _deep_merge_dict(target: dict, updates: dict) -> None:for key, value in updates.items():if isinstance(value, dict) and isinstance(target.get(key), dict):_deep_merge_dict(target[key], value)else:target[key] = valuedef _workspace_diff_html(cs: "ChallengeState") -> str:"""Show a unified diff for the target file the student changed.576 unmodified lines"""def _submission_outcome(result: dict) -> str:if not result.get("touched_bug_function", True):return "wrong_location" if result.get("changed_function_names") else "no_attempt"if result.get("all_passed"):return "full_fix"before_passed = result.get("before_passed", 0)after_passed = result.get("passed", 0)if after_passed > before_passed:return "partial_fix"if after_passed < before_passed:return "regression"return "attempted_no_improvement"def _build_submission_record(cs: "ChallengeState",student_name: str,submitted_code: str,result: dict,hints_used: int,hint_log: list,attempt_number: int,debug_logs: str,enable_cloud_uploads: bool,) -> dict:timestamp = datetime.now()submission_id = timestamp.strftime("%Y%m%d_%H%M%S_%f")expected_fixed_code = _compute_expected_fixed_code(cs) or cs.original_codechallenge_id = f"{cs.workspace.name}:{cs.target_file}:{cs.function_name or 'unknown'}"student_name = (student_name or "Anonymous").strip() or "Anonymous"outcome = _submission_outcome(result)google_status = "pending" if enable_cloud_uploads and GOOGLE_SHEETS_AVAILABLE else "disabled"git_status = "pending" if enable_cloud_uploads and GIT_SUBMISSIONS_AVAILABLE else "disabled"return {"submission_id": submission_id,"timestamp": timestamp.isoformat(),"student": {"name": student_name,"email": "",},"challenge": {"challenge_id": challenge_id,"created_at": cs.challenge_created_at,"workspace_name": cs.workspace.name,"workspace_path": str(cs.workspace),"repo_url": cs.github_url,"target_file": cs.target_file,"function_name": cs.function_name,"bug_func_name": cs.bug_func_name,"bug_func_names": cs.bug_func_names,"bug_description": cs.bug_description,"difficulty_level": cs.nesting_level,"refactoring_enabled": cs.refactoring_enabled,"debug_mode": cs.debug_mode,"challenge_prompt": cs.readme(),"original_code": cs.original_code,"buggy_code": cs.sabotaged_code,"expected_fixed_code": expected_fixed_code,"public_tests": cs.public_tests,"secret_tests": cs.secret_tests,},"submission": {"attempt_number": attempt_number,"hints_used": hints_used,"chat_history": hint_log or [],"student_code": submitted_code,"student_diff": _plain_diff_text(cs.sabotaged_code,submitted_code,f"received/{cs.target_file}",f"student/{cs.target_file}",),"changed_function_names": result.get("changed_function_names", []),"changed_functions": result.get("changed_functions", []),"bug_function_names": result.get("bug_function_names", []),"touched_bug_function": result.get("touched_bug_function", False),},"tests": {"before_passed": result.get("before_passed", 0),"before_total": result.get("before_total", 0),"public_passed": result.get("public_passed", 0),"public_total": result.get("public_total", 0),"secret_passed": result.get("secret_passed", 0),"secret_total": result.get("secret_total", 0),"passed_tests": result.get("passed", 0),"total_tests": result.get("total_tests", 0),"all_passed": result.get("all_passed", False),"per_test_before": result.get("per_test_before", []),"per_test_after": result.get("per_test_after", []),"public_output": result.get("public_output", ""),"secret_output": result.get("secret_output", ""),"test_output": result.get("test_output", ""),},"scoring": {"llm_score": result.get("llm_score", result.get("total_score", 0)),"llm_explanation": result.get("llm_explanation", ""),"hint_penalty": result.get("hint_penalty", 0),"total_score": result.get("total_score", 0),"test_score": result.get("test_score", 0),"correct_location": result.get("correct_location", False),"submission_outcome": outcome,},"system": {"llm_provider": os.getenv("LLM_PROVIDER", ""),"llm_model": os.getenv("LLM_MODEL", ""),"agent_model": os.getenv("AGENT_MODEL", ""),},"cloud": {"google_sheets": {"status": google_status, "error": ""},"git_backup": {"status": git_status, "error": ""},},"debug": {"captured_logs": debug_logs,},}# โโ Full two-page interface โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโdef create_full_interface() -> gr.Blocks:424 unmodified linescontent = cs.read_py_file(rel_path)return gr.update(value=content, interactive=True, label=rel_path)def on_save(code, rel_path, workspace_path):if not workspace_path:return "โ ๏ธ No challenge loaded."cs = ChallengeState(workspace_path)if rel_path:cs.write_py_file(rel_path, code)else:cs.write_target(code)return "โ Saved"def on_run_tests(code, rel_path, workspace_path):loading = '<p style="text-align:center;padding:20px;color:#888;">โณ Running testsโฆ</p>'yield (gr.update(selected=2), loading)if not workspace_path:1 unmodified linereturn# Auto-save before running testscs_temp = ChallengeState(workspace_path)if rel_path:cs_temp.write_py_file(rel_path, code)else:cs_temp.write_target(code)try:from orchestrator.scoring import run_testsr = run_tests(workspace_path)2 unmodified linesexcept Exception as exc:yield (gr.update(selected=2), f"<p style='color:#ef4444;font-family:monospace;'>โ Error: {exc}</p>")def on_show_changes(code, rel_path, workspace_path):if not workspace_path:diff = "<p style='color:#888'>No challenge loaded.</p>"else:1 unmodified line# Save code from editor, then read from disk for comparison# (Gradio code_editor doesn't always pass updated content reliably)cs = ChallengeState(workspace_path)if rel_path:cs.write_py_file(rel_path, code)else:cs.write_target(code)diff = _workspace_diff_html(cs)except Exception as e:diff = f"<p style='color:#ef4444;'>Error generating diff: {str(e)[:200]}</p>"6 unmodified linescs.reset_target()return cs.sabotaged_code, gr.update(selected=1)def on_submit(trigger, hints_used, submit_count, workspace_path, hint_log, user_name, code, rel_path):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}")24 unmodified linesprint(f"[{datetime.now().strftime('%H:%M:%S')}] ๐ Starting submission evaluation...")cs = ChallengeState(workspace_path)log = SubmissionLog(cs.workspace)if rel_path:cs.write_py_file(rel_path, code)print(f"[{datetime.now().strftime('%H:%M:%S')}] ๐ Reading submitted code...")submitted_code = cs.read_target()10 unmodified linesbug_func_names=cs.bug_func_names,)new_count = submit_count + 1print(f"[{datetime.now().strftime('%H:%M:%S')}] ๐ Generating results...")6 unmodified lines# Get all captured logsdebug_logs = log_capture.getvalue()print(f"[{datetime.now().strftime('%H:%M:%S')}] ๐พ Saving submission...")submission_record = _build_submission_record(cs=cs,student_name=user_name,submitted_code=submitted_code,result=result,hints_used=hints_used,hint_log=hint_log or [],attempt_number=new_count,debug_logs=debug_logs,enable_cloud_uploads=True,)log_path = log.save(submission_record)sys.stdout = original_stdout # Restore stdout# Return results to user IMMEDIATELY9 unmodified lines# Upload to cloud services in BACKGROUND THREAD (non-blocking)def _background_upload():student_name = user_name.strip() if user_name else "Anonymous"cloud_updates = {}# Google Sheets (fast summary)if GOOGLE_SHEETS_AVAILABLE:8 unmodified linespassed_tests=result["passed"],all_passed=result["all_passed"],chat_history=hint_log or [],submission_record=submission_record,)print(f"โ Logged to Google Sheets: {student_name}")cloud_updates["google_sheets"] = {"status": "success", "error": ""}except Exception as e:print(f"โ ๏ธ Google Sheets logging failed: {e}")cloud_updates["google_sheets"] = {"status": "failed", "error": str(e)}else:cloud_updates["google_sheets"] = {"status": "disabled", "error": ""}# Git Submissions (detailed backup with all code)if GIT_SUBMISSIONS_AVAILABLE:12 unmodified lineshints_used=hints_used,challenge_prompt=cs.readme(),target_file=cs.target_file,submission_record=submission_record,)print(f"โ Pushed to Git: {student_name}")cloud_updates["git_backup"] = {"status": "success", "error": ""}except Exception as e:print(f"โ ๏ธ Git submission backup failed: {e}")cloud_updates["git_backup"] = {"status": "failed", "error": str(e)}else:cloud_updates["git_backup"] = {"status": "disabled", "error": ""}log.update(log_path, {"cloud": cloud_updates})# Start background upload (won't block UI)upload_thread = threading.Thread(target=_background_upload, daemon=True)52 unmodified linesinputs=[file_dropdown, workspace_state],outputs=[code_editor],)save_btn.click(on_save, inputs=[code_editor, file_dropdown, workspace_state], outputs=[save_status])btn_tests.click(on_run_tests, inputs=[code_editor, file_dropdown, workspace_state], outputs=[left_tabs, test_output])run_tests_tab_btn.click(on_run_tests, inputs=[code_editor, file_dropdown, workspace_state], outputs=[left_tabs, test_output])btn_changes.click(on_show_changes, inputs=[code_editor, file_dropdown, workspace_state], outputs=[left_tabs, changes_diff_html])refresh_btn.click(on_show_changes, inputs=[code_editor, file_dropdown, workspace_state], outputs=[left_tabs, changes_diff_html])revert_btn.click(on_revert, inputs=[workspace_state], outputs=[code_editor, left_tabs])submit_btn.click(on_submit,inputs=[submit_trigger, hints_used_state, submission_count_state,workspace_state, hint_log_state, user_name_state, code_editor, file_dropdown],outputs=[challenge_page, # Hide challenge pageresults_page, # Show results page154 unmodified linescontent = cs.read_py_file(rel_path)return gr.update(value=content, interactive=True, label=rel_path)def on_save(code, rel_path):if rel_path:cs.write_py_file(rel_path, code)else:cs.write_target(code)return "โ Saved"def on_run_tests(code, rel_path):loading = '<p style="text-align:center;padding:20px;color:#888;">โณ Running testsโฆ</p>'yield (gr.update(selected=2), loading)# Auto-save before running testsif rel_path:cs.write_py_file(rel_path, code)else:cs.write_target(code)try:from orchestrator.scoring import run_testsr = run_tests(workspace_path)11 unmodified linescs.reset_target()return cs.sabotaged_code, gr.update(selected=1)def on_submit(hints_used, submit_count, hint_log, code, rel_path):# Capture all print statements for debug consolelog_capture = StringIO()original_stdout = sys.stdout12 unmodified linessys.stdout = log_capture # Capture againprint(f"[{datetime.now().strftime('%H:%M:%S')}] ๐ Starting submission evaluation (standalone mode)...")if rel_path:cs.write_py_file(rel_path, code)print(f"[{datetime.now().strftime('%H:%M:%S')}] ๐ Reading submitted code...")submitted_code = cs.read_target()9 unmodified linesbug_func_names=cs.bug_func_names,)new_count = submit_count + 1print(f"[{datetime.now().strftime('%H:%M:%S')}] ๐ Generating results...")6 unmodified lines# Get all captured logsdebug_logs = log_capture.getvalue()print(f"[{datetime.now().strftime('%H:%M:%S')}] ๐พ Saving submission...")submission_record = _build_submission_record(cs=cs,student_name="Anonymous (standalone mode)",submitted_code=submitted_code,result=result,hints_used=hints_used,hint_log=hint_log or [],attempt_number=new_count,debug_logs=debug_logs,enable_cloud_uploads=False,)log.save(submission_record)sys.stdout = original_stdout # Restore stdout# Return results to user IMMEDIATELY94 unmodified linesfile_dropdown.change(on_file_select, inputs=[file_dropdown], outputs=[code_editor])save_btn.click(on_save, inputs=[code_editor, file_dropdown], outputs=[save_status])btn_tests.click(on_run_tests, inputs=[code_editor, file_dropdown], outputs=[left_tabs, test_output])run_tests_tab_btn.click(on_run_tests, inputs=[code_editor, file_dropdown], outputs=[left_tabs, test_output])btn_changes.click(on_show_changes, outputs=[left_tabs, changes_diff_html])refresh_btn.click(on_show_changes, outputs=[left_tabs, changes_diff_html])2 unmodified linessubmit_btn.click(on_submit,inputs=[hints_used_state, submission_count_state, hint_log_state, code_editor, file_dropdown],outputs=[challenge_col, results_col,score_summary_html,
student_interface.py+236-41