mirror of
https://github.com/gradio-app/gradio.git
synced 2024-11-21 01:01:05 +08:00
Some cleanups to the docs page (#1822)
* break execution if website isn't properly built * small misc changes * formatting
This commit is contained in:
parent
4a1879edaf
commit
31ba09aafa
@ -233,16 +233,21 @@ def skip() -> dict:
|
||||
@document()
|
||||
class Blocks(BlockContext):
|
||||
"""
|
||||
The Blocks class is a low-level API that allows you to create custom web
|
||||
applications entirely in Python. Compared to the Interface class, Blocks offers
|
||||
more flexibility and control over: (1) the layout of components (2) the events that
|
||||
Blocks is Gradio's low-level API that allows you to create more custom web
|
||||
applications and demos than Interfaces (yet still entirely in Python).
|
||||
|
||||
|
||||
Compared to the Interface class, Blocks offers more flexibility and control over:
|
||||
(1) the layout of components (2) the events that
|
||||
trigger the execution of functions (3) data flows (e.g. inputs can trigger outputs,
|
||||
which can trigger the next level of outputs). Blocks also offers ways to group
|
||||
together related demos e.g. using tabs.
|
||||
together related demos such as with tabs.
|
||||
|
||||
|
||||
The basic usage of Blocks is as follows: create a Blocks object, then use it as a
|
||||
context (with the "with" statement), and then define layouts, components, or events
|
||||
within the Blocks context. Finally, call the launch() method to launch the demo.
|
||||
|
||||
Example:
|
||||
import gradio as gr
|
||||
def update(name):
|
||||
@ -749,7 +754,8 @@ class Blocks(BlockContext):
|
||||
) -> Tuple[FastAPI, str, str]:
|
||||
"""
|
||||
Launches a simple web server that serves the demo. Can also be used to create a
|
||||
shareable link.
|
||||
public link used by anyone to access the demo from their browser by setting share=True.
|
||||
|
||||
Parameters:
|
||||
inline: whether to display in the interface inline in an iframe. Defaults to True in python notebooks; False otherwise.
|
||||
inbrowser: whether to automatically launch the interface in a new tab on the default browser.
|
||||
@ -781,7 +787,7 @@ class Blocks(BlockContext):
|
||||
def reverse(text):
|
||||
return text[::-1]
|
||||
demo = gr.Interface(reverse, "text", "text")
|
||||
demo.launch(share=True)
|
||||
demo.launch(share=True, auth=("username", "password"))
|
||||
"""
|
||||
self.dev_mode = False
|
||||
if (
|
||||
|
@ -45,15 +45,20 @@ if TYPE_CHECKING: # Only import for type checking (is False at runtime).
|
||||
@document("launch", "load", "from_pipeline", "integrate")
|
||||
class Interface(Blocks):
|
||||
"""
|
||||
The Interface class is a high-level abstraction that allows you to create a
|
||||
web-based demo around a machine learning model or arbitrary Python function
|
||||
by specifying: (1) the function (2) the desired input components and (3) desired output components.
|
||||
The Interface class is Gradio's main high-level abstraction, and allows you to create a
|
||||
web-based GUI / demo around a machine learning model (or any Python function). You must specify
|
||||
three parameters: (1) the function to create a GUI for (2) the desired input components and
|
||||
(3) the desired output components. Further parameters can be specified to control the appearance
|
||||
and behavior of the demo.
|
||||
|
||||
Example:
|
||||
import gradio as gr
|
||||
|
||||
def image_classifier(inp):
|
||||
return {'cat': 0.3, 'dog': 0.7}
|
||||
|
||||
demo = gr.Interface(fn=image_classifier, inputs="image", outputs="label")
|
||||
demo.launch(share=True)
|
||||
demo.launch()
|
||||
Demos: hello_world, hello_world_3, gpt_j
|
||||
"""
|
||||
|
||||
|
@ -4,6 +4,7 @@ if [ -z "$(ls | grep CONTRIBUTING.md)" ]; then
|
||||
exit -1
|
||||
else
|
||||
echo "Building the website"
|
||||
set -e
|
||||
cd website/homepage
|
||||
npm install
|
||||
npm run build
|
||||
|
@ -38,7 +38,7 @@
|
||||
{% else %}
|
||||
<div class="codeblock"><pre><code class="lang-python">{{ parent }}.<span>{{ obj["name"] }}(</span><!--
|
||||
-->{% for param in obj["parameters"] %}<!--
|
||||
-->{% if "positional" in param["kind"] and "default" not in param %}<!--
|
||||
-->{% if "positional" in param["kind"] and "default" not in param and param["name"] != "self" %}<!--
|
||||
-->{{ param["name"] }}, <!--
|
||||
-->{% endif %}<!--
|
||||
-->{% endfor %}<!--
|
||||
|
@ -59,8 +59,6 @@
|
||||
</div>
|
||||
</section>
|
||||
<section id="blocks" class="pt-2 mb-8">
|
||||
<h3 class="text-3xl font-light my-4" id="building-with-blocks">Building with Blocks</h3>
|
||||
<p class="mt-8 mb-12 text-lg">Want to build more customizable UIs? Take a look at how to build with Blocks.</p>
|
||||
<div class="flex flex-col gap-10">
|
||||
{% with obj=find_cls("Blocks"), parent="gradio" %}
|
||||
{% include "docs/obj_doc_template.html" %}
|
||||
@ -78,7 +76,9 @@
|
||||
</section>
|
||||
<section id="blocks-utils" class="pt-2 flex flex-col gap-10">
|
||||
<h3 class="text-3xl font-light my-4" id="blocks-utils-header">Blocks Utilities</h3>
|
||||
<p class="mb-12">Customize the behavior of blocks with these utilities</p>
|
||||
<p class="mb-12">Within Gradio Blocks, various functions exist to make it easier
|
||||
to define events and data flows.
|
||||
</p>
|
||||
<div class="flex flex-col gap-10">
|
||||
{% with obj=find_cls("update"), parent="gradio" %}
|
||||
{% include "docs/obj_doc_template.html" %}
|
||||
|
Loading…
Reference in New Issue
Block a user