gourav3017 commited on
Commit
4ab9818
·
1 Parent(s): aa965c4

Update app.py for new hub version and download to local

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -18,7 +18,7 @@ token = os.getenv("HF_TOKEN")
18
  @st.cache_data
19
  def get_patient_ids():
20
  # Extract disease site from patient ID prefix (e.g., Lung_Patient_1)
21
- file = hf_hub_download(REPO_ID, repo_type="dataset", filename="data_info.jsonl", local_dir="./temp", token=token)
22
  with open(file) as f:
23
  # data_info = json.load(f)
24
  data_info = [json.loads(line) for line in f]
@@ -27,6 +27,9 @@ def get_patient_ids():
27
  df["disease_site"] = df["patient_id"].str.extract(r"^(.*?)_")
28
  return df
29
 
 
 
 
30
 
31
  @st.cache_data
32
  def load_all_metadata(disease_site):
@@ -40,7 +43,7 @@ def load_all_metadata(disease_site):
40
  structs = load_structure_metadata(patient_id)
41
  # Load beam metadata for the patient
42
  beams = load_beam_metadata(patient_id)
43
- planner_file = hf_hub_download(REPO_ID, repo_type="dataset", filename=f"data/{patient_id}/PlannerBeams.json", local_dir="./temp", token=token)
44
  with open(planner_file) as f:
45
  planner_data = json.load(f)
46
  planner_beam_ids = planner_data.get("IDs", [])
@@ -54,25 +57,24 @@ def load_all_metadata(disease_site):
54
 
55
  @st.cache_data
56
  def load_structure_metadata(patient_id):
57
- file = hf_hub_download(REPO_ID, repo_type="dataset", filename=f"data/{patient_id}/StructureSet_MetaData.json", local_dir="./temp", token=token)
58
  with open(file) as f:
59
  return json.load(f)
60
 
61
  @st.cache_data
62
  def load_beam_metadata(patient_id):
63
- beam_meta_paths = []
64
-
65
- files = list_repo_files(repo_id=REPO_ID, repo_type="dataset")
66
  beam_meta_paths = [
67
  f for f in files
68
  if f.startswith(f"data/{patient_id}/Beams/Beam_") and f.endswith("_MetaData.json")
69
  ]
70
- # for bid in beam_ids:
71
- # beam_meta_paths.append(f"data/{patient_id}/Beams/Beam_{bid}_MetaData.json")
72
 
73
  beam_meta = []
74
  for path in beam_meta_paths:
75
- file = hf_hub_download(REPO_ID, repo_type="dataset", filename=path, local_dir="./temp", token=token)
 
 
 
76
  with open(file) as f:
77
  beam_meta.append(json.load(f))
78
  return beam_meta
 
18
  @st.cache_data
19
  def get_patient_ids():
20
  # Extract disease site from patient ID prefix (e.g., Lung_Patient_1)
21
+ file = hf_hub_download(REPO_ID, repo_type="dataset", filename="data_info.jsonl", token=token)
22
  with open(file) as f:
23
  # data_info = json.load(f)
24
  data_info = [json.loads(line) for line in f]
 
27
  df["disease_site"] = df["patient_id"].str.extract(r"^(.*?)_")
28
  return df
29
 
30
+ @st.cache_data
31
+ def _list_all_repo_files():
32
+ return list_repo_files(repo_id=REPO_ID, repo_type="dataset")
33
 
34
  @st.cache_data
35
  def load_all_metadata(disease_site):
 
43
  structs = load_structure_metadata(patient_id)
44
  # Load beam metadata for the patient
45
  beams = load_beam_metadata(patient_id)
46
+ planner_file = hf_hub_download(REPO_ID, repo_type="dataset", filename=f"data/{patient_id}/PlannerBeams.json", token=token)
47
  with open(planner_file) as f:
48
  planner_data = json.load(f)
49
  planner_beam_ids = planner_data.get("IDs", [])
 
57
 
58
  @st.cache_data
59
  def load_structure_metadata(patient_id):
60
+ file = hf_hub_download(REPO_ID, repo_type="dataset", filename=f"data/{patient_id}/StructureSet_MetaData.json", token=token)
61
  with open(file) as f:
62
  return json.load(f)
63
 
64
  @st.cache_data
65
  def load_beam_metadata(patient_id):
66
+ files = _list_all_repo_files()
 
 
67
  beam_meta_paths = [
68
  f for f in files
69
  if f.startswith(f"data/{patient_id}/Beams/Beam_") and f.endswith("_MetaData.json")
70
  ]
 
 
71
 
72
  beam_meta = []
73
  for path in beam_meta_paths:
74
+ file = hf_hub_download(REPO_ID,
75
+ repo_type="dataset",
76
+ filename=path,
77
+ token=token) # no local_dir
78
  with open(file) as f:
79
  beam_meta.append(json.load(f))
80
  return beam_meta