mirror of
https://github.com/gradio-app/gradio.git
synced 2025-02-17 11:29:58 +08:00
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:
parent
2a67fe6ec9
commit
600722c218
8
demo/interface_parallel/run.py
Normal file
8
demo/interface_parallel/run.py
Normal 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()
|
10
demo/interface_parallel_load/run.py
Normal file
10
demo/interface_parallel_load/run.py
Normal 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()
|
10
demo/interface_series/run.py
Normal file
10
demo/interface_series/run.py
Normal 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()
|
9
demo/interface_series_load/run.py
Normal file
9
demo/interface_series_load/run.py
Normal 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()
|
@ -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):
|
||||
|
@ -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).
|
||||
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user