# plan 1 below script is a sample to let the space save a file user uploaded to a private repo 2 the context is that we want to help user do data analysis: user need to upload the kpi of individual employees(A, which we do not know and should not know), and compare these data with employee test score(which we know), the identifier is email 3 in order to help user with analysis without knowning indiviudal employee kpi, we want to save a copy of data where the score corresponds while the email is unknown ## prd Give customers a one-click upload inside our Hugging Face Space that: merges their private KPI sheet with our stored assessment scores via email replaces every e-mail with a deterministic, irreversible hash (employee_id) stores only the privacy-safe table to the public dataset zh3036/lenovo_kpi never lets raw e-mail or KPI data leave the running container. ## sample code ``` python import gradio as gr import os, shutil, pathlib from huggingface_hub import HfApi # -------------------------------------------------- # 1 ) Tell the script where to push the uploads # -------------------------------------------------- REPO_ID = "zh3036/lenovo_kpi" # ← your dataset repo REPO_TYPE = "dataset" # <- do not change UPLOAD_SUBDIR = "raw_uploads" # folder *inside* the repo # The write token lives in the Space’s “Settings → Secrets” HF_WRITE_TOKEN = os.getenv("HF_WRITE_TOKEN") api = HfApi() # -------------------------------------------------- # 2 ) Callback that fires as soon as a file arrives # -------------------------------------------------- def receive(file_obj): # A. keep a local copy inside the running container (optional) os.makedirs("uploads", exist_ok=True) local_path = pathlib.Path("uploads") / pathlib.Path(file_obj.name).name shutil.copy(file_obj.name, local_path) # B. push permanently to the Hub hub_path = f"{UPLOAD_SUBDIR}/{local_path.name}" api.upload_file( path_or_fileobj=local_path, path_in_repo=hub_path, repo_id=REPO_ID, repo_type=REPO_TYPE, token=HF_WRITE_TOKEN, ) # C. tiny confirmation for the browser return f"✅ {local_path.name} stored in {REPO_ID}/{hub_path}" # -------------------------------------------------- # 3 ) Minimal Gradio UI # -------------------------------------------------- with gr.Blocks() as demo: uploader = gr.File(label="Drop a file for Lenovo KPI dataset") status = gr.Textbox(label="Upload log", interactive=False) uploader.upload(receive, uploader, status) demo.launch() ```