Spaces:
Sleeping
Sleeping
Upload visual2.py
#10
by SVanc - opened
- visual2.py +23 -18
visual2.py
CHANGED
|
@@ -298,52 +298,57 @@ def _(mo):
|
|
| 298 |
|
| 299 |
@app.cell
|
| 300 |
def _(Path, mo):
|
| 301 |
-
#
|
|
|
|
|
|
|
| 302 |
default_candidates = [
|
| 303 |
-
"/mnt/data
|
| 304 |
-
|
|
|
|
| 305 |
]
|
| 306 |
|
| 307 |
-
#
|
| 308 |
-
|
|
|
|
|
|
|
| 309 |
|
| 310 |
-
#
|
| 311 |
-
|
|
|
|
|
|
|
|
|
|
| 312 |
|
| 313 |
-
#
|
| 314 |
data_path = mo.ui.text(
|
| 315 |
-
value=default_file,
|
| 316 |
label="Excel dataset path",
|
| 317 |
-
full_width=True
|
| 318 |
)
|
| 319 |
|
| 320 |
-
# Voor (bijkomende) png output, check the box
|
| 321 |
export_png = mo.ui.checkbox(
|
| 322 |
value=False,
|
| 323 |
-
label="Also export PNG (optional; requires cairosvg)"
|
| 324 |
)
|
| 325 |
|
| 326 |
-
# box voor output stem
|
| 327 |
output_stem = mo.ui.text(
|
| 328 |
-
value=default_stem,
|
| 329 |
label="Output file stem",
|
| 330 |
-
full_width=True
|
| 331 |
)
|
| 332 |
|
| 333 |
-
# Display of input controls
|
| 334 |
mo.vstack(
|
| 335 |
[
|
| 336 |
mo.md(
|
| 337 |
'<div class="coffee-sites-notebook"><div class="card" style="padding: 1rem 1.1rem;">'
|
| 338 |
'<div class="section-title">Inputs</div>'
|
| 339 |
-
'<div class="helper">
|
| 340 |
'</div></div>'
|
| 341 |
),
|
| 342 |
data_path,
|
| 343 |
mo.hstack(
|
| 344 |
[export_png, output_stem],
|
| 345 |
justify="start",
|
| 346 |
-
gap=1.5
|
| 347 |
),
|
| 348 |
]
|
| 349 |
)
|
|
|
|
| 298 |
|
| 299 |
@app.cell
|
| 300 |
def _(Path, mo):
|
| 301 |
+
# ===== Input/output paths for Hugging Face Spaces =====
|
| 302 |
+
# Primary location requested for local runs in this environment.
|
| 303 |
+
DATA_FILENAME = "data_species_merged.xlsx"
|
| 304 |
default_candidates = [
|
| 305 |
+
Path("/mnt/data") / DATA_FILENAME,
|
| 306 |
+
Path.cwd() / DATA_FILENAME, # typical Hugging Face Space layout
|
| 307 |
+
Path(__file__).resolve().parent / DATA_FILENAME,
|
| 308 |
]
|
| 309 |
|
| 310 |
+
# Automatically use the first existing dataset path. If none exists, keep
|
| 311 |
+
# /mnt/data/data_species_merged.xlsx as the displayed default so the error
|
| 312 |
+
# message clearly shows the expected file location.
|
| 313 |
+
default_file = next((p for p in default_candidates if p.exists()), default_candidates[0])
|
| 314 |
|
| 315 |
+
# Write generated figures to a local outputs folder. This works both in
|
| 316 |
+
# /mnt/data and in Hugging Face Spaces.
|
| 317 |
+
output_dir = Path("outputs")
|
| 318 |
+
output_dir.mkdir(exist_ok=True)
|
| 319 |
+
default_stem = output_dir / "coffee_sites_visualisation_marimo"
|
| 320 |
|
| 321 |
+
# Keep the path visible but pre-filled automatically.
|
| 322 |
data_path = mo.ui.text(
|
| 323 |
+
value=str(default_file),
|
| 324 |
label="Excel dataset path",
|
| 325 |
+
full_width=True,
|
| 326 |
)
|
| 327 |
|
|
|
|
| 328 |
export_png = mo.ui.checkbox(
|
| 329 |
value=False,
|
| 330 |
+
label="Also export PNG (optional; requires cairosvg)",
|
| 331 |
)
|
| 332 |
|
|
|
|
| 333 |
output_stem = mo.ui.text(
|
| 334 |
+
value=str(default_stem),
|
| 335 |
label="Output file stem",
|
| 336 |
+
full_width=True,
|
| 337 |
)
|
| 338 |
|
|
|
|
| 339 |
mo.vstack(
|
| 340 |
[
|
| 341 |
mo.md(
|
| 342 |
'<div class="coffee-sites-notebook"><div class="card" style="padding: 1rem 1.1rem;">'
|
| 343 |
'<div class="section-title">Inputs</div>'
|
| 344 |
+
'<div class="helper">The notebook automatically looks for <code>data_species_merged.xlsx</code> in <code>/mnt/data</code>, the current working directory, and the app folder. For Hugging Face Spaces, place the Excel file next to this Python file or keep the shown path if you mount data there.</div>'
|
| 345 |
'</div></div>'
|
| 346 |
),
|
| 347 |
data_path,
|
| 348 |
mo.hstack(
|
| 349 |
[export_png, output_stem],
|
| 350 |
justify="start",
|
| 351 |
+
gap=1.5,
|
| 352 |
),
|
| 353 |
]
|
| 354 |
)
|