CoolFace
Apppublic

DamonCooper/KMZ-Cleaner

sourceHugging Faceupdated 8mo agoView on Hugging Face
0likes
streamlit_app.py43 linesDownload Raw Back to src
1import streamlit as st2import zipfile3import xml.etree.ElementTree as ET4from datetime import datetime5import io6 7st.set_page_config(page_title="KMZ Cleaner", page_icon="🌍")8st.title("🌍 KMZ Cleaner Professional")9 10uploaded_file = st.file_uploader("Виберіть ваші KMZ файли", type=['kmz'])11 12if uploaded_file:13    st.info("Обробка файлу...")14    input_zip_stream = io.BytesIO(uploaded_file.read())15    output_zip_stream = io.BytesIO()16    17    with zipfile.ZipFile(input_zip_stream, 'r') as zin:18        with zipfile.ZipFile(output_zip_stream, 'w', compression=zipfile.ZIP_DEFLATED) as zout:19            for item in zin.infolist():20                content = zin.read(item.filename)21                if item.filename == 'doc.kml':22                    ET.register_namespace('', "http://www.opengis.net/kml/2.2")23                    root = ET.fromstring(content)24                    namespace = {'kml': 'http://www.opengis.net/kml/2.2'}25                    folders_removed = 026                    for parent in root.findall('.//kml:Folder/..', namespace):27                        for folder in parent.findall('kml:Folder', namespace):28                            desc = folder.find('kml:description', namespace)29                            if desc and desc.text == 'Район проникнення':30                                parent.remove(folder)31                                folders_removed += 132                    st.success(f"✅ Готово! Видалено районів: {folders_removed}")33                    new_content = ET.tostring(root, encoding='utf-8', xml_declaration=True)34                    zout.writestr(item.filename, new_content)35                else:36                    zout.writestr(item, content)37 38    st.download_button(39        label="📥 Завантажити результат",40        data=output_zip_stream.getvalue(),41        file_name=f"{datetime.now().strftime('%d%m%y')}-clean.kmz",42        mime="application/vnd.google-earth.kmz"43    )