File size: 1,046 Bytes
4470c81
 
 
 
 
 
 
 
8d6d0f6
4470c81
 
 
 
 
 
 
4422bca
4470c81
4422bca
4470c81
 
 
4422bca
4470c81
4422bca
4470c81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import io

import pandas as pd
import streamlit as st
from huggingface_hub import HfApi


@st.cache_resource
def get_hf_api() -> HfApi:
    return HfApi()


@st.cache_resource
def get_geojson_index_df():
    hf_api = get_hf_api()
    try:
        index_path = hf_api.hf_hub_download(
            repo_id="rodekruis/flood-mapping",
            filename="index.parquet",
            repo_type="dataset",
            force_download=True,
        )
        return pd.read_parquet(index_path)
    except Exception as e:
        st.warning(f"No index.parquet found on Hugging Face: {e}")
        return pd.DataFrame(columns=["aoi_id", "datetime", "product", "path_in_repo"])


def update_geojson_index_df(index_df: pd.DataFrame):
    hf_api = get_hf_api()

    write_buffer = io.BytesIO()
    index_df.to_parquet(write_buffer, index=False)

    hf_api.upload_file(
        path_or_fileobj=write_buffer,
        path_in_repo="index.parquet",
        repo_id="rodekruis/flood-mapping",
        repo_type="dataset",
    )
    get_geojson_index_df.clear()