File size: 1,110 Bytes
622a1cd
 
 
 
c60585c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
622a1cd
 
c60585c
 
 
 
622a1cd
 
 
418f355
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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()