ageraustine commited on
Commit
a9bebef
·
verified ·
1 Parent(s): e1b3834

Upload folder using huggingface_hub

Browse files
src/__pycache__/gradio_app.cpython-311.pyc CHANGED
Binary files a/src/__pycache__/gradio_app.cpython-311.pyc and b/src/__pycache__/gradio_app.cpython-311.pyc differ
 
src/gradio_app.py CHANGED
@@ -47,16 +47,109 @@ BASIN_NAMES = {0: "La Eure", 1: "La Risle"}
47
  BASIN_FILE_NAMES = {0: "eure", 1: "risle"}
48
  N_CLICK_TARGETS = 300
49
 
50
-
51
- def parse_data_root() -> Path:
 
 
 
 
 
 
 
 
 
52
  parser = argparse.ArgumentParser()
53
- parser.add_argument("--data-root", type=Path, default=Path("datasets"))
54
  args, _ = parser.parse_known_args()
55
- return args.data_root
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
 
58
- DATA_ROOT = parse_data_root()
59
 
 
60
 
61
  # --- Data Loaders (Cached via simple dictionaries/memoization) ---
62
  _cache = {}
 
47
  BASIN_FILE_NAMES = {0: "eure", 1: "risle"}
48
  N_CLICK_TARGETS = 300
49
 
50
+ def find_data_root() -> Path:
51
+ """
52
+ Automatically locate the dataset directory.
53
+
54
+ Priority:
55
+ 1. Explicit --data-root argument
56
+ 2. DATA_ROOT environment variable
57
+ 3. Common locations relative to app.py
58
+ 4. Recursive search for a directory containing
59
+ station_elevations.csv
60
+ """
61
  parser = argparse.ArgumentParser()
62
+ parser.add_argument("--data-root", type=Path, default=None)
63
  args, _ = parser.parse_known_args()
64
+
65
+ # 1. Explicit CLI argument
66
+ if args.data_root is not None:
67
+ root = args.data_root.expanduser().resolve()
68
+ if root.exists():
69
+ return root
70
+
71
+ # 2. Environment variable
72
+ import os
73
+
74
+ env_root = os.environ.get("DATA_ROOT")
75
+ if env_root:
76
+ root = Path(env_root).expanduser().resolve()
77
+ if root.exists():
78
+ return root
79
+
80
+ # app.py is in src/
81
+ app_dir = Path(__file__).resolve().parent
82
+ project_root = app_dir.parent
83
+
84
+ # 3. Common locations
85
+ candidates = [
86
+ Path.cwd() / "datasets",
87
+ Path.cwd() / "data",
88
+ project_root / "datasets",
89
+ project_root / "data",
90
+ app_dir / "datasets",
91
+ app_dir / "data",
92
+ ]
93
+
94
+ for root in candidates:
95
+ if (root / "station_elevations.csv").exists():
96
+ return root.resolve()
97
+
98
+ # 4. Search recursively from likely roots
99
+ search_roots = [
100
+ Path.cwd(),
101
+ project_root,
102
+ app_dir,
103
+ ]
104
+
105
+ seen = set()
106
+
107
+ for search_root in search_roots:
108
+ if not search_root.exists():
109
+ continue
110
+
111
+ try:
112
+ for station_file in search_root.rglob("station_elevations.csv"):
113
+ root = station_file.parent.resolve()
114
+
115
+ if root in seen:
116
+ continue
117
+
118
+ seen.add(root)
119
+
120
+ # Make sure this actually looks like our dataset
121
+ if (
122
+ (root / "station_elevations.csv").exists()
123
+ and (
124
+ (root / "centerlines").exists()
125
+ or (root / "reach_graph").exists()
126
+ or (root / "hydrometric").exists()
127
+ or (root / "ades").exists()
128
+ )
129
+ ):
130
+ return root
131
+ except (PermissionError, OSError):
132
+ continue
133
+
134
+ raise FileNotFoundError(
135
+ "Could not automatically locate the dataset directory. "
136
+ "Expected a directory containing 'station_elevations.csv'. "
137
+ "Use --data-root PATH or set DATA_ROOT."
138
+ )
139
+
140
+
141
+ DATA_ROOT = find_data_root()
142
+ print(f"[River Network Explorer] DATA_ROOT = {DATA_ROOT}")
143
+
144
+ # def parse_data_root() -> Path:
145
+ # parser = argparse.ArgumentParser()
146
+ # parser.add_argument("--data-root", type=Path, default=Path("datasets"))
147
+ # args, _ = parser.parse_known_args()
148
+ # return args.data_root
149
 
150
 
 
151
 
152
+ # DATA_ROOT = parse_data_root()
153
 
154
  # --- Data Loaders (Cached via simple dictionaries/memoization) ---
155
  _cache = {}