Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files736 unmodified lines7377387397407417423 unmodified lines7467477487497507517528 unmodified lines761762763764765766767768769770771772773736 unmodified linesdef _sanitize_code_tags(text: str) -> str:import recleaned_text = re.sub(r"</?code[^>]*>\s*```", "<code>\n", text, flags=re.IGNORECASE)cleaned_text = re.sub(r"```\s*</?code[^>]*>", "\n</code>", cleaned_text, flags=re.IGNORECASE)3 unmodified linesinner = re.sub(r"```(?:py|python)?\s*\n?", "", inner, flags=re.IGNORECASE)inner = re.sub(r"\n?```", "", inner)inner = re.sub(r"</?code[^>]*>", "", inner, flags=re.IGNORECASE)return f"<code>\n{inner.strip()}\n</code>"return re.sub(r"<code>(.*?)</code>",8 unmodified linesflags=re.DOTALL | re.IGNORECASE,)if md_match:inner = re.sub(r"</?code[^>]*>", "", md_match.group(1), flags=re.IGNORECASE).strip()prefix = cleaned_text[: md_match.start()].strip()return f"{prefix}\n<code>\n{inner}\n</code>" if prefix else f"<code>\n{inner}\n</code>"stripped_orphan_tags = re.sub(r"</?code[^>]*>", "", cleaned_text, flags=re.IGNORECASE).strip()if stripped_orphan_tags != cleaned_text.strip() and stripped_orphan_tags:return f"<code>\n{stripped_orphan_tags}\n</code>"return cleaned_text736 unmodified lines7377387397407417427437447457467477487497507517523 unmodified lines7567577587597607617628 unmodified lines771772773774775776777778779780781782783784736 unmodified linesdef _sanitize_code_tags(text: str) -> str:import redef _clean_python_code(code_str: str) -> str:lines = []for line in code_str.splitlines():stripped = line.lstrip()if re.match(r"^(?:thoughts?|thinking)\s*:", stripped, flags=re.IGNORECASE):lines.append("# " + stripped)else:lines.append(line)return "\n".join(lines).strip()cleaned_text = re.sub(r"</?code[^>]*>\s*```", "<code>\n", text, flags=re.IGNORECASE)cleaned_text = re.sub(r"```\s*</?code[^>]*>", "\n</code>", cleaned_text, flags=re.IGNORECASE)3 unmodified linesinner = re.sub(r"```(?:py|python)?\s*\n?", "", inner, flags=re.IGNORECASE)inner = re.sub(r"\n?```", "", inner)inner = re.sub(r"</?code[^>]*>", "", inner, flags=re.IGNORECASE)return f"<code>\n{_clean_python_code(inner)}\n</code>"return re.sub(r"<code>(.*?)</code>",8 unmodified linesflags=re.DOTALL | re.IGNORECASE,)if md_match:inner = re.sub(r"</?code[^>]*>", "", md_match.group(1), flags=re.IGNORECASE)prefix = cleaned_text[: md_match.start()].strip()body = f"<code>\n{_clean_python_code(inner)}\n</code>"return f"{prefix}\n{body}" if prefix else bodystripped_orphan_tags = re.sub(r"</?code[^>]*>", "", cleaned_text, flags=re.IGNORECASE).strip()if stripped_orphan_tags != cleaned_text.strip() and stripped_orphan_tags:return f"<code>\n{_clean_python_code(stripped_orphan_tags)}\n</code>"return cleaned_text
app.py+15-4