Replace unsupported range sliders with min/max number pairs (range sliders do not work in gradio 5.x or 6.x)
Browse files100 unmodified lines10110210310410510631 unmodified lines1381391401411421431441451461471481491501511521531544 unmodified lines15916016116216316416516616716 unmodified lines18418518618718818919019119219319413 unmodified lines20820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723813 unmodified lines252253254255256257258259100 unmodified lines"""def build_map(pid):sel = PARCELS[PARCELS[ID_COL] == pid]if sel.empty:31 unmodified linesreturn iframe, titledef apply_filters(garden_rng, parcel_lo, parcel_hi, cov_rng, nb_rng, gemeenten, secties,perc_lo, perc_hi, year_rng, excl_year, doelen, residential, idq, limit):df = DATAif parcel_lo is None:parcel_lo = 0.0if parcel_hi is None:parcel_hi = PARCEL_MAXm = df['calculated_garden_area'].between(garden_rng[0], garden_rng[1])m = m & df['total_parcel_area'].between(parcel_lo, parcel_hi)m = m & df['building_coverage_pct'].between(cov_rng[0], cov_rng[1])m = m & df['n_buildings'].between(nb_rng[0], nb_rng[1])if gemeenten:m = m & df['kadastraleGemeenteWaarde'].isin(gemeenten)if secties:4 unmodified lineslo = -1 if perc_lo is None else perc_lohi = 10 ** 9 if perc_hi is None else perc_him = m & df['perceelnummer'].between(lo, hi)if year_rng is not None:y = df['bouwjaar_median']ym = y.between(year_rng[0], year_rng[1])if not excl_year:ym = ym | y.isna()m = m & ym16 unmodified linesframe[c] = frame[c].round(1)csv_path = os.path.join(tempfile.gettempdir(), 'maastricht_parcels_filtered.csv')export.to_csv(csv_path, index=False)# NaN (parcels with no buildings have no bouwjaar) is not JSON compliant:# convert to None so the Dataframe payload serializes.shown = shown.astype(object).where(pd.notna(shown), None)status = ('**' + format(len(res), ',d') + '** parcels match (of ' + format(len(df), ',d')+ ' in the snapshot). Garden ' + str(garden_rng[0]) + '\u2013' + str(garden_rng[1])+ ' m\u00b2, sorted by garden size; showing top ' + str(len(shown)) + '.')return status, shown, csv_path13 unmodified linesui.Markdown('Cadastral parcels (**Kadaster BRK**) joined to building footprints (**BAG**) for the ''whole municipality of Maastricht, pre-loaded from a one-time PDOK snapshot.\n\n''*Garden area = parcel area \u2212 building footprint (intersection-clipped).*')with ui.Row():with ui.Column(scale=1):ui.Markdown('### Filters')garden = ui.Slider(minimum=0, maximum=2000, value=(50, 500), step=10,label='Garden area (m\u00b2)')parcel_lo = ui.Number(value=0, label='Parcel area min (m\u00b2)')parcel_hi = ui.Number(value=PARCEL_MAX, label='Parcel area max (m\u00b2)')cov = ui.Slider(minimum=0, maximum=100, value=(0, 100), step=1,label='Building coverage (%)')nb = ui.Slider(minimum=0, maximum=50, value=(0, 50), step=1,label='Number of buildings')gemeenten = ui.Dropdown(choices=GEMEENTEN, multiselect=True,label='Kadastrale gemeente')secties = ui.Dropdown(choices=SECTIES, multiselect=True, label='Sectie')with ui.Row():perc_lo = ui.Number(value=None, label='Perceel nr min')perc_hi = ui.Number(value=None, label='Perceel nr max')year = ui.Slider(minimum=1200, maximum=2026, value=(1200, 2026), step=1,label='Bouwjaar (median)')excl_year = ui.Checkbox(value=False,label='Exclude parcels without a known bouwjaar')doelen = ui.Dropdown(choices=DOELEN, multiselect=True, label='Gebruiksdoel')residential = ui.Radio(choices=['Any', 'Yes', 'No'], value='Any',label='Residential (woonfunctie)')idq = ui.Textbox(label='Kadaster ID contains', placeholder='e.g. 3430000927')13 unmodified linesmodal_map = ui.HTML()close_btn = ui.Button('\u2715 Close map', elem_id='parcel-modal-close')inputs = [garden, parcel_lo, parcel_hi, cov, nb, gemeenten, secties, perc_lo, perc_hi,year, excl_year, doelen, residential, idq, limit]btn.click(fn=apply_filters, inputs=inputs, outputs=[status, table, download])demo.load(fn=apply_filters, inputs=inputs, outputs=[status, table, download])table.select(fn=open_modal, inputs=[table], outputs=[modal, modal_title, modal_map])100 unmodified lines10110210310410510610710810911011111211311431 unmodified lines1461471481491501511521531541551561571581591601611621631641651661671681691701711721731741754 unmodified lines18018118218318418518618718818919016 unmodified lines20720820921021121221321421521621713 unmodified lines23123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626713 unmodified lines281282283284285286287288289100 unmodified lines"""def _fmt(v):try:fv = float(v)return str(int(fv)) if fv.is_integer() else str(round(fv, 1))except Exception:return str(v)def build_map(pid):sel = PARCELS[PARCELS[ID_COL] == pid]if sel.empty:31 unmodified linesreturn iframe, titledef apply_filters(garden_lo, garden_hi, parcel_lo, parcel_hi, cov_lo, cov_hi, nb_lo, nb_hi,gemeenten, secties, perc_lo, perc_hi, year_lo, year_hi, excl_year,doelen, residential, idq, limit):df = DATAif garden_lo is None:garden_lo = 0.0if garden_hi is None:garden_hi = 1e12if parcel_lo is None:parcel_lo = 0.0if parcel_hi is None:parcel_hi = PARCEL_MAXif cov_lo is None:cov_lo = 0.0if cov_hi is None:cov_hi = 100.0if nb_lo is None:nb_lo = 0if nb_hi is None:nb_hi = 10 ** 9m = df['calculated_garden_area'].between(garden_lo, garden_hi)m = m & df['total_parcel_area'].between(parcel_lo, parcel_hi)m = m & df['building_coverage_pct'].between(cov_lo, cov_hi)m = m & df['n_buildings'].between(nb_lo, nb_hi)if gemeenten:m = m & df['kadastraleGemeenteWaarde'].isin(gemeenten)if secties:4 unmodified lineslo = -1 if perc_lo is None else perc_lohi = 10 ** 9 if perc_hi is None else perc_him = m & df['perceelnummer'].between(lo, hi)if year_lo is not None or year_hi is not None:lo = 1200 if year_lo is None else year_lohi = 2026 if year_hi is None else year_hiy = df['bouwjaar_median']ym = y.between(lo, hi)if not excl_year:ym = ym | y.isna()m = m & ym16 unmodified linesframe[c] = frame[c].round(1)csv_path = os.path.join(tempfile.gettempdir(), 'maastricht_parcels_filtered.csv')export.to_csv(csv_path, index=False)# NaN (parcels without buildings have no bouwjaar) is not JSON compliant:# convert to None so the Dataframe payload serializes.shown = shown.astype(object).where(pd.notna(shown), None)status = ('**' + format(len(res), ',d') + '** parcels match (of ' + format(len(df), ',d')+ ' in the snapshot). Garden ' + _fmt(garden_lo) + '\u2013' + _fmt(garden_hi)+ ' m\u00b2, sorted by garden size; showing top ' + str(len(shown)) + '.')return status, shown, csv_path13 unmodified linesui.Markdown('Cadastral parcels (**Kadaster BRK**) joined to building footprints (**BAG**) for the ''whole municipality of Maastricht, pre-loaded from a one-time PDOK snapshot.\n\n''*Garden area = parcel area \u2212 building footprint (intersection-clipped). ''Every field is filterable; the garden range defaults to 50\u2013500 m\u00b2.*')with ui.Row():with ui.Column(scale=1):ui.Markdown('### Filters')with ui.Row():garden_lo = ui.Number(value=50, label='Garden min (m\u00b2)')garden_hi = ui.Number(value=500, label='Garden max (m\u00b2)')with ui.Row():parcel_lo = ui.Number(value=0, label='Parcel min (m\u00b2)')parcel_hi = ui.Number(value=PARCEL_MAX, label='Parcel max (m\u00b2)')with ui.Row():cov_lo = ui.Number(value=0, label='Coverage min (%)')cov_hi = ui.Number(value=100, label='Coverage max (%)')with ui.Row():nb_lo = ui.Number(value=0, label='Buildings min')nb_hi = ui.Number(value=50, label='Buildings max')with ui.Row():perc_lo = ui.Number(value=None, label='Perceel nr min')perc_hi = ui.Number(value=None, label='Perceel nr max')with ui.Row():year_lo = ui.Number(value=1200, label='Bouwjaar min')year_hi = ui.Number(value=2026, label='Bouwjaar max')gemeenten = ui.Dropdown(choices=GEMEENTEN, multiselect=True,label='Kadastrale gemeente')secties = ui.Dropdown(choices=SECTIES, multiselect=True, label='Sectie')doelen = ui.Dropdown(choices=DOELEN, multiselect=True, label='Gebruiksdoel')excl_year = ui.Checkbox(value=False,label='Exclude parcels without a known bouwjaar')residential = ui.Radio(choices=['Any', 'Yes', 'No'], value='Any',label='Residential (woonfunctie)')idq = ui.Textbox(label='Kadaster ID contains', placeholder='e.g. 3430000927')13 unmodified linesmodal_map = ui.HTML()close_btn = ui.Button('\u2715 Close map', elem_id='parcel-modal-close')inputs = [garden_lo, garden_hi, parcel_lo, parcel_hi, cov_lo, cov_hi, nb_lo, nb_hi,gemeenten, secties, perc_lo, perc_hi, year_lo, year_hi, excl_year,doelen, residential, idq, limit]btn.click(fn=apply_filters, inputs=inputs, outputs=[status, table, download])demo.load(fn=apply_filters, inputs=inputs, outputs=[status, table, download])table.select(fn=open_modal, inputs=[table], outputs=[modal, modal_title, modal_map])
_space/app.py+56-26