Files changed (1) hide show
  1. visual2.py +23 -18
visual2.py CHANGED
@@ -298,52 +298,57 @@ def _(mo):
298
 
299
  @app.cell
300
  def _(Path, mo):
301
- # Possible default locations where the Excel file might exist
 
 
302
  default_candidates = [
303
- "/mnt/data/merged_species_dataset.xlsx", # uploaded dataset
304
- "/__modal/volumes/vo-qWmx7cdqVT9K9vk42U6q5b/merged_species_dataset.xlsx", # voor Molab, maar exacte link aan te passen
 
305
  ]
306
 
307
- # Code neemt het eerste bestaande path, en als hij er geen vindt, dan neemt hij het eerst path als default
308
- default_file = next((p for p in default_candidates if Path(p).exists()), default_candidates[0])
 
 
309
 
310
- # naam voor de stem van de output, zonder de extensie
311
- default_stem = "/__modal/volumes/vo-qWmx7cdqVT9K9vk42U6q5b/coffee_sites_visualisation_marimo_v3"
 
 
 
312
 
313
- # Input box for excel path
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">These controls stay simple so the notebook reruns cleanly. The visual itself is fully data-driven.</div>'
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
  )