Spaces:
Running on Zero
Running on Zero
Build prompt-free diffusion drawing canvas
Browse filesFiles changed (3)
- README.md+6-7
- app.py+3-59
- hf_login.pyAdded+34
56 unmodified lines5758596061626364656667686956 unmodified lineschecks deployed streaming, 13 cycles, resume, exports, and privacy.`deploy_space.py` enforces private visibility and uploads an explicit allowlist.The visible sign-in control is a normal same-tab, top-level link to Gradio'sstandard OAuth route, retaining browser user activation when leaving the iframe.A hidden stock LoginButton registers those routes. A status bar responds locallyon click, shows indeterminate activity, and offers a retry after six seconds ifthe current page has not navigated. This is not a percentage of OAuth completion.After return, actual OAuth session state selects the signed-in confirmation baror the sign-in controls. Only basic profile identity is requested.ZeroGPU quota is attributed by Hugging Face to the authenticated visitor, not ashared owner API key. Sign-in does not override private Space access restrictions.The Space does not use your computer's GPU.56 unmodified lines57585960616263646566676856 unmodified lineschecks deployed streaming, 13 cycles, resume, exports, and privacy.`deploy_space.py` enforces private visibility and uploads an explicit allowlist.Sign-in uses the same TopLevelLoginButton component as Let It Flow, with onevisible button and Gradio's built-in session-status handling. The only navigationchange is `_top` instead of `_blank`, preserving this app's same-tab preference.It uses the canonical hf.space hostname for both login and logout. There is nosecond sign-in control, hidden registration button, progress panel, or fallbacklink. Only basic profile identity is requested.ZeroGPU quota is attributed by Hugging Face to the authenticated visitor, not ashared owner API key. Sign-in does not override private Space access restrictions.The Space does not use your computer's GPU.
8 unmodified lines91011121314151617181920212223242526272829303132333435363738394041424344343 unmodified lines38838939039139239339439539639739839940040140240340440520 unmodified lines42642742842943043143243343443543643743843944044144244344444544632 unmodified lines4794804814824834844854864874884894904918 unmodified linesfrom PIL import ImageChops, ImageStatimport gradio as grimport torchfrom diffusers import StableDiffusionPipeline, StableDiffusionImg2ImgPipelinefrom diffusers import StableDiffusionXLPipeline, StableDiffusionXLImg2ImgPipelinefrom diffusers.utils.torch_utils import randn_tensorLOGIN_FEEDBACK_JS = """const link = element.querySelector('[data-sign-in]');const feedback = element.querySelector('[data-auth-feedback]');const text = element.querySelector('[data-auth-message]');link.addEventListener('click', (event) => {if (link.dataset.pending === 'true') { event.preventDefault(); return; }link.dataset.pending = 'true';link.setAttribute('aria-disabled', 'true');feedback.classList.add('is-busy');feedback.setAttribute('aria-busy', 'true');text.textContent = 'Opening Hugging Face sign-in...';setTimeout(() => {feedback.classList.remove('is-busy');feedback.setAttribute('aria-busy', 'false');link.dataset.pending = 'false';link.removeAttribute('aria-disabled');text.textContent = 'Sign-in has not completed here. Try again, or use Open the app directly below.';}, 6000);});"""def account_controls(profile: gr.OAuthProfile | None):signed_in = profile is not Nonereturn gr.update(visible=not signed_in), gr.update(visible=signed_in)class CaptureStart:343 unmodified lines#welcome {width:calc(100% - 24px) !important;box-sizing:border-box}#experience {width:100% !important;max-width:100% !important}.auth-panel {display:grid;gap:12px}.auth-login {display:block;padding:14px 20px;border-radius:10px;background:#f4bf67;color:#17242b !important;text-decoration:none !important;text-align:center;font:600 16px/1.4 system-ui,sans-serif}#welcome .auth-login {color:#17242b !important}.auth-login:hover {background:#e7aa45}.auth-login:focus-visible {outline:3px solid #f4bf67;outline-offset:3px}.auth-feedback {padding:12px 14px;border:1px solid #577f89;border-radius:10px;background:#112530;color:#d5e3e6;font:13px/1.6 system-ui,sans-serif}.auth-track {height:5px;margin-top:10px;border-radius:6px;background:#29434e;overflow:hidden}.auth-indicator {width:0;height:100%;background:#f4bf67;border-radius:6px}.is-busy .auth-indicator {width:35%;animation:auth-progress 1.3s ease-in-out infinite}.is-signed-in .auth-indicator {width:100%;background:#86b6b3}@keyframes auth-progress {0% {transform:translateX(-100%)}100% {transform:translateX(390%)}}@media(prefers-reduced-motion:reduce){.is-busy .auth-indicator {width:100%;animation:none}}"""# Set both palettes so browser light/dark preferences cannot invert only part of the UI.20 unmodified linestimer = gr.Timer(.5, active=False)with gr.Column(visible=True, elem_id="welcome") as welcome:gr.HTML('<header><div class="eyebrow">AN EXPERIMENT IN AUTOMATIC DRAWING</div><h1>Automatic Drawing<span class="title-stop">.</span></h1><p>Inspired by automatic drawing, this experiment lets an image unfold without a written prompt. Begin with noise, watch forms emerge, then see the image become the starting point for something new.</p></header>')# Retain Gradio's OAuth route registration without its scripted navigation.with gr.Column(visible="hidden"):gr.LoginButton()with gr.Column(elem_id="sign-in-controls") as sign_in_controls:gr.HTML('''<div class="auth-panel"><a class="auth-login" data-sign-in href="https://jejunepixels-automatic-drawing.hf.space/login/huggingface?_target_url=/%3Fauth_return%3D1" target="_top">Sign in with Hugging Face</a><div class="auth-feedback" data-auth-feedback role="status" aria-live="polite" aria-busy="false"><span data-auth-message>Not signed in. Ready to connect your Hugging Face account.</span><div class="auth-track" aria-hidden="true"><div class="auth-indicator"></div></div></div></div>''', js_on_load=LOGIN_FEEDBACK_JS, elem_id="login-feedback")with gr.Column(visible=False, elem_id="sign-out-controls") as sign_out_controls:gr.HTML('<div class="auth-feedback is-signed-in" role="status" aria-live="polite">Signed in. Your Hugging Face account is connected.<div class="auth-track" aria-hidden="true"><div class="auth-indicator"></div></div></div>')sign_out = gr.Button("Log out of drawing", elem_id="sign-out")gr.HTML('<a href="https://jejunepixels-automatic-drawing.hf.space/" target="_top" style="color:#f4bf67;text-decoration:underline">Open the app directly in this tab</a>')gr.Markdown("Sign in continues in this tab. Your personal ZeroGPU quota applies. This Space remains private.")model = gr.Dropdown(choices=[("SD-Turbo - faster", "stabilityai/sd-turbo"),("SDXL-Turbo - larger model", "stabilityai/sdxl-turbo")],value="stabilityai/sd-turbo", label="Choose your model")32 unmodified linesapi_start.click(start_session, [state], [timer, status], queue=False, api_name="start").then(playback_button, [state], [playback], queue=False, api_name=False)api_pause.click(pause_session, [state], [timer, status], queue=False, api_name="pause").then(playback_button, [state], [playback], queue=False, api_name=False)outputs = [canvas, gallery, status]demo.load(account_controls, inputs=None, outputs=[sign_in_controls, sign_out_controls],queue=False, api_name=False)sign_out.click(fn=None, inputs=None, outputs=None, js="""() => {const destination = new URL('/logout', window.location.origin);destination.searchParams.set('_target_url', '/?signed_out=' + Date.now());window.location.replace(destination.href);}""", queue=False, api_name=False)begin.click(enter_canvas, [state, model],[welcome, experience, canvas, gallery, status, timer, png, gif],concurrency_limit=1, concurrency_id="drawing", api_name="begin").then(playback_button, [state], [playback], queue=False, api_name=False)8 unmodified lines91011121314151617181920343 unmodified lines36436536636736836920 unmodified lines39039139239339439539639732 unmodified lines4304314324334344358 unmodified linesfrom PIL import ImageChops, ImageStatimport gradio as grfrom hf_login import TopLevelLoginButtonimport torchfrom diffusers import StableDiffusionPipeline, StableDiffusionImg2ImgPipelinefrom diffusers import StableDiffusionXLPipeline, StableDiffusionXLImg2ImgPipelinefrom diffusers.utils.torch_utils import randn_tensorclass CaptureStart:343 unmodified lines#welcome {width:calc(100% - 24px) !important;box-sizing:border-box}#experience {width:100% !important;max-width:100% !important}"""# Set both palettes so browser light/dark preferences cannot invert only part of the UI.20 unmodified linestimer = gr.Timer(.5, active=False)with gr.Column(visible=True, elem_id="welcome") as welcome:gr.HTML('<header><div class="eyebrow">AN EXPERIMENT IN AUTOMATIC DRAWING</div><h1>Automatic Drawing<span class="title-stop">.</span></h1><p>Inspired by automatic drawing, this experiment lets an image unfold without a written prompt. Begin with noise, watch forms emerge, then see the image become the starting point for something new.</p></header>')TopLevelLoginButton(elem_id="hf-login")gr.Markdown("Sign in to use your Hugging Face GPU quota.")model = gr.Dropdown(choices=[("SD-Turbo - faster", "stabilityai/sd-turbo"),("SDXL-Turbo - larger model", "stabilityai/sdxl-turbo")],value="stabilityai/sd-turbo", label="Choose your model")32 unmodified linesapi_start.click(start_session, [state], [timer, status], queue=False, api_name="start").then(playback_button, [state], [playback], queue=False, api_name=False)api_pause.click(pause_session, [state], [timer, status], queue=False, api_name="pause").then(playback_button, [state], [playback], queue=False, api_name=False)outputs = [canvas, gallery, status]begin.click(enter_canvas, [state, model],[welcome, experience, canvas, gallery, status, timer, png, gif],concurrency_limit=1, concurrency_id="drawing", api_name="begin").then(playback_button, [state], [playback], queue=False, api_name=False)
12345678910111213141516171819202122232425262728293031323334"""Let It Flow's login component, using the current tab for this Space."""import jsonimport osimport reimport gradio as gr
def canonical_space_origin(): host = os.environ.get("SPACE_HOST", "jejunepixels-automatic-drawing.hf.space").split(",", 1)[0].strip().lower() if not re.fullmatch(r"[a-z0-9][a-z0-9-]*\.hf\.space", host): raise ValueError("Expected the canonical hf.space hostname for OAuth.") return "https://" + host
def login_redirect_js(default_value): return """(buttonValue) => { const origin = ORIGIN; const route = buttonValue === DEFAULT ? '/login/huggingface' : '/logout'; const url = new URL(route, origin); url.searchParams.set('_target_url', '/'); window.open(url.href, '_top'); }""".replace("ORIGIN", json.dumps(canonical_space_origin())).replace("DEFAULT", json.dumps(default_value))
class TopLevelLoginButton(gr.LoginButton): def get_block_name(self): return "button"
def get_block_class(self): return "button"
def activate(self): self.click(fn=None, inputs=[self], outputs=None, js=login_redirect_js(self.value)) self.attach_load_event(self._check_login_status, None)README.md+6-7
app.py+3-59
hf_login.pyAdded+34