Spaces:
Sleeping
Sleeping
github-actions[bot]
[Render] Cuong2004/Manim-Agent-Worker-Render @ 1d7c417 (run 25583057312)
a1fdb19 | from __future__ import annotations | |
| import re | |
| def extract_python_code(text: str) -> str: | |
| """Extract code from ```python ... ``` or return the original text if no blocks found.""" | |
| # Try to find a python code block | |
| match = re.search(r"```(?:python|py)?\s*\n?(.*?)\n?```", text, re.DOTALL | re.IGNORECASE) | |
| if match: | |
| return match.group(1).strip() | |
| # Try to find any code block | |
| match = re.search(r"```\s*\n?(.*?)\n?```", text, re.DOTALL) | |
| if match: | |
| return match.group(1).strip() | |
| return text.strip() | |