Spaces:
Runtime error

Require HF sign-in, add per-user limits and a proprietary-data disclaimer

#4
NVIDIA org
•
edited Oct 18

Per-user rate limits, HF sign-in, and a proprietary-data disclaimer. No user data is logged or stored. This replaces #1 and #2 after the decision in the Slack thread to defer data collection; it is based directly on main. No change to atomworks-studio.

Changes

  • README.md: hf_oauth: true, hf_oauth_expiration_minutes: 480, and a notice not to submit proprietary, confidential or third-party-owned structures.
  • space.py:
    • generate() refuses with gr.Error unless a user is signed in (UI and /generate_cif API), checks quota, and releases the slot in finally. The refusal message gives the sign-in URL and repeats the disclaimer (DISCLAIMER constant, placeholder wording, easy to edit).
    • signed_in_username() reads the login from Gradio's per-event request context. Studio's handlers don't pass the user, but asyncio.to_thread copies the context into the worker thread, so no Studio change is needed. This relies on Gradio internals, so keep sdk_version: 6.29.1 pinned.
    • enable_oauth() adds Gradio's /login/huggingface, /login/callback and /logout routes ahead of Studio's catch-all mount at /.
  • New limits.py: 1 active generation per user and 10 per rolling hour (module constants). Thread-safe, in memory, per replica by design. Usernames are held only in memory for counting.
  • requirements.txt: authlib, itsdangerous (needed by Gradio's OAuth).

Behaviour to know about

  • Users sign in at https://<space-host>/login/huggingface. There is no Login button in the UI because Studio owns the page.
  • The CIF API example in the README (gradio_client with an HF token) will be refused, since it carries a token rather than a browser session.
  • A failed generation still counts toward the hourly cap.
  • The disclaimer is in the README and in the sign-in message only; there is no banner in the UI (that needs a hook in Studio).
  • Counters are per replica; someone switching networks gets a fresh budget.

Tested (locally, with torch/hydra/Studio stubbed, in a stand-in app shaped like Studio's)
Anonymous refused; signed-in user succeeds; expired session refused; slot released after an inference error; 11th request in an hour refused with a retry time; OAuth route reachable despite the catch-all; no logging code present. limits.py: 50 racing threads yield exactly one winner.

Not tested: needs a throwaway Space first

  • Real HF OAuth end to end (redirect, callback, cookie inside the huggingface.co iframe, /design mount path). The tests faked the session.
  • That authlib/itsdangerous resolve with the pinned stack on the Space build.
  • Not run on GPU hardware.
NVIDIA org

Closing: all of this (sign-in, per-user limits, disclaimer) is already on main via #1/#2 as merged by Kieran, so this draft is redundant.

shyamr982 changed pull request status to closed

Sign up or log in to comment