from datetime import datetime import pandas as pd import streamlit as st from utils.kml_creator import generate_kml_from_df st.title("📡 Telecom Sector KML Generator") # display mandatory columns col1, col2 = st.columns(2) with col1: st.write("Mandatory columns:") st.markdown( """ | Column Name | Description | | --- | --- | | code| code of the site | | name | Name of the sector | | Azimut | Azimuth of the sector | | Longitude | Longitude of the sector | | Latitude | Latitude of the sector | | Size | Size of the sector ex:100 | | colors | Color of the sector | """ ) st.write( "All other columns added in the file will be displayed in the KML description for each sector." ) with col2: st.markdown( """ | Color Name | KML Color Code (AABBGGRR) | | --- | --- | | Red | 7f0000ff | | Green | 7f00ff00 | | Blue | 7fff0000 | | Yellow | 7f00ffff | | Cyan | 7fffff00 | | Magenta | 7fff00ff | | Orange | 7f007fff | | Purple | 7f7f00ff | | Pink | 7fcc99ff | | Brown | 7f2a2aa5 | """ ) sector_kml_sample_file = "samples/Sector_kml.xlsx" # Create a download button st.download_button( label="Download Sector KML sample File", data=open(sector_kml_sample_file, "rb").read(), file_name="Sector_kml.xlsx", mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", ) st.write("Upload an excel file containing sectors data to generate a KML file.") # Upload CSV file uploaded_file = st.file_uploader("Upload XLSX file", type=["xlsx"]) if uploaded_file is not None: # Read CSV df = pd.read_excel(uploaded_file, keep_default_na=False) # Check if required columns exist required_columns = { "code", "name", "Azimut", "Longitude", "Latitude", "size", "color", } if not required_columns.issubset(df.columns): st.error(f"Uploaded file must contain columns: {', '.join(required_columns)}") else: # Generate KML kml_data = generate_kml_from_df(df) # Download button st.download_button( label="📥 Download KML", data=kml_data, file_name=f"Sectors_kml_{datetime.now()}.kml", mime="application/vnd.google-earth.kml+xml", ) st.success("KML file generated successfully! 🎉")