Skip to content

Commit b468d9b

Browse files
committed
retour api fix
1 parent 1c47643 commit b468d9b

1 file changed

Lines changed: 14 additions & 19 deletions

File tree

app/main.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import gc
66
import os
77
from contextlib import asynccontextmanager
8-
from typing import Dict
8+
from typing import Dict, List
99

1010
import geopandas as gpd
1111
import mlflow
@@ -17,7 +17,6 @@
1717
from pyproj import Transformer
1818
from shapely.geometry import box
1919
from shapely.geometry import Point
20-
import requests
2120

2221
from app.logger_config import configure_logger
2322
from app.utils import (
@@ -94,53 +93,49 @@ def show_welcome_page():
9493

9594
@app.get("/find_image", tags=["Find Image"])
9695
async def find_image(
97-
lon_gps: float,
98-
lat_gps: float,
99-
nuts_id: str,
96+
gps_point: List[float] = Query(..., description="[longitude, latitude] in WGS84"),
97+
nuts_id: str = Query(...),
10098
year: int = Query(2021, ge=2018, le=2024)
10199
) -> str:
102100
"""
103101
Find image path for a given NUTS3 and year.
104102
105103
Args:
106-
lon_gps (float): longitude of the gps point.
107-
lat_gps (float): longitude of the gps point.
104+
gps_point (List[float]): [longitude, latitude] of the GPS point in WGS84.
108105
nuts_id (str): The ID of the NUTS.
109106
year (int): The year of the satellite images.
110107
Returns:
111-
str: Image filepath if the image is finded, otherwise None.
112-
108+
str: Image filepath if found, otherwise empty string.
113109
"""
110+
lon_gps, lat_gps = gps_point[0], gps_point[1]
114111
logger.info(f"Find the image filepath for this gps point: {lon_gps}, {lat_gps}")
115112
gc.collect()
116113

117114
url = f"https://minio.lab.sspcloud.fr/projet-formation/diffusion/funathon/2026/project3/data/images/{nuts_id}/{year}/filename2bbox.parquet"
118115

119-
response = requests.head(url)
120-
121-
if response.status_code == 200:
116+
try:
122117
df = pd.read_parquet(url)
123-
else:
124-
print(f"❌ No data for NUTS3='{nuts_id}' and year={year} (HTTP {response.status_code})")
125-
return None
118+
except Exception:
119+
print(f"❌ No data for NUTS3='{nuts_id}' and year={year}")
120+
return ""
126121

127-
# Création de la géométrie
128122
df["geometry"] = df.apply(
129123
lambda row: box(row["bbox"][0], row["bbox"][1], row["bbox"][2], row["bbox"][3]),
130124
axis=1
131125
)
132126

133-
# Conversion en GeoDataFrame
134127
gdf = gpd.GeoDataFrame(df, geometry="geometry", crs="EPSG:3035")
135128

136-
# Convertir le point GPS (EPSG:4326) en EPSG:3035
137129
transformer = Transformer.from_crs("EPSG:4326", "EPSG:3035", always_xy=True)
138130
x, y = transformer.transform(lon_gps, lat_gps)
139131

140132
point = Point(x, y)
141133
result = gdf[gdf.contains(point)]
142134

143-
return result["filename"].values
135+
if result.empty:
136+
return ""
137+
138+
return str(result["filename"].values[0])
144139

145140

146141
@app.get("/predict_image", tags=["Predict Image"])

0 commit comments

Comments
 (0)