Add examples for series and parallel (#1738)

* Add examples for series and parallel

* Add ML demos for interface and load
This commit is contained in:
Freddy Boulton 2022-07-11 11:21:30 -04:00 committed by GitHub
parent 2a67fe6ec9
commit 600722c218
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 44 additions and 2 deletions

View File

@ -0,0 +1,8 @@
import gradio as gr
greeter_1 = gr.Interface(lambda name: f"Hello {name}!", inputs="textbox", outputs=gr.Textbox(label="Greeter 1"))
greeter_2 = gr.Interface(lambda name: f"Greetings {name}!", inputs="textbox", outputs=gr.Textbox(label="Greeter 2"))
demo = gr.Parallel(greeter_1, greeter_2)
if __name__ == "__main__":
demo.launch()

View File

@ -0,0 +1,10 @@
import gradio as gr
generator1 = gr.Interface.load("huggingface/gpt2")
generator2 = gr.Interface.load("huggingface/EleutherAI/gpt-neo-2.7B")
generator3 = gr.Interface.load("huggingface/EleutherAI/gpt-j-6B")
demo = gr.Parallel(generator1, generator2, generator3)
if __name__ == "__main__":
demo.launch()

View File

@ -0,0 +1,10 @@
import gradio as gr
get_name = gr.Interface(lambda name: name, inputs="textbox", outputs="textbox")
prepend_hello = gr.Interface(lambda name: f"Hello {name}!", inputs="textbox", outputs="textbox")
append_nice = gr.Interface(lambda greeting: f"{greeting} Nice to meet you!",
inputs="textbox", outputs=gr.Textbox(label="Greeting"))
demo = gr.Series(get_name, prepend_hello, append_nice)
if __name__ == "__main__":
demo.launch()

View File

@ -0,0 +1,9 @@
import gradio as gr
generator = gr.Interface.load("huggingface/gpt2")
translator = gr.Interface.load("huggingface/t5-small")
demo = gr.Series(generator, translator)
if __name__ == "__main__":
demo.launch()

View File

@ -17,6 +17,8 @@ class Parallel(gradio.Interface):
"""
Creates a new Interface consisting of multiple models in parallel (comparing their outputs).
The Interfaces to put in Parallel must share the same input components (but can have different output components).
Demos: interface_parallel, interface_parallel_load
"""
def __init__(self, *interfaces: gradio.Interface, **options):
@ -57,6 +59,8 @@ class Series(gradio.Interface):
"""
Creates a new Interface from multiple models in series (the output of one is fed as the input to the next,
and so the input and output components must agree between the interfaces).
Demos: interface_series, interface_series_load
"""
def __init__(self, *interfaces: gradio.Interface, **options):

View File

@ -1,6 +1,7 @@
# Advanced Interface Features
Pinned: 1
Docs: series, parallel
**Prerequisite**: This Guide builds on the Quickstart. Make sure to [read the Quickstart first](/getting_started).

View File

@ -49,10 +49,10 @@
{% with obj=find_cls("TabbedInterface"), parent="gradio" %}
{% include "docs/obj_doc_template.html" %}
{% endwith %}
{% with obj=find_cls("Parallel"), parent="gradio" %}
{% with obj=find_cls("Parallel"), is_class=True, parent="gradio" %}
{% include "docs/obj_doc_template.html" %}
{% endwith %}
{% with obj=find_cls("Series"), parent="gradio" %}
{% with obj=find_cls("Series"), is_class=True, parent="gradio" %}
{% include "docs/obj_doc_template.html" %}
{% endwith %}
</div>