Spaces:
Sleeping
Sleeping
Commit ·
cf13ec1
1
Parent(s): 872fbcb
fix localisation (#15)
Browse files- fix rer localisation (a372660f260cb902a2bc1c49bb953513a2b0fee4)
- Dockerfile +2 -1
- src/data_loader.py +3 -0
- src/flowchart_engine.py +19 -3
Dockerfile
CHANGED
|
@@ -9,9 +9,10 @@ RUN apt-get update && apt-get install -y \
|
|
| 9 |
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
|
| 11 |
COPY requirements.txt ./
|
|
|
|
|
|
|
| 12 |
COPY src/ ./src/
|
| 13 |
|
| 14 |
-
RUN pip3 install -r requirements.txt
|
| 15 |
|
| 16 |
EXPOSE 8501
|
| 17 |
|
|
|
|
| 9 |
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
|
| 11 |
COPY requirements.txt ./
|
| 12 |
+
RUN pip3 install -r requirements.txt
|
| 13 |
+
|
| 14 |
COPY src/ ./src/
|
| 15 |
|
|
|
|
| 16 |
|
| 17 |
EXPOSE 8501
|
| 18 |
|
src/data_loader.py
CHANGED
|
@@ -3,6 +3,7 @@ data_loader.py - Chargement et indexation des bases de données EcoALIM, GFLI et
|
|
| 3 |
"""
|
| 4 |
from __future__ import annotations
|
| 5 |
|
|
|
|
| 6 |
import json
|
| 7 |
import re
|
| 8 |
from functools import lru_cache
|
|
@@ -238,6 +239,7 @@ def search_gfli(
|
|
| 238 |
Recherche dans GFLI par nom de matière (en anglais) et optionnellement par pays ISO.
|
| 239 |
Uses word-boundary matching for better precision.
|
| 240 |
"""
|
|
|
|
| 241 |
df = load_gfli()
|
| 242 |
matiere_norm = _normalize_for_search(matiere)
|
| 243 |
|
|
@@ -270,6 +272,7 @@ def search_gfli(
|
|
| 270 |
# Filtrage strict : si un pays est demandé, ne retourner QUE les résultats de ce pays
|
| 271 |
mask = mask & mask_country
|
| 272 |
|
|
|
|
| 273 |
return df[mask].copy()
|
| 274 |
|
| 275 |
|
|
|
|
| 3 |
"""
|
| 4 |
from __future__ import annotations
|
| 5 |
|
| 6 |
+
import logging
|
| 7 |
import json
|
| 8 |
import re
|
| 9 |
from functools import lru_cache
|
|
|
|
| 239 |
Recherche dans GFLI par nom de matière (en anglais) et optionnellement par pays ISO.
|
| 240 |
Uses word-boundary matching for better precision.
|
| 241 |
"""
|
| 242 |
+
logging.info(f"Searching GLFI with args matiere: {matiere}, country_iso: {country_iso}")
|
| 243 |
df = load_gfli()
|
| 244 |
matiere_norm = _normalize_for_search(matiere)
|
| 245 |
|
|
|
|
| 272 |
# Filtrage strict : si un pays est demandé, ne retourner QUE les résultats de ce pays
|
| 273 |
mask = mask & mask_country
|
| 274 |
|
| 275 |
+
logging.info("Masked df", df[mask].head())
|
| 276 |
return df[mask].copy()
|
| 277 |
|
| 278 |
|
src/flowchart_engine.py
CHANGED
|
@@ -78,7 +78,10 @@ def _is_france(pays: Optional[str]) -> bool:
|
|
| 78 |
if not pays:
|
| 79 |
return False
|
| 80 |
n = _normalize_country_name(pays)
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
|
| 84 |
def _is_european(pays: Optional[str]) -> bool:
|
|
@@ -88,7 +91,8 @@ def _is_european(pays: Optional[str]) -> bool:
|
|
| 88 |
n = _normalize_country_name(pays)
|
| 89 |
if n in config.EUROPEAN_COUNTRIES_FR:
|
| 90 |
return True
|
| 91 |
-
|
|
|
|
| 92 |
return pays_iso in config.EUROPEAN_COUNTRIES_ISO
|
| 93 |
|
| 94 |
|
|
@@ -96,7 +100,19 @@ def _get_country_iso(pays: Optional[str]) -> Optional[str]:
|
|
| 96 |
"""Convertit un nom de pays FR en code ISO."""
|
| 97 |
if not pays:
|
| 98 |
return None
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
|
| 102 |
def _is_name_match(matiere: str, intrant_name: str) -> bool:
|
|
|
|
| 78 |
if not pays:
|
| 79 |
return False
|
| 80 |
n = _normalize_country_name(pays)
|
| 81 |
+
if n in ("france", "fr"):
|
| 82 |
+
return True
|
| 83 |
+
# Fallback: check if input is ISO code "FR"
|
| 84 |
+
return pays.strip().upper() == "FR"
|
| 85 |
|
| 86 |
|
| 87 |
def _is_european(pays: Optional[str]) -> bool:
|
|
|
|
| 91 |
n = _normalize_country_name(pays)
|
| 92 |
if n in config.EUROPEAN_COUNTRIES_FR:
|
| 93 |
return True
|
| 94 |
+
# Try to get ISO from French mapping, or use uppercase input as fallback
|
| 95 |
+
pays_iso = config.PAYS_FR_TO_ISO.get(n, pays.strip().upper())
|
| 96 |
return pays_iso in config.EUROPEAN_COUNTRIES_ISO
|
| 97 |
|
| 98 |
|
|
|
|
| 100 |
"""Convertit un nom de pays FR en code ISO."""
|
| 101 |
if not pays:
|
| 102 |
return None
|
| 103 |
+
n = _normalize_country_name(pays)
|
| 104 |
+
# Try to get ISO from French mapping, or use uppercase input as fallback if it's already an ISO code
|
| 105 |
+
iso = config.PAYS_FR_TO_ISO.get(n)
|
| 106 |
+
if iso:
|
| 107 |
+
return iso
|
| 108 |
+
# Check if input is already a valid ISO code
|
| 109 |
+
pays_upper = pays.strip().upper()
|
| 110 |
+
if pays_upper in config.EUROPEAN_COUNTRIES_ISO:
|
| 111 |
+
return pays_upper
|
| 112 |
+
# Check if it's a valid ISO code in our mapping values
|
| 113 |
+
if pays_upper in config.PAYS_FR_TO_ISO.values():
|
| 114 |
+
return pays_upper
|
| 115 |
+
return None
|
| 116 |
|
| 117 |
|
| 118 |
def _is_name_match(matiere: str, intrant_name: str) -> bool:
|