from datasets import load_dataset
import json
import os
import zipfile
# Load dataset
dataset = load_dataset("maringetxway/local")["train"]
# Create output folder
os.makedirs("map_project", exist_ok=True)
# Save data.json
with open("map_project/data.json", "w") as f:
json.dump(dataset[:], f)
# index.html
index_html = """
World Map from Hugging Face Dataset
"""
with open("map_project/index.html", "w") as f:
f.write(index_html)
# script.js
script_js = """const map = L.map('map').setView([20, 0], 2);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
fetch('data.json')
.then(response => response.json())
.then(data => {
data.forEach(entry => {
const lat = parseFloat(entry.latitude || entry.Latitude);
const lng = parseFloat(entry.longitude || entry.Longitude);
const name = entry.name || entry.Name || 'Unknown';
const desc = entry.description || entry.Description || '';
if (!isNaN(lat) && !isNaN(lng)) {
L.marker([lat, lng])
.addTo(map)
.bindPopup(`${name}
${desc}`);
}
});
});
"""
with open("map_project/script.js", "w") as f:
f.write(script_js)
# Zip it
with zipfile.ZipFile("world_map_project.zip", "w") as zipf:
for foldername, subfolders, filenames in os.walk("map_project"):
for filename in filenames:
filepath = os.path.join(foldername, filename)
zipf.write(filepath, os.path.relpath(filepath, "map_project"))
print("✅ Done! File saved as world_map_project.zip")