Spaces:
Sleeping
Sleeping
Kai Izumoto
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
# InfinateCodeGenerator - Ultimate Merged Edition (v1.0.1) -
|
| 2 |
"""
|
| 3 |
Consolidated, hardened, and production-ready version (patched call_model & retries).
|
| 4 |
"""
|
|
@@ -664,8 +664,48 @@ Return the perfected code in META format."""
|
|
| 664 |
if response_retry and "<<ERROR" not in response_retry:
|
| 665 |
response = response_retry
|
| 666 |
else:
|
| 667 |
-
#
|
| 668 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 669 |
|
| 670 |
meta = parse_meta(response)
|
| 671 |
if not meta or not meta.get("files"):
|
|
|
|
| 1 |
+
# InfinateCodeGenerator - Ultimate Merged Edition (v1.0.1) - full script
|
| 2 |
"""
|
| 3 |
Consolidated, hardened, and production-ready version (patched call_model & retries).
|
| 4 |
"""
|
|
|
|
| 664 |
if response_retry and "<<ERROR" not in response_retry:
|
| 665 |
response = response_retry
|
| 666 |
else:
|
| 667 |
+
# Still failed — produce a safe fallback scaffold so iteration does not fail
|
| 668 |
+
logging.warning(f"Conservative retry failed for iteration {iteration}; producing fallback scaffold.")
|
| 669 |
+
fallback_main = self.current_files.get("main.py", "# New project\n\ndef main():\n print('Hello, World!')\n\nif __name__ == '__main__':\n main()")
|
| 670 |
+
fallback_main += "\n\n# NOTE: Model failed to generate new code for this iteration. Fallback scaffold inserted."
|
| 671 |
+
|
| 672 |
+
fallback_test = (
|
| 673 |
+
"import pytest\n\n"
|
| 674 |
+
"def test_placeholder():\n"
|
| 675 |
+
" \"\"\"Placeholder test created because model failed to produce output.\"\"\"\n"
|
| 676 |
+
" assert True\n"
|
| 677 |
+
)
|
| 678 |
+
|
| 679 |
+
fallback_requirements = self.current_files.get("requirements.txt", "# Add your requirements here")
|
| 680 |
+
|
| 681 |
+
files = {
|
| 682 |
+
"main.py": fallback_main,
|
| 683 |
+
"tests/test_main.py": fallback_test,
|
| 684 |
+
"requirements.txt": fallback_requirements
|
| 685 |
+
}
|
| 686 |
+
|
| 687 |
+
# Write files and run evaluators so the pipeline can continue
|
| 688 |
+
write_files(workdir, files)
|
| 689 |
+
eval_results = run_evaluators(workdir)
|
| 690 |
+
eval_results["fallback_used"] = True
|
| 691 |
+
eval_results["fallback_info"] = f"Model failed; fallback scaffold used for iteration {iteration}."
|
| 692 |
+
|
| 693 |
+
review = f"Fallback scaffold inserted because model failed to return usable output. See /tmp/failed_response_{iteration}.txt for raw model response."
|
| 694 |
+
readme = f"# Fallback Project\n\nThis scaffold was inserted automatically because model generation failed on iteration {iteration}."
|
| 695 |
+
|
| 696 |
+
files["README.md"] = readme
|
| 697 |
+
write_files(workdir, {"README.md": readme})
|
| 698 |
+
zip_path = make_zip(workdir)
|
| 699 |
+
|
| 700 |
+
return {
|
| 701 |
+
"success": True,
|
| 702 |
+
"eval": eval_results,
|
| 703 |
+
"zip": zip_path,
|
| 704 |
+
"workdir": str(workdir),
|
| 705 |
+
"files": files,
|
| 706 |
+
"review": review,
|
| 707 |
+
"readme": readme
|
| 708 |
+
}
|
| 709 |
|
| 710 |
meta = parse_meta(response)
|
| 711 |
if not meta or not meta.get("files"):
|