Skip to content

Add docs #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/setup.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
python -m pip install torch torchaudio --index-url https://download.pytorch.org/whl/cpu
python -m pip install torch torchvision
python -m pip install -e ".[demo]"
python -m pip install --upgrade streamlit
sudo apt-get update && sudo apt-get install libgl1
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ repos:
rev: v5.0.0
hooks:
- id: check-added-large-files
exclude: docs
- id: check-case-conflict
- id: check-json
- id: check-merge-conflict
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@
</picture>
</p>

# OSM-AI-helper: a Blueprint by Mozilla.ai for contributing to Open Street Map with the help of AI
# OSM-AI-helper: a Blueprint by Mozilla.ai for contributing to OpenStreetMap with the help of AI

[![](https://dcbadge.limes.pink/api/server/YuMNeuKStr?style=flat)](https://discord.gg/YuMNeuKStr)
[![Docs](https://github.com/mozilla-ai/osm-ai-helper/actions/workflows/docs.yaml/badge.svg)](https://github.com/mozilla-ai/osm-ai-helper/actions/workflows/docs.yaml/)
[![Tests](https://github.com/mozilla-ai/osm-ai-helper/actions/workflows/tests.yaml/badge.svg)](https://github.com/mozilla-ai/osm-ai-helper/actions/workflows/tests.yaml/)
[![Ruff](https://github.com/mozilla-ai/osm-ai-helper/actions/workflows/lint.yaml/badge.svg?label=Ruff)](https://github.com/mozilla-ai/osm-ai-helper/actions/workflows/lint.yaml/)

<img src="./images/osm-ai-helper-diagram.png" width="800" alt="osm-ai-helper Diagram" />

📘 To explore this project further and discover other Blueprints, visit the [**Blueprints Hub**](https://developer-hub.mozilla.ai/).

👉 📖 For more detailed guidance on using this project, please visit our [**Docs here**](https://mozilla-ai.github.io/osm-ai-helper/)

### Built with

- Python 3.10+
- [Ultralytics](https://github.com/ultralytics/ultralytics)
- [SAM 2](https://github.com/facebookresearch/sam2)
![Python](https://img.shields.io/badge/Python-3.10%2B-blue) [![Ultralytics](https://img.shields.io/badge/Ultralytics-008080?logo=ultralytics&logoColor=white)](https://ultralytics.com/) [![SAM 2](https://img.shields.io/badge/SAM%202-0099FF?logo=meta&logoColor=white)](https://segment-anything.com/)


## Quick-start

Get started right away finding swimming pools and contributing them to Open Street Map:
Get started right away finding swimming pools and contributing them to OpenStreetMap:

| Find Swimming Pools |
| ------------------- |
| [![Run Inference](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mozilla-ai/osm-ai-helper/blob/main/demo/run_inference.ipynb)
| Google Colab | HuggingFace Spaces | GitHub Codespaces |
| -------------| ------------------- | ----------------- |
| [![Run Inference](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/mozilla-ai/osm-ai-helper/blob/main/demo/run_inference.ipynb) | [![Try on Spaces](https://img.shields.io/badge/%F0%9F%A4%97%20Try%20on-Spaces-blue)](https://huggingface.co/spaces/mozilla-ai/osm-ai-helper) | [![Try on Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=928839264&skip_quickstart=true&machine=standardLinux32gb) |

You can also create your own dataset and finetune a new model for a different use case:

Expand Down
74 changes: 56 additions & 18 deletions demo/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import folium
import streamlit as st
from branca.element import MacroElement
from jinja2 import Template
from loguru import logger
from huggingface_hub import hf_hub_download
from PIL import Image
Expand All @@ -24,6 +26,34 @@ def write(self, message):
return


@st.fragment
def show_map():
class LatLngPopup(MacroElement):
_template = Template(
"""
{% macro script(this, kwargs) %}
var {{this.get_name()}} = L.popup();
function latLngPop(e) {
{{this.get_name()}}
.setLatLng(e.latlng)
.setContent(e.latlng.lat.toFixed(4) + ", " + e.latlng.lng.toFixed(4))
.openOn({{this._parent.get_name()}});
}
{{this._parent.get_name()}}.on('click', latLngPop);
{% endmacro %}
"""
)

def __init__(self):
super().__init__()
self._name = "LatLngPopup"

m = folium.Map(location=[42.2489, -8.5117], zoom_start=11, tiles="OpenStreetMap")
m.add_child(LatLngPopup())

st_folium(m, height=400, width=800)


@st.fragment
def inference(lat_lon, margin):
with st.spinner("Downloading model..."):
Expand All @@ -35,7 +65,7 @@ def inference(lat_lon, margin):
)
with st.spinner("Running inference..."):
output_path, existing, new, missed = run_inference(
model_file="models/model.pt",
yolo_model_file="models/model.pt",
output_dir="results",
lat_lon=lat_lon,
margin=margin,
Expand Down Expand Up @@ -97,31 +127,39 @@ def upload_results(output_path):
)


st.title("Open Street Map AI Helper")
st.title("OpenStreetMap AI Helper")

st.divider()

st.subheader("Click on the map to select a latitude and longitude")

m = folium.Map(location=[42.2489, -8.5117], zoom_start=11, tiles="OpenStreetMap")
show_map()

st_data = st_folium(m, width=725)
lat_lon = st.text_input("Paste the copied (latitude, longitude)")

if st_data.get("last_clicked"):
lat = st_data["last_clicked"]["lat"]
lon = st_data["last_clicked"]["lng"]
st.write(f"Last Clicked: {lat}, {lon}")
if st.button("Run Inference") and lat_lon:
logger.add(StreamlitHandler(), format="<level>{message}</level>")

if st.button("Run Inference"):
streamlit_handler = StreamlitHandler()
logger.add(streamlit_handler, format="<level>{message}</level>")
lat, lon = lat_lon.split(",")
output_path, new = inference(
lat_lon=(float(lat.strip()), float(lon.strip())), margin=3
)

output_path, new = inference(lat_lon=(lat, lon), margin=3)
if new:
st.divider()
st.header("Review `new` polygons")
st.markdown(
"Every `new` polygon will be displayed at the center of the image in `yellow`."
)
st.markdown(
"Polygons in other colors are those already existing in OpenStreetMap and they just "
"indicate whether the model has found them (`green`) or missed them (`red`)."
)
for new in Path(output_path).glob("*.json"):
handle_polygon(new)

if new:
st.divider()
st.header("Review `new` polygons")
for new in Path(output_path).glob("*.json"):
handle_polygon(new)
logger.add(StreamlitHandler(), format="<level>{message}</level>")

upload_results(output_path)
upload_results(output_path)
else:
st.warning("No `new` polygons were found. Try a different location.")
Loading