gradio/demo/kitchen_sink/run.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

161 lines
6.0 KiB
Python
Raw Normal View History

import os
2022-01-04 01:46:07 +08:00
import json
import numpy as np
import gradio as gr
CHOICES = ["foo", "bar", "baz"]
2022-01-04 01:46:07 +08:00
JSONOBJ = """{"items":{"item":[{"id": "0001","type": null,"is_good": false,"ppu": 0.55,"batters":{"batter":[{ "id": "1001", "type": "Regular" },{ "id": "1002", "type": "Chocolate" },{ "id": "1003", "type": "Blueberry" },{ "id": "1004", "type": "Devil's Food" }]},"topping":[{ "id": "5001", "type": "None" },{ "id": "5002", "type": "Glazed" },{ "id": "5005", "type": "Sugar" },{ "id": "5007", "type": "Powdered Sugar" },{ "id": "5006", "type": "Chocolate with Sprinkles" },{ "id": "5003", "type": "Chocolate" },{ "id": "5004", "type": "Maple" }]}]}}"""
def fn(
text1,
text2,
num,
slider1,
slider2,
single_checkbox,
checkboxes,
radio,
dropdown,
Dropdown Component Updates (#3211) * dropdown * more dropdown updates * dropdown styling + option visibility * changelog * notebook * fix test * Allow more image formats (#3225) * add wildcard to image input * simplify mime types * changelog * regen noteboks --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co> Co-authored-by: pngwn <hello@pngwn.io> * fix webcam mirroring (#3245) * fix webcam * changelog * fix changelog * fix changelog * fix changelog --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Add `interactive=False` mode to `gr.Button` (#3266) * add interactive=False to button * add interactive=True by default * changelog * fix frontend * fix backend test * formatting * review changes * LaTeX height fix (#3258) * latex height fix * changelog * formatting * em * em * accidentally added script (#3273) * Adding a script to benchmark the queue (#3272) * added benchmark queue script * changelg * fix instructions * Fix matplotlib image size (#3274) * Fix matplotlib css * CHANGELOG * Undo lockfile * Add timeouts to queue messages (#3196) * Fix + test * Remove print statements + fix import for 3.7 * CHANGELOG * Remove more print statements * Add 60 second timeout for uploading data * Fix test --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * icons * separate options into component * formatting * changelog * changelog * fix ui tests * formatting again... * backend test fix * format * doc fixes --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co> Co-authored-by: fienestar <fienestar@gmail.com> Co-authored-by: pngwn <hello@pngwn.io> Co-authored-by: Freddy Boulton <alfonsoboulton@gmail.com>
2023-02-24 05:32:18 +08:00
multi_dropdown,
im1,
im2,
im3,
im4,
video,
audio1,
audio2,
file,
df1,
df2,
):
return (
(text1 if single_checkbox else text2)
+ ", selected:"
+ ", ".join(checkboxes), # Text
{
"positive": num / (num + slider1 + slider2),
"negative": slider1 / (num + slider1 + slider2),
"neutral": slider2 / (num + slider1 + slider2),
}, # Label
(audio1[0], np.flipud(audio1[1]))
if audio1 is not None
else os.path.join(os.path.dirname(__file__), "files/cantina.wav"), # Audio
np.flipud(im1)
if im1 is not None
else os.path.join(os.path.dirname(__file__), "files/cheetah1.jpg"), # Image
video
if video is not None
else os.path.join(os.path.dirname(__file__), "files/world.mp4"), # Video
[
("The", "art"),
("quick brown", "adj"),
("fox", "nn"),
("jumped", "vrb"),
("testing testing testing", None),
("over", "prp"),
("the", "art"),
("testing", None),
("lazy", "adj"),
("dogs", "nn"),
(".", "punc"),
]
+ [(f"test {x}", f"test {x}") for x in range(10)], # HighlightedText
2022-01-04 01:46:07 +08:00
# [("The testing testing testing", None), ("quick brown", 0.2), ("fox", 1), ("jumped", -1), ("testing testing testing", 0), ("over", 0), ("the", 0), ("testing", 0), ("lazy", 1), ("dogs", 0), (".", 1)] + [(f"test {x}", x/10) for x in range(-10, 10)], # HighlightedText
[
("The testing testing testing", None),
("over", 0.6),
("the", 0.2),
("testing", None),
("lazy", -0.1),
("dogs", 0.4),
(".", 0),
]
+ [(f"test", x / 10) for x in range(-10, 10)], # HighlightedText
2022-01-04 01:46:07 +08:00
json.loads(JSONOBJ), # JSON
"<button style='background-color: red'>Click Me: "
+ radio
+ "</button>", # HTML
os.path.join(os.path.dirname(__file__), "files/titanic.csv"),
df1, # Dataframe
np.random.randint(0, 10, (4, 4)), # Dataframe
df2, # Timeseries
)
2022-03-29 05:58:30 +08:00
demo = gr.Interface(
fn,
inputs=[
gr.Textbox(value="Lorem ipsum", label="Textbox"),
2022-03-29 05:58:30 +08:00
gr.Textbox(lines=3, placeholder="Type here..", label="Textbox 2"),
gr.Number(label="Number", value=42),
2022-05-16 14:55:35 +08:00
gr.Slider(10, 20, value=15, label="Slider: 10 - 20"),
2022-03-29 05:58:30 +08:00
gr.Slider(maximum=20, step=0.04, label="Slider: step @ 0.04"),
gr.Checkbox(label="Checkbox"),
gr.CheckboxGroup(label="CheckboxGroup", choices=CHOICES, value=CHOICES[0:2]),
gr.Radio(label="Radio", choices=CHOICES, value=CHOICES[2]),
2022-03-29 05:58:30 +08:00
gr.Dropdown(label="Dropdown", choices=CHOICES),
Dropdown Component Updates (#3211) * dropdown * more dropdown updates * dropdown styling + option visibility * changelog * notebook * fix test * Allow more image formats (#3225) * add wildcard to image input * simplify mime types * changelog * regen noteboks --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co> Co-authored-by: pngwn <hello@pngwn.io> * fix webcam mirroring (#3245) * fix webcam * changelog * fix changelog * fix changelog * fix changelog --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Add `interactive=False` mode to `gr.Button` (#3266) * add interactive=False to button * add interactive=True by default * changelog * fix frontend * fix backend test * formatting * review changes * LaTeX height fix (#3258) * latex height fix * changelog * formatting * em * em * accidentally added script (#3273) * Adding a script to benchmark the queue (#3272) * added benchmark queue script * changelg * fix instructions * Fix matplotlib image size (#3274) * Fix matplotlib css * CHANGELOG * Undo lockfile * Add timeouts to queue messages (#3196) * Fix + test * Remove print statements + fix import for 3.7 * CHANGELOG * Remove more print statements * Add 60 second timeout for uploading data * Fix test --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * icons * separate options into component * formatting * changelog * changelog * fix ui tests * formatting again... * backend test fix * format * doc fixes --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co> Co-authored-by: fienestar <fienestar@gmail.com> Co-authored-by: pngwn <hello@pngwn.io> Co-authored-by: Freddy Boulton <alfonsoboulton@gmail.com>
2023-02-24 05:32:18 +08:00
gr.Dropdown(label="Multiselect Dropdown (Max choice: 2)", choices=CHOICES, multiselect=True, max_choices=2),
2022-03-29 05:58:30 +08:00
gr.Image(label="Image"),
gr.Image(label="Image w/ Cropper", tool="select"),
gr.Image(label="Sketchpad", source="canvas"),
gr.Image(label="Webcam", source="webcam"),
gr.Video(label="Video"),
gr.Audio(label="Audio"),
gr.Audio(label="Microphone", source="microphone"),
gr.File(label="File"),
gr.Dataframe(label="Dataframe", headers=["Name", "Age", "Gender"]),
gr.Timeseries(x="time", y=["price", "value"], colors=["pink", "purple"]),
],
outputs=[
2022-03-29 05:58:30 +08:00
gr.Textbox(label="Textbox"),
gr.Label(label="Label"),
gr.Audio(label="Audio"),
gr.Image(label="Image"),
gr.Video(label="Video"),
Cleaning up the way data is processed for components (#1967) * remove preprocess_example * removing methods * added path support for images * fixes * video * formatting * fixing preprocess * fixes * removed from audio * fixed file * formatting * serialization * foramtting * formatting * removed save flag / restore flag * formatting * removed flagging * removed * load value * fixing typing * fixes, typing * fixes * file * handling images * formatting * fixed serializing for flagging * formatting * json * temp file * removed processing * changed processing * fixed temp FINALLY * flagging works * fix examples test * formatting * async examples * working on mix * comment out failing test * fixed interface problem * fix kitchen sink deprecation warning * gallery examples * fixes * fixes to serialization * fixing label serializing * fixed file serialization * kitchen sink restored * outbreak forecast updated * formatting * formatting and api mode * fix 1 test :/ * fixing tests * fixed components tests * remvoed test files * formatting * fixed examples * fixes * formatting * restored certain files * added encryption * fixed syntax mistake * formatting * fixed 1 test * clean up interface * formatting * fixed route tests * more fixes * formatting * formatting * fixing pipeline * format frontend * format backend * tweaks * fix * fix final test? * merged * Sanitize for CSV (#2017) * sanitize for csv * added sanitization logic * fixed examples * turn cache off * fixed example caching with optional inputs * fixed review problems * fixed Interface.load * updating the tests * updating the tests * fix * fixed seriailizing * testing * rewrite run prediction * formatting * await * fixes * formatting * finally fixed mix * fixed tests * formatting * formatting * deserialize fix * formatting * fixes * fixes * fix * fix tests * fixes Co-authored-by: Freddy Boulton <alfonsoboulton@gmail.com>
2022-08-23 23:31:04 +08:00
gr.HighlightedText(label="HighlightedText").style(
color_map={"punc": "pink", "test 0": "blue"}
2022-02-09 02:56:13 +08:00
),
2022-03-29 05:58:30 +08:00
gr.HighlightedText(label="HighlightedText", show_legend=True),
gr.JSON(label="JSON"),
gr.HTML(label="HTML"),
gr.File(label="File"),
gr.Dataframe(label="Dataframe"),
gr.Dataframe(label="Numpy"),
gr.Timeseries(x="time", y=["price", "value"], label="Timeseries"),
],
examples=[
[
"the quick brown fox",
"jumps over the lazy dog",
10,
12,
4,
True,
["foo", "baz"],
"baz",
"bar",
Dropdown Component Updates (#3211) * dropdown * more dropdown updates * dropdown styling + option visibility * changelog * notebook * fix test * Allow more image formats (#3225) * add wildcard to image input * simplify mime types * changelog * regen noteboks --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co> Co-authored-by: pngwn <hello@pngwn.io> * fix webcam mirroring (#3245) * fix webcam * changelog * fix changelog * fix changelog * fix changelog --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Add `interactive=False` mode to `gr.Button` (#3266) * add interactive=False to button * add interactive=True by default * changelog * fix frontend * fix backend test * formatting * review changes * LaTeX height fix (#3258) * latex height fix * changelog * formatting * em * em * accidentally added script (#3273) * Adding a script to benchmark the queue (#3272) * added benchmark queue script * changelg * fix instructions * Fix matplotlib image size (#3274) * Fix matplotlib css * CHANGELOG * Undo lockfile * Add timeouts to queue messages (#3196) * Fix + test * Remove print statements + fix import for 3.7 * CHANGELOG * Remove more print statements * Add 60 second timeout for uploading data * Fix test --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * icons * separate options into component * formatting * changelog * changelog * fix ui tests * formatting again... * backend test fix * format * doc fixes --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co> Co-authored-by: fienestar <fienestar@gmail.com> Co-authored-by: pngwn <hello@pngwn.io> Co-authored-by: Freddy Boulton <alfonsoboulton@gmail.com>
2023-02-24 05:32:18 +08:00
["foo", "bar"],
os.path.join(os.path.dirname(__file__), "files/cheetah1.jpg"),
os.path.join(os.path.dirname(__file__), "files/cheetah1.jpg"),
os.path.join(os.path.dirname(__file__), "files/cheetah1.jpg"),
os.path.join(os.path.dirname(__file__), "files/cheetah1.jpg"),
os.path.join(os.path.dirname(__file__), "files/world.mp4"),
os.path.join(os.path.dirname(__file__), "files/cantina.wav"),
os.path.join(os.path.dirname(__file__), "files/cantina.wav"),
os.path.join(os.path.dirname(__file__), "files/titanic.csv"),
[[1, 2, 3, 4], [4, 5, 6, 7], [8, 9, 1, 2], [3, 4, 5, 6]],
os.path.join(os.path.dirname(__file__), "files/time.csv"),
]
]
* 3,
title="Kitchen Sink",
description="Try out all the components!",
article="Learn more about [Gradio](http://gradio.app)",
cache_examples=True,
)
2021-06-30 03:04:22 +08:00
if __name__ == "__main__":
demo.launch()