writing-skills
writing-skills
Use when creating new skills, editing existing skills, or verifying skills work before deployment
GradioBuild and deploy ML demo interfaces with proper state management, queuing, and production patterns.
Independent GitHub snapshot · Automated classification · Original documentation governs
gr.Interface is for single-function demos — use gr.Blocks for anything with multiple steps, conditional UI, or custom layout.click(), .change(), .submit() event handlers — Interface only has one functiongr.State() creates per-session state — it resets when the user refreshes the pagefn(state) -> state — forgetting the output loses updatesgr.State() for user-specific data.queue(), long-running functions block all other users — always call demo.queue() before .launch()concurrency_limit=1 on a function serializes calls — use for GPU-bound inference that can't parallelizemax_size in queue limits waiting users — without it, memory grows unbounded under loadyield enable streaming — but they hold a queue slot until completegr.File(type="binary") returns bytes, type="filepath" returns a string path — mismatching causes silent failuresgr.File(value="path/to/file") for downloads, not raw bytes — the component handles content-disposition headersmax_file_size in launch() to change itgr.Dropdown(value=None) with allow_custom_value=False crashes if the user submits nothing — set a default or make it optionalgr.Image(type="pil") returns a PIL Image, type="numpy" returns an array, type="filepath" returns a path — inconsistent inputs break functionsgr.Chatbot expects list of tuples [(user, bot), ...] — returning just strings doesn't rendervisible=False components still run their functions — use gr.update(interactive=False) to disable without hidingauth=("user", "pass") is plaintext in code — use auth=auth_function for production with proper credential checkingshare=True with auth still exposes auth to Gradio's servers — use your own tunnel for sensitive appsshare=True creates a 72-hour public URL through Gradio's servers — not for production, just demosserver_name="0.0.0.0" to accept external connections — default 127.0.0.1 only allows localhostroot_path="/subpath" or assets and API routes breakgr.update(value=x, visible=True) to modify component properties — returning just the value only changes value.then() for sequential operations — parallel .click() handlers raceevery=5 on a function polls every 5 seconds — but it holds connections open, scale carefullytrigger_mode="once" prevents double-clicks from firing twice — default allows rapid duplicate submissionscache_examples=True pre-computes example outputs at startup — speeds up demos but increases load timegr.State with initializationbatch=True with max_batch_size=N groups concurrent requests — essential for GPU throughput