Spaces:
Running
Running
Download extract_html.py from Tom199328/MOSS-TTS-Nano: direct link, hf CLI and curl.
- Browser
- Download file 1.33 kB
-
https://huggingface.co/spaces/Tom199328/MOSS-TTS-Nano/resolve/main/extract_html.py
- Command line
-
hf download hf://spaces/Tom199328/MOSS-TTS-Nano/extract_html.py
-
curl -L -o extract_html.py https://huggingface.co/spaces/Tom199328/MOSS-TTS-Nano/resolve/main/extract_html.py
1.33 kB
| import os | |
| from pathlib import Path | |
| def extract_html(): | |
| app_path = Path("app.py") | |
| content = app_path.read_text(encoding="utf-8") | |
| start_marker = ' template = """\n<!doctype html>' | |
| end_marker = '\n</html>\n"""' | |
| start_idx = content.find(start_marker) | |
| if start_idx == -1: | |
| print("Start marker not found.") | |
| return | |
| end_idx = content.find(end_marker, start_idx) | |
| if end_idx == -1: | |
| print("End marker not found.") | |
| return | |
| # Extract the HTML content | |
| html_content = content[start_idx + len(' template = """\n') : end_idx + len('\n</html>\n')] | |
| # Write to ui/templates/index.html | |
| os.makedirs("ui/templates", exist_ok=True) | |
| Path("ui/templates/index.html").write_text(html_content, encoding="utf-8") | |
| # Replace in app.py | |
| replacement = ''' import os | |
| template_path = os.path.join(os.path.dirname(__file__), "ui", "templates", "index.html") | |
| with open(template_path, "r", encoding="utf-8") as f: | |
| template = f.read()''' | |
| new_content = content[:start_idx] + replacement + content[end_idx + len('\n"""'):] | |
| app_path.write_text(new_content, encoding="utf-8") | |
| print("Successfully extracted HTML to ui/templates/index.html and updated app.py!") | |
| if __name__ == "__main__": | |
| extract_html() | |