MFLUX-WEBUI icon indicating copy to clipboard operation
MFLUX-WEBUI copied to clipboard

Fix Hugging Face authentication issue

Open rovo79 opened this issue 9 months ago • 1 comments

Fix Hugging Face authentication issue

Issue Fixed

Fixed the error 'HfApi' object has no attribute 'set_access_token' which occurred when trying to authenticate with Hugging Face API. This error appeared because the code was using an outdated or incorrect authentication method.

Solution

Updated the login_huggingface function to use the official login() method from the huggingface_hub library instead of trying to directly set an access token on the API object. This approach:

  1. Uses the officially supported authentication flow
  2. Properly validates the token via the HF API
  3. Correctly stores credentials for future use
  4. Adds git credentials if requested

Implementation Details

  • Imported the login function directly from huggingface_hub
  • Used this function to handle token validation and storage
  • Added proper error handling to provide meaningful feedback to users
  • Set add_to_git_credential=True to ensure git operations work correctly with protected repositories

Note: My IDE auto-formatted portions of the file. The functional change is limited to the login_huggingface function. The other differences are purely formatting changes that don't affect functionality.

rovo79 avatar Mar 07 '25 15:03 rovo79

#14 these commits fix that error

rovo79 avatar Mar 07 '25 19:03 rovo79