Skip to content

Add HuggingFace token warning and authentication docs#1323

Merged
henrykironde merged 2 commits intoweecology:mainfrom
vickysharma-prog:add-hf-token-docs
Mar 9, 2026
Merged

Add HuggingFace token warning and authentication docs#1323
henrykironde merged 2 commits intoweecology:mainfrom
vickysharma-prog:add-hf-token-docs

Conversation

@vickysharma-prog
Copy link
Copy Markdown
Contributor

@vickysharma-prog vickysharma-prog commented Feb 25, 2026

Description

Adds HuggingFace token authentication docs and a runtime warning for missing tokens.

Changes

Documentation (docs/getting_started/install.md):

  • Added "HuggingFace Authentication (Optional)" section
  • Setup instructions for Linux/macOS, Windows (CMD & PowerShell), and Python

Runtime Warning (src/deepforest/main.py):

  • Added _warn_if_no_hf_token() helper
  • Warning triggered once per process in load_model() when no token is found
  • Points users to documentation for setup instructions

Tests (tests/test_main.py):

  • No token present → warning emitted
  • Token present → no warning
  • Warning emitted only once per process

Related Issue(s)

Fixes #1322

AI-Assisted Development

  • I used AI tools (e.g., GitHub Copilot, ChatGPT, etc.) in developing this PR
  • I understand all the code I'm submitting
  • I have reviewed and validated all AI-generated code

AI tools used (if applicable):
None – written manually following existing codebase patterns.

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.97%. Comparing base (7036fa9) to head (3a123da).
⚠️ Report is 21 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1323   +/-   ##
=======================================
  Coverage   86.97%   86.97%           
=======================================
  Files          24       24           
  Lines        3009     3009           
=======================================
  Hits         2617     2617           
  Misses        392      392           
Flag Coverage Δ
unittests 86.97% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@musaqlain
Copy link
Copy Markdown
Contributor

musaqlain commented Feb 25, 2026

Hi, thanks for working on this!
As the original issue #1322 suggested, we should probably also implement a meaningful runtime warning message. If users miss this documentation section, they will still encounter unhandled huggingface_hub stack traces when hitting the rate limit during model initialization.
To handle this gracefully, we could add a quick check using Python's built-in warnings module.
What do you think about it? 👀

@henrykironde
Copy link
Copy Markdown
Contributor

Thanks @vickysharma-prog for the contribution and @musaqlain for the suggestions.

@vickysharma-prog
Copy link
Copy Markdown
Contributor Author

vickysharma-prog commented Feb 25, 2026

@henrykironde I noticed #1325 also covers the warning implementation. I'm adding the runtime warning and tests to this PR as well to keep everything in one place.

@vickysharma-prog
Copy link
Copy Markdown
Contributor Author

vickysharma-prog commented Feb 25, 2026

@henrykironde Added a runtime warning for a missing HuggingFace token, along with tests.

The warning is emitted once per process when no token is found and points users to the documentation for setup instructions.

Changes in this update:

  • Added _warn_if_no_hf_token() helper in main.py
  • Triggered the warning in load_model()
  • Added tests covering: no token present, token present, and once-only warning behavior

Squashed into a single commit for a clean history. Happy to address any feedback!

@vickysharma-prog vickysharma-prog changed the title docs: add HuggingFace token authentication guide Add HuggingFace token warning and authentication docs Feb 25, 2026
Comment thread docs/getting_started/install.md Outdated
$env:HF_TOKEN="your_token_here"
```

**Python:**
Copy link
Copy Markdown
Contributor

@henrykironde henrykironde Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Python version part can be dropped.

Comment thread docs/getting_started/install.md Outdated

When downloading models from HuggingFace Hub, you may see a warning about unauthenticated requests. Setting a HuggingFace token provides higher rate limits and faster downloads.

### Get Your Token
Copy link
Copy Markdown
Contributor

@henrykironde henrykironde Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove the detailed token setup instructions and instead direct users to the Hugging Face documentation. There’s no need to include multiple lines for such a simple setup and clarification.

For more details, see the Hugging Face token documentation.

Copy link
Copy Markdown
Contributor

@henrykironde henrykironde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @vickysharma-prog — I’ve reviewed Copilot’s PR as well.

I agree that we should keep the documentation in docs/getting_started/install.md as you’ve done. However, we need to simplify it. I’d suggest borrowing from Copilot’s more streamlined approach and combining that with your steps to create a cleaner, simpler version in this file. We can place it just above the GPU instructions.

As for the additional file/code changes to catch exceptions and raise warnings, I think that’s overkill. We should drop that.

@henrykironde
Copy link
Copy Markdown
Contributor

This PR closes #1325

@vickysharma-prog
Copy link
Copy Markdown
Contributor Author

Thanks @henrykironde for the review!
I'll simplify the documentation to link to the HuggingFace token docs and remove the warning code and tests. Will push the update shortly.

@vickysharma-prog
Copy link
Copy Markdown
Contributor Author

@henrykironde Updated simplified the docs and removed the warning code/tests as suggested. Ready for re-review!

@vickysharma-prog
Copy link
Copy Markdown
Contributor Author

Hi @henrykironde, just a gentle follow-up I've simplified the docs and removed the warning code as you suggested. Let me know if anything else is needed!

Copy link
Copy Markdown
Contributor

@henrykironde henrykironde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @vickysharma-prog

@henrykironde henrykironde merged commit 716c934 into weecology:main Mar 9, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unauthenticated HuggingFace Hub requests

3 participants