Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files732 unmodified lines7337347357367377388 unmodified lines7477487497507517527537547557567577587597607617627637647657667677687692 unmodified lines772773774775776777778779780732 unmodified linessuper().__init__(*args, **kwargs)self._explicit_api_key = kwargs.get("api_key")@staticmethoddef _sanitize_code_tags(text: str) -> str:import re8 unmodified lineslines.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)if re.search(r"<code>.*?</code>", cleaned_text, flags=re.DOTALL | re.IGNORECASE):def _clean_html_block(match):inner = match.group(1)inner = 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>",_clean_html_block,cleaned_text,flags=re.DOTALL | re.IGNORECASE,)md_match = re.search(r"```(?:py|python)?\s*\n(.*?)```",2 unmodified lines)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:732 unmodified lines7337347357367377387398 unmodified lines7487497507517527537547557567577587597607617627637642 unmodified lines767768769770771772773732 unmodified linessuper().__init__(*args, **kwargs)self._explicit_api_key = kwargs.get("api_key")@staticmethod@staticmethoddef _sanitize_code_tags(text: str) -> str:import re8 unmodified lineslines.append(line)return "\n".join(lines).strip()cleaned_text = re.sub(r"<\|[^|]+\|>", "", text)cleaned_text = re.sub(r"</?code[^>]*>\s*```", "<code>\n", cleaned_text, flags=re.IGNORECASE)cleaned_text = re.sub(r"```\s*</?code[^>]*>", "\n</code>", cleaned_text, flags=re.IGNORECASE)html_match = re.search(r"<code>(.*?)</code>", cleaned_text, flags=re.DOTALL | re.IGNORECASE)if html_match:inner = html_match.group(1)inner = 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>"md_match = re.search(r"```(?:py|python)?\s*\n(.*?)```",2 unmodified lines)if md_match:inner = re.sub(r"</?code[^>]*>", "", md_match.group(1), flags=re.IGNORECASE)return f"<code>\n{_clean_python_code(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:
app.py+11-18