Spaces:
Sleeping
Sleeping
Upload app.py
Browse files- metadata_search/app.py +32 -0
metadata_search/app.py
CHANGED
|
@@ -119,6 +119,9 @@ UI_DIR = PROJECT_ROOT / "github_pages"
|
|
| 119 |
|
| 120 |
@app.get("/api/test-summary")
|
| 121 |
def test_summary():
|
|
|
|
|
|
|
|
|
|
| 122 |
file_name = request.args.get("file", "").strip()
|
| 123 |
|
| 124 |
if not file_name:
|
|
@@ -127,15 +130,44 @@ def test_summary():
|
|
| 127 |
"error": "Missing ?file=..."
|
| 128 |
}), 400
|
| 129 |
|
|
|
|
| 130 |
path = summary_path(file_name)
|
| 131 |
text = load_summary(file_name)
|
| 132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
return jsonify({
|
| 134 |
"ok": path is not None and text is not None,
|
| 135 |
"file_name": file_name,
|
|
|
|
|
|
|
|
|
|
| 136 |
"resolved_path": str(path) if path else None,
|
| 137 |
"text_length": len(text) if text else 0,
|
| 138 |
"preview": text[:500] if text else None,
|
|
|
|
|
|
|
| 139 |
})
|
| 140 |
|
| 141 |
|
|
|
|
| 119 |
|
| 120 |
@app.get("/api/test-summary")
|
| 121 |
def test_summary():
|
| 122 |
+
import re
|
| 123 |
+
from huggingface_hub import hf_hub_download
|
| 124 |
+
|
| 125 |
file_name = request.args.get("file", "").strip()
|
| 126 |
|
| 127 |
if not file_name:
|
|
|
|
| 130 |
"error": "Missing ?file=..."
|
| 131 |
}), 400
|
| 132 |
|
| 133 |
+
# First test the normal application path.
|
| 134 |
path = summary_path(file_name)
|
| 135 |
text = load_summary(file_name)
|
| 136 |
|
| 137 |
+
# If normal resolution fails, expose the exact cloud lookup attempt.
|
| 138 |
+
year_match = re.search(r"\\s-\\s(\\d{4})\\s-\\s", file_name)
|
| 139 |
+
year = year_match.group(1) if year_match else None
|
| 140 |
+
repo_id = os.getenv(
|
| 141 |
+
"WATERSCOPE_DATASET_REPO",
|
| 142 |
+
"EnvironmentalAI/WaterScopeAI-Data",
|
| 143 |
+
).strip()
|
| 144 |
+
repo_file = f"Summary/{year}/{Path(file_name).name}" if year else None
|
| 145 |
+
|
| 146 |
+
direct_download_path = None
|
| 147 |
+
direct_download_error = None
|
| 148 |
+
|
| 149 |
+
if path is None and repo_file:
|
| 150 |
+
try:
|
| 151 |
+
direct_download_path = hf_hub_download(
|
| 152 |
+
repo_id=repo_id,
|
| 153 |
+
repo_type="dataset",
|
| 154 |
+
filename=repo_file,
|
| 155 |
+
local_dir="/tmp/waterscope-summary-debug",
|
| 156 |
+
)
|
| 157 |
+
except Exception as exc:
|
| 158 |
+
direct_download_error = f"{type(exc).__name__}: {exc}"
|
| 159 |
+
|
| 160 |
return jsonify({
|
| 161 |
"ok": path is not None and text is not None,
|
| 162 |
"file_name": file_name,
|
| 163 |
+
"detected_year": year,
|
| 164 |
+
"repo_id": repo_id,
|
| 165 |
+
"repo_file_attempted": repo_file,
|
| 166 |
"resolved_path": str(path) if path else None,
|
| 167 |
"text_length": len(text) if text else 0,
|
| 168 |
"preview": text[:500] if text else None,
|
| 169 |
+
"direct_download_path": direct_download_path,
|
| 170 |
+
"direct_download_error": direct_download_error,
|
| 171 |
})
|
| 172 |
|
| 173 |
|