Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions gradio/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,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):
Expand Down Expand Up @@ -739,7 +744,8 @@ def launch(
) -> 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.
Expand Down Expand Up @@ -771,7 +777,7 @@ def launch(
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 (
Expand Down
13 changes: 9 additions & 4 deletions gradio/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,20 @@
@document("launch", "load", "from_pipeline")
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
"""

Expand Down
1 change: 1 addition & 0 deletions scripts/launch_website.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion website/homepage/src/docs/obj_doc_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -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" %}<!--
Comment thread
abidlabs marked this conversation as resolved.
-->{{ param["name"] }}, <!--
-->{% endif %}<!--
-->{% endfor %}<!--
Expand Down
6 changes: 3 additions & 3 deletions website/homepage/src/docs/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ <h3 class="text-3xl font-light my-4" id="combining-interfaces">Combining Interfa
</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" %}
Expand All @@ -78,7 +76,9 @@ <h3 class="text-3xl font-light my-4" id="block-layouts">Block Layouts</h3>
</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
Comment thread
abidlabs marked this conversation as resolved.
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" %}
Expand Down