| import gradio as gr |
| import htmlmin |
| import tempfile |
|
|
| def minify_html(path): |
| |
| with open(path, "r", encoding="utf-8") as f: |
| txt = f.read() |
| |
| minified = htmlmin.minify( |
| txt, |
| remove_comments=True, |
| remove_empty_space=True, |
| reduce_empty_attributes=True, |
| reduce_boolean_attributes=True, |
| remove_optional_attribute_quotes=True, |
| keep_pre=False |
| ) |
| |
| tmp = tempfile.NamedTemporaryFile( |
| mode="w", delete=False, suffix=".html", encoding="utf-8" |
| ) |
| tmp.write(minified) |
| tmp.close() |
| return tmp.name |
|
|
| interface = gr.Interface( |
| fn=minify_html, |
| inputs=gr.File(label="Загрузите .html", type="filepath"), |
| outputs=gr.File(label="Скачать минифицированный .html"), |
| title="Максимальная HTML‑минификация" |
| ) |
|
|
| if __name__ == "__main__": |
| interface.launch() |