Spaces:
Runtime error
Runtime error
Require HF sign-in, add per-user limits and a proprietary-data disclaimer
#4
by shyamr982 - opened
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 withgr.Errorunless a user is signed in (UI and/generate_cifAPI), checks quota, and releases the slot infinally. The refusal message gives the sign-in URL and repeats the disclaimer (DISCLAIMERconstant, 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, butasyncio.to_threadcopies the context into the worker thread, so no Studio change is needed. This relies on Gradio internals, so keepsdk_version: 6.29.1pinned.enable_oauth()adds Gradio's/login/huggingface,/login/callbackand/logoutroutes 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_clientwith 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,
/designmount path). The tests faked the session. - That
authlib/itsdangerousresolve with the pinned stack on the Space build. - Not run on GPU hardware.
shyamr982 changed pull request status to closed