Skip to content

Gradio Docstring Standard

Ömer Faruk Özdemir edited this page Aug 8, 2022 · 1 revision

As part of the documentation sprint, we just enforced all of the classes that need to be documented to follow this docstring format:

"""
Class method that constructs an Interface from a Hugging Face repo. Can accept
model repos (if src is "models") or Space repos (if src is "spaces"). The input
and output components are automatically loaded from the repo.
Parameters:
    name: the name of the model (e.g. "gpt2"), can include the `src` as prefix (e.g. "models/gpt2")
    src: the source of the model: `models` or `spaces` (or empty if source is provided as a prefix in `name`)
    api_key: optional api key for use with Hugging Face Hub
    alias: optional string used as the name of the loaded model instead of the default name
Returns:
    a Gradio Interface object for the given model
Example:
    import gradio as gr
    description = "Story generation with GPT"
    examples = [["An adventurer is approached by a mysterious stranger in the tavern for a new quest."]]
    demo = gr.Interface.load("models/EleutherAI/gpt-neo-1.3B", description=description, examples=examples)
    demo.launch()
"""

Originally from: https://github.com/gradio-app/gradio/issues/1913#issuecomment-1205750292