"""GPU-allowance line for the ZeroGPU Spaces in this folder. Canonical copy: shared-ui/gpu_note.py. Edit it there, then run `python shared-ui/sync.py` to copy it into each project. ZeroGPU charges GPU time to the visitor's own daily allowance when they open the Space on huggingface.co while signed in there: the Space page passes their identity to the embedded app. Everyone else uses a short guest allowance. The apps need no sign-in of their own, so the intro page explains this instead. """ import html import gradio as gr EMBEDDED = ("No account needed. {action} uses a little GPU time from a short daily guest allowance; " "if you’re signed in to huggingface.co, your account’s larger allowance is used instead.") DIRECT = ("No account needed. Here GPU time uses the short daily guest allowance; " "{link} to use your account’s allowance.") # Show the Space-page wording inside the huggingface.co frame, the own-address wording otherwise. SHOW_FOR_CONTEXT = """() => { const direct = window.self === window.top; document.querySelectorAll('.gpu-note-embedded').forEach(el => { el.hidden = direct; }); document.querySelectorAll('.gpu-note-direct').forEach(el => { el.hidden = !direct; }); }""" def gpu_note(demo, action, name, space_id): """Add the line inside `demo`'s Blocks; `action` is e.g. "Each reply", `space_id` e.g. "owner/name".""" url = f"https://huggingface.co/spaces/{space_id}" link = f'open {html.escape(name)} on Hugging Face' note = gr.HTML( f'
' f'{DIRECT.format(link=link)}
', padding=False, elem_classes=["gpu-note"]) demo.load(None, None, None, js=SHOW_FOR_CONTEXT) return note