mirror of
https://github.com/gradio-app/gradio.git
synced 2024-11-21 01:01:05 +08:00
demo updates
This commit is contained in:
parent
0d0d64e5d1
commit
8ee90120de
@ -241,11 +241,12 @@ class Image(InputComponent):
|
||||
Input type: Union[numpy.array, PIL.Image, str]
|
||||
"""
|
||||
|
||||
def __init__(self, shape=None, image_mode='RGB', source="upload", type="numpy", label=None):
|
||||
def __init__(self, shape=None, image_mode='RGB', invert_colors=False, source="upload", type="numpy", label=None):
|
||||
'''
|
||||
Parameters:
|
||||
shape (Tuple[int, int]): shape to crop and resize image to; if None, matches input image size.
|
||||
image_mode (str): "RGB" if color, or "L" if black and white.
|
||||
invert_colors (bool): whether to invert the image as a preprocessing step.
|
||||
source (str): Source of image. "upload" creates a box where user can drop an image file, "webcam" allows user to take snapshot from their webcam, "canvas" defaults to a white image that can be edited and drawn upon with tools.
|
||||
type (str): Type of value to be returned by component. "numpy" returns a numpy array with shape (width, height, 3), "pil" returns a PIL image object, "file" returns a temporary file object whose path can be retrieved by file_obj.name.
|
||||
label (str): component name in interface.
|
||||
@ -254,6 +255,7 @@ class Image(InputComponent):
|
||||
self.image_mode = image_mode
|
||||
self.source = source
|
||||
self.type = type
|
||||
self.invert_colors = invert_colors
|
||||
super().__init__(label)
|
||||
|
||||
@classmethod
|
||||
@ -261,7 +263,7 @@ class Image(InputComponent):
|
||||
return {
|
||||
"image": {},
|
||||
"webcam": {"source": "webcam"},
|
||||
"sketchpad": {"image_mode": "L", "source": "canvas"},
|
||||
"sketchpad": {"image_mode": "L", "source": "canvas", "shape": (28, 28), "invert_colors": True},
|
||||
}
|
||||
|
||||
def get_template_context(self):
|
||||
@ -279,6 +281,8 @@ class Image(InputComponent):
|
||||
if self.shape is not None:
|
||||
im = processing_utils.resize_and_crop(
|
||||
im, (self.shape[0], self.shape[1]))
|
||||
if self.invert_colors:
|
||||
im = PIL.ImageOps.invert(im)
|
||||
if self.type == "pil":
|
||||
return im
|
||||
elif self.type == "numpy":
|
||||
|
@ -11,7 +11,7 @@ const key_values = {
|
||||
init: function(opts) {},
|
||||
output: function(data) {
|
||||
let html = ""
|
||||
for (const [key, value] of Object.entries(data)) {
|
||||
for (const [key, value] of data) {
|
||||
html += `<tr>
|
||||
<td>${key}</td>
|
||||
<td>${value}</td>
|
||||
|
@ -29,37 +29,37 @@
|
||||
<meta name="twitter:image" content="{{thumbnail}}">
|
||||
|
||||
<title>Gradio</title>
|
||||
<!-- VENDOR -->
|
||||
<link type="text/css" href="../static/css/vendor/tui-color-picker.css" rel="stylesheet">
|
||||
<link type="text/css" href="../static/css/vendor/tui-image-editor.css" rel="stylesheet">
|
||||
<link type="text/css" href="../static/css/vendor/jquery-ui.css" rel="stylesheet">
|
||||
<link type="text/css" href="../static/css/vendor/jexcel.min.css" rel="stylesheet">
|
||||
<link type="text/css" href="../static/css/vendor/jsuites.min.css" rel="stylesheet">
|
||||
<link type="text/css" href="../static/css/vendor/jsonTree.css" rel="stylesheet">
|
||||
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
|
||||
<!-- VENDOR -->
|
||||
<link type="text/css" href="/static/css/vendor/tui-color-picker.css" rel="stylesheet">
|
||||
<link type="text/css" href="/static/css/vendor/tui-image-editor.css" rel="stylesheet">
|
||||
<link type="text/css" href="/static/css/vendor/jquery-ui.css" rel="stylesheet">
|
||||
<link type="text/css" href="/static/css/vendor/jexcel.min.css" rel="stylesheet">
|
||||
<link type="text/css" href="/static/css/vendor/jsuites.min.css" rel="stylesheet">
|
||||
<link type="text/css" href="/static/css/vendor/jsonTree.css" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../static/css/style.css">
|
||||
<link rel="stylesheet" href="../static/css/gradio.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/input/csv.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/input/image.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/input/sketchpad.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/input/textbox.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/input/radio.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/input/dropdown.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/input/checkbox_group.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/input/slider.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/input/webcam.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/input/microphone.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/input/file.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/output/image.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/output/label.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/output/key_values.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/output/textbox.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/output/highlighted_text.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/output/audio.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/output/json.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/output/html.css">
|
||||
<link rel="stylesheet" href="../static/css/loading.css"/>
|
||||
<link rel="stylesheet" href="/static/css/style.css">
|
||||
<link rel="stylesheet" href="/static/css/gradio.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/input/csv.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/input/image.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/input/sketchpad.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/input/textbox.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/input/radio.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/input/dropdown.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/input/checkbox_group.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/input/slider.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/input/webcam.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/input/microphone.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/input/file.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/output/image.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/output/label.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/output/key_values.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/output/textbox.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/output/highlighted_text.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/output/audio.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/output/json.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/output/html.css">
|
||||
<link rel="stylesheet" href="/static/css/loading.css"/>
|
||||
</head>
|
||||
|
||||
<body id="lib">
|
||||
@ -68,54 +68,54 @@
|
||||
<img src="static/img/logo_inline.png">
|
||||
</a></div>
|
||||
<!-- VENDOR -->
|
||||
<script src="../static/js/vendor/jquery.min.js"></script>
|
||||
<script src="../static/js/vendor/html2canvas.min.js"></script>
|
||||
<script src="../static/js/vendor/jquery-ui.min.js"></script>
|
||||
<script src="../static/js/vendor/jquery.ui.touch-punch.js"></script>
|
||||
<script src="../static/js/vendor/jsonTree.js"></script>
|
||||
<script src="../static/js/vendor/fabric.js"></script>
|
||||
<script src="../static/js/vendor/tui-code-snippet.min.js"></script>
|
||||
<script src="../static/js/vendor/FileSaver.min.js"></script>
|
||||
<script src="../static/js/vendor/tui-color-picker.js"></script>
|
||||
<script src="../static/js/vendor/tui-image-editor.js"></script>
|
||||
<script src="../static/js/vendor/white-theme.js"></script>
|
||||
<script src="../static/js/vendor/black-theme.js"></script>
|
||||
<script src="../static/js/vendor/wavesurfer.min.js"></script>
|
||||
<script src="../static/js/vendor/p5.min.js"></script>
|
||||
<script src="../static/js/vendor/p5.sound.min.js"></script>
|
||||
<script src="../static/js/vendor/p5.dom.min.js"></script>
|
||||
<script src="../static/js/vendor/jexcel.min.js"></script>
|
||||
<script src="../static/js/vendor/jsuites.min.js"></script>
|
||||
<script src="/static/js/vendor/jquery.min.js"></script>
|
||||
<script src="/static/js/vendor/html2canvas.min.js"></script>
|
||||
<script src="/static/js/vendor/jquery-ui.min.js"></script>
|
||||
<script src="/static/js/vendor/jquery.ui.touch-punch.js"></script>
|
||||
<script src="/static/js/vendor/jsonTree.js"></script>
|
||||
<script src="/static/js/vendor/fabric.js"></script>
|
||||
<script src="/static/js/vendor/tui-code-snippet.min.js"></script>
|
||||
<script src="/static/js/vendor/FileSaver.min.js"></script>
|
||||
<script src="/static/js/vendor/tui-color-picker.js"></script>
|
||||
<script src="/static/js/vendor/tui-image-editor.js"></script>
|
||||
<script src="/static/js/vendor/white-theme.js"></script>
|
||||
<script src="/static/js/vendor/black-theme.js"></script>
|
||||
<script src="/static/js/vendor/wavesurfer.min.js"></script>
|
||||
<script src="/static/js/vendor/p5.min.js"></script>
|
||||
<script src="/static/js/vendor/p5.sound.min.js"></script>
|
||||
<script src="/static/js/vendor/p5.dom.min.js"></script>
|
||||
<script src="/static/js/vendor/jexcel.min.js"></script>
|
||||
<script src="/static/js/vendor/jsuites.min.js"></script>
|
||||
|
||||
<script src="../static/js/utils.js"></script>
|
||||
<script src="../static/js/all_io.js"></script>
|
||||
<script src="../static/js/interfaces/input/csv.js"></script>
|
||||
<script src="../static/js/interfaces/input/image.js"></script>
|
||||
<script src="../static/js/vendor/sketchpad.js"></script>
|
||||
<script src="../static/js/interfaces/input/sketchpad.js"></script>
|
||||
<script src="../static/js/interfaces/input/textbox.js"></script>
|
||||
<script src="../static/js/interfaces/input/radio.js"></script>
|
||||
<script src="../static/js/interfaces/input/checkbox_group.js"></script>
|
||||
<script src="../static/js/interfaces/input/checkbox.js"></script>
|
||||
<script src="../static/js/interfaces/input/dropdown.js"></script>
|
||||
<script src="../static/js/interfaces/input/slider.js"></script>
|
||||
<script src="../static/js/interfaces/input/dataframe.js"></script>
|
||||
<script src="../static/js/interfaces/input/audio.js"></script>
|
||||
<script src="../static/js/interfaces/input/file.js"></script>
|
||||
<script src="../static/js/vendor/webcam.min.js"></script>
|
||||
<script src="../static/js/interfaces/input/webcam.js"></script>
|
||||
<script src="../static/js/interfaces/input/microphone.js"></script>
|
||||
<script src="../static/js/interfaces/output/image.js"></script>
|
||||
<script src="../static/js/interfaces/output/label.js"></script>
|
||||
<script src="../static/js/interfaces/output/key_values.js"></script>
|
||||
<script src="../static/js/interfaces/output/textbox.js"></script>
|
||||
<script src="../static/js/interfaces/output/highlighted_text.js"></script>
|
||||
<script src="../static/js/interfaces/output/audio.js"></script>
|
||||
<script src="../static/js/interfaces/output/json.js"></script>
|
||||
<script src="../static/js/interfaces/output/html.js"></script>
|
||||
<script src="../static/js/interfaces/output/dataframe.js"></script>
|
||||
<script src="../static/js/interfaces/output/file.js"></script>
|
||||
<script src="../static/js/gradio.js"></script>
|
||||
<script src="/static/js/utils.js"></script>
|
||||
<script src="/static/js/all_io.js"></script>
|
||||
<script src="/static/js/interfaces/input/csv.js"></script>
|
||||
<script src="/static/js/interfaces/input/image.js"></script>
|
||||
<script src="/static/js/vendor/sketchpad.js"></script>
|
||||
<script src="/static/js/interfaces/input/sketchpad.js"></script>
|
||||
<script src="/static/js/interfaces/input/textbox.js"></script>
|
||||
<script src="/static/js/interfaces/input/radio.js"></script>
|
||||
<script src="/static/js/interfaces/input/checkbox_group.js"></script>
|
||||
<script src="/static/js/interfaces/input/checkbox.js"></script>
|
||||
<script src="/static/js/interfaces/input/dropdown.js"></script>
|
||||
<script src="/static/js/interfaces/input/slider.js"></script>
|
||||
<script src="/static/js/interfaces/input/dataframe.js"></script>
|
||||
<script src="/static/js/interfaces/input/audio.js"></script>
|
||||
<script src="/static/js/interfaces/input/file.js"></script>
|
||||
<script src="/static/js/vendor/webcam.min.js"></script>
|
||||
<script src="/static/js/interfaces/input/webcam.js"></script>
|
||||
<script src="/static/js/interfaces/input/microphone.js"></script>
|
||||
<script src="/static/js/interfaces/output/image.js"></script>
|
||||
<script src="/static/js/interfaces/output/label.js"></script>
|
||||
<script src="/static/js/interfaces/output/key_values.js"></script>
|
||||
<script src="/static/js/interfaces/output/textbox.js"></script>
|
||||
<script src="/static/js/interfaces/output/highlighted_text.js"></script>
|
||||
<script src="/static/js/interfaces/output/audio.js"></script>
|
||||
<script src="/static/js/interfaces/output/json.js"></script>
|
||||
<script src="/static/js/interfaces/output/html.js"></script>
|
||||
<script src="/static/js/interfaces/output/dataframe.js"></script>
|
||||
<script src="/static/js/interfaces/output/file.js"></script>
|
||||
<script src="/static/js/gradio.js"></script>
|
||||
<script>
|
||||
$.getJSON("static/config.json", function(config) {
|
||||
io = gradio_url(config, "/api/predict/", "#interface_target");
|
||||
|
31
demo/all.py
31
demo/all.py
@ -1,31 +0,0 @@
|
||||
import gradio as gr
|
||||
import numpy as np
|
||||
|
||||
def answer_question(quantity, animal, place, activity_list, morning, etc, im1, im2):
|
||||
return f"""The {quantity} {animal}s went to the {place} where they {" and ".join(activity_list)} until the {"morning" if morning else "night"}""", np.flipud(im2)
|
||||
|
||||
|
||||
gr.Interface(answer_question,
|
||||
[
|
||||
gr.inputs.Slider(2, 20),
|
||||
gr.inputs.Dropdown(["cat", "dog", "bird"]),
|
||||
gr.inputs.Radio(["park", "zoo", "road"]),
|
||||
gr.inputs.CheckboxGroup(["ran", "swam", "ate", "slept"]),
|
||||
gr.inputs.Checkbox(label="Is it the morning?"),
|
||||
gr.inputs.Textbox(default="What else?"),
|
||||
gr.inputs.Sketchpad(shape=(100,100)),
|
||||
gr.inputs.Image(shape=(100,100)),
|
||||
],
|
||||
[
|
||||
gr.outputs.Textbox(),
|
||||
gr.outputs.Image()
|
||||
],
|
||||
examples=[
|
||||
[2, "cat", "park", ["ran", "swam"], True, "t1"],
|
||||
[4, "dog", "zoo", ["ate", "swam"], False, "t2"],
|
||||
[10, "bird", "road", ["ran"], False, "t3"],
|
||||
[8, "cat", "zoo", ["ate"], True, "t1"],
|
||||
],
|
||||
title="Test for all Interfaces",
|
||||
description="Here's an example that uses almost all the interface types, so give it a try! Let's hope it works :D"
|
||||
).launch()
|
21
demo/diff_texts.py
Normal file
21
demo/diff_texts.py
Normal file
@ -0,0 +1,21 @@
|
||||
import gradio as gr
|
||||
from difflib import Differ
|
||||
|
||||
def diff_texts(text1, text2):
|
||||
d = Differ()
|
||||
return [
|
||||
(token[2:], token[0]) for token in d.compare(text1, text2)
|
||||
]
|
||||
|
||||
gr.Interface(
|
||||
diff_texts,
|
||||
[
|
||||
gr.inputs.Textbox(lines=3, default="The quick brown fox jumped over the lazy dogs."),
|
||||
gr.inputs.Textbox(lines=3, default="The fast brown fox jumps over lazy dogs."),
|
||||
],
|
||||
gr.outputs.HighlightedText(color_map={
|
||||
"+": "lightgreen",
|
||||
"-": "pink",
|
||||
" ": "none",
|
||||
})
|
||||
).launch()
|
@ -9,7 +9,7 @@ urlretrieve("https://gr-models.s3-us-west-2.amazonaws.com/mnist-model.h5", "mnis
|
||||
model = tf.keras.models.load_model("mnist-model.h5")
|
||||
|
||||
def recognize_digit(image):
|
||||
image = image.reshape(-1, 1)
|
||||
image = image.reshape(1, -1)
|
||||
prediction = model.predict(image).tolist()[0]
|
||||
return {str(i): prediction[i] for i in range(10)}
|
||||
|
||||
|
@ -10,5 +10,6 @@ gr.Interface(filter_records,
|
||||
gr.inputs.Dataframe(headers=["name", "age", "gender"], datatype=["str", "number", "str"], row_count=5),
|
||||
gr.inputs.Dropdown(["M", "F", "O"])
|
||||
],
|
||||
"dataframe"
|
||||
"dataframe",
|
||||
description="Enter gender as 'M', 'F', or 'O' for other."
|
||||
).launch()
|
@ -1,26 +0,0 @@
|
||||
import gradio as gr
|
||||
import numpy as np
|
||||
from time import time
|
||||
|
||||
|
||||
def flip(image):
|
||||
start = time()
|
||||
return image
|
||||
|
||||
|
||||
def flip2(image):
|
||||
start = time()
|
||||
return np.fliplr(image)
|
||||
|
||||
def flip10(i1, i2, i3, i4, i5):
|
||||
return i1 + i2
|
||||
|
||||
gr.Interface(flip2,
|
||||
["webcam"],
|
||||
["image"],
|
||||
examples=[
|
||||
["images/cheetah1.jpg"],
|
||||
["images/cheetah2.jpg"],
|
||||
["images/lion.jpg"],
|
||||
]
|
||||
).launch(share=True)
|
22
demo/generate_tone.py
Normal file
22
demo/generate_tone.py
Normal file
@ -0,0 +1,22 @@
|
||||
import gradio as gr
|
||||
import numpy as np
|
||||
import random
|
||||
|
||||
notes = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
|
||||
|
||||
def generate_tone(note, octave, duration):
|
||||
sr = 48000
|
||||
a4_freq, tones_from_a4 = 440, 12 * (octave - 4) + (note - 9)
|
||||
frequency = a4_freq * 2 ** (tones_from_a4 / 12)
|
||||
audio = np.linspace(0, duration, duration * sr)
|
||||
audio = (20000 * np.sin(audio * (2 * np.pi * frequency))).astype(np.int16)
|
||||
return (sr, audio)
|
||||
|
||||
|
||||
gr.Interface(
|
||||
generate_tone,
|
||||
[
|
||||
gr.inputs.Dropdown(notes, type="index"),
|
||||
gr.inputs.Slider(4, 6, step=1),
|
||||
gr.inputs.Textbox(type="number", default=1, label="Duration in seconds")
|
||||
], "audio").launch()
|
21
demo/image_mod.py
Normal file
21
demo/image_mod.py
Normal file
@ -0,0 +1,21 @@
|
||||
import gradio as gr
|
||||
from time import time
|
||||
from PIL import Image, ImageFilter
|
||||
|
||||
|
||||
def image_mod(image):
|
||||
return image.rotate(45), image.filter(ImageFilter.FIND_EDGES)
|
||||
|
||||
|
||||
gr.Interface(image_mod,
|
||||
gr.inputs.Image(type="pil"),
|
||||
[
|
||||
gr.outputs.Image(type="pil"),
|
||||
gr.outputs.Image(type="pil"),
|
||||
],
|
||||
examples=[
|
||||
["images/cheetah1.jpg"],
|
||||
["images/cheetah2.jpg"],
|
||||
["images/lion.jpg"],
|
||||
]
|
||||
).launch(share=True)
|
@ -1,32 +0,0 @@
|
||||
import gradio as gr
|
||||
import numpy as np
|
||||
import random
|
||||
|
||||
def answer_question(text, audio):
|
||||
return [
|
||||
("The movie was ", "good"),
|
||||
("unexpectedly, ", "great"),
|
||||
("a fantastic experience ", "neutral"),
|
||||
], {
|
||||
"address": "1 Main St.",
|
||||
"bedrooms": 5,
|
||||
"is_apt": False,
|
||||
"residents": [
|
||||
{"name": "Farhan", "age": 13},
|
||||
{"name": "Aziz", "age": 18},
|
||||
{"name": "Fozan", "age": None},
|
||||
]
|
||||
}, "<div style='background-color: pink; padding: 2px;'>" + str(audio[1].shape) + "</div>", audio
|
||||
|
||||
gr.Interface(answer_question,
|
||||
[
|
||||
gr.inputs.Dropdown(["cat", "dog", "bird"]),
|
||||
"microphone",
|
||||
],
|
||||
[
|
||||
gr.outputs.HighlightedText(color_map={"good": "lightgreen", "bad": "pink"}),
|
||||
gr.outputs.JSON(),
|
||||
gr.outputs.HTML(),
|
||||
gr.outputs.Audio(),
|
||||
],
|
||||
).launch()
|
@ -1,11 +1,11 @@
|
||||
import gradio as gr
|
||||
import numpy as np
|
||||
|
||||
def answer_question(quantity, animal, place, activity_list, morning):
|
||||
def sentence_builder(quantity, animal, place, activity_list, morning):
|
||||
return f"""The {quantity} {animal}s went to the {place} where they {" and ".join(activity_list)} until the {"morning" if morning else "night"}"""
|
||||
|
||||
|
||||
gr.Interface(answer_question,
|
||||
gr.Interface(sentence_builder,
|
||||
[
|
||||
gr.inputs.Slider(2, 20),
|
||||
gr.inputs.Dropdown(["cat", "dog", "bird"]),
|
@ -4,7 +4,7 @@ import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
|
||||
def plot_forecast(final_year, companies, noise, show_legend, point_style):
|
||||
def stock_forecast(final_year, companies, noise, show_legend, point_style):
|
||||
start_year = 2020
|
||||
x = np.arange(start_year, final_year + 1)
|
||||
year_count = x.shape[0]
|
||||
@ -19,14 +19,14 @@ def plot_forecast(final_year, companies, noise, show_legend, point_style):
|
||||
return plt
|
||||
|
||||
|
||||
gr.Interface(plot_forecast,
|
||||
gr.Interface(stock_forecast,
|
||||
[
|
||||
gr.inputs.Radio([2025, 2030, 2035, 2040],
|
||||
label="Project to:"),
|
||||
gr.inputs.CheckboxGroup(
|
||||
["Google", "Microsoft", "Gradio"], label="Company Selection"),
|
||||
gr.inputs.Slider(1, 100, label="Noise Level"),
|
||||
gr.inputs.Checkbox(label="Show Legend"),
|
||||
["Google", "Microsoft", "Gradio"]),
|
||||
gr.inputs.Slider(1, 100),
|
||||
"checkbox",
|
||||
gr.inputs.Dropdown(["cross", "line", "circle"], label="Style"),
|
||||
],
|
||||
gr.outputs.Image(plot=True, label="forecast")
|
30
demo/text_analysis.py
Normal file
30
demo/text_analysis.py
Normal file
@ -0,0 +1,30 @@
|
||||
import spacy
|
||||
from spacy import displacy
|
||||
import gradio as gr
|
||||
|
||||
nlp = spacy.load("en_core_web_sm")
|
||||
|
||||
def text_analysis(text):
|
||||
doc = nlp(text)
|
||||
html = displacy.render(doc, style="dep", page=True)
|
||||
html = "<div style='max-width:100%; max-height:360px; overflow:auto'>" + html + "</div>"
|
||||
pos_count = {
|
||||
"char_count": len(text),
|
||||
"token_count": 0,
|
||||
}
|
||||
pos_tokens = []
|
||||
|
||||
for token in doc:
|
||||
pos_count["token_count"] += 1
|
||||
pos_count[token.pos_] = pos_count.get(token.pos_, 0) + 1
|
||||
pos_tokens.extend([(token.text, token.pos_), (" ", None)])
|
||||
|
||||
return pos_tokens, pos_count, html
|
||||
|
||||
gr.Interface(
|
||||
text_analysis,
|
||||
gr.inputs.Textbox(placeholder="Enter sentence here..."),
|
||||
[
|
||||
"highlight", "key_values", "html"
|
||||
]
|
||||
).launch()
|
@ -11,7 +11,7 @@ const key_values = {
|
||||
init: function(opts) {},
|
||||
output: function(data) {
|
||||
let html = ""
|
||||
for (const [key, value] of Object.entries(data)) {
|
||||
for (const [key, value] of data) {
|
||||
html += `<tr>
|
||||
<td>${key}</td>
|
||||
<td>${value}</td>
|
||||
|
@ -29,37 +29,37 @@
|
||||
<meta name="twitter:image" content="{{thumbnail}}">
|
||||
|
||||
<title>Gradio</title>
|
||||
<!-- VENDOR -->
|
||||
<link type="text/css" href="../static/css/vendor/tui-color-picker.css" rel="stylesheet">
|
||||
<link type="text/css" href="../static/css/vendor/tui-image-editor.css" rel="stylesheet">
|
||||
<link type="text/css" href="../static/css/vendor/jquery-ui.css" rel="stylesheet">
|
||||
<link type="text/css" href="../static/css/vendor/jexcel.min.css" rel="stylesheet">
|
||||
<link type="text/css" href="../static/css/vendor/jsuites.min.css" rel="stylesheet">
|
||||
<link type="text/css" href="../static/css/vendor/jsonTree.css" rel="stylesheet">
|
||||
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
|
||||
<!-- VENDOR -->
|
||||
<link type="text/css" href="/static/css/vendor/tui-color-picker.css" rel="stylesheet">
|
||||
<link type="text/css" href="/static/css/vendor/tui-image-editor.css" rel="stylesheet">
|
||||
<link type="text/css" href="/static/css/vendor/jquery-ui.css" rel="stylesheet">
|
||||
<link type="text/css" href="/static/css/vendor/jexcel.min.css" rel="stylesheet">
|
||||
<link type="text/css" href="/static/css/vendor/jsuites.min.css" rel="stylesheet">
|
||||
<link type="text/css" href="/static/css/vendor/jsonTree.css" rel="stylesheet">
|
||||
|
||||
<link rel="stylesheet" href="../static/css/style.css">
|
||||
<link rel="stylesheet" href="../static/css/gradio.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/input/csv.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/input/image.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/input/sketchpad.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/input/textbox.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/input/radio.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/input/dropdown.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/input/checkbox_group.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/input/slider.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/input/webcam.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/input/microphone.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/input/file.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/output/image.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/output/label.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/output/key_values.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/output/textbox.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/output/highlighted_text.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/output/audio.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/output/json.css">
|
||||
<link rel="stylesheet" href="../static/css/interfaces/output/html.css">
|
||||
<link rel="stylesheet" href="../static/css/loading.css"/>
|
||||
<link rel="stylesheet" href="/static/css/style.css">
|
||||
<link rel="stylesheet" href="/static/css/gradio.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/input/csv.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/input/image.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/input/sketchpad.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/input/textbox.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/input/radio.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/input/dropdown.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/input/checkbox_group.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/input/slider.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/input/webcam.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/input/microphone.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/input/file.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/output/image.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/output/label.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/output/key_values.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/output/textbox.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/output/highlighted_text.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/output/audio.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/output/json.css">
|
||||
<link rel="stylesheet" href="/static/css/interfaces/output/html.css">
|
||||
<link rel="stylesheet" href="/static/css/loading.css"/>
|
||||
</head>
|
||||
|
||||
<body id="lib">
|
||||
@ -68,54 +68,54 @@
|
||||
<img src="static/img/logo_inline.png">
|
||||
</a></div>
|
||||
<!-- VENDOR -->
|
||||
<script src="../static/js/vendor/jquery.min.js"></script>
|
||||
<script src="../static/js/vendor/html2canvas.min.js"></script>
|
||||
<script src="../static/js/vendor/jquery-ui.min.js"></script>
|
||||
<script src="../static/js/vendor/jquery.ui.touch-punch.js"></script>
|
||||
<script src="../static/js/vendor/jsonTree.js"></script>
|
||||
<script src="../static/js/vendor/fabric.js"></script>
|
||||
<script src="../static/js/vendor/tui-code-snippet.min.js"></script>
|
||||
<script src="../static/js/vendor/FileSaver.min.js"></script>
|
||||
<script src="../static/js/vendor/tui-color-picker.js"></script>
|
||||
<script src="../static/js/vendor/tui-image-editor.js"></script>
|
||||
<script src="../static/js/vendor/white-theme.js"></script>
|
||||
<script src="../static/js/vendor/black-theme.js"></script>
|
||||
<script src="../static/js/vendor/wavesurfer.min.js"></script>
|
||||
<script src="../static/js/vendor/p5.min.js"></script>
|
||||
<script src="../static/js/vendor/p5.sound.min.js"></script>
|
||||
<script src="../static/js/vendor/p5.dom.min.js"></script>
|
||||
<script src="../static/js/vendor/jexcel.min.js"></script>
|
||||
<script src="../static/js/vendor/jsuites.min.js"></script>
|
||||
<script src="/static/js/vendor/jquery.min.js"></script>
|
||||
<script src="/static/js/vendor/html2canvas.min.js"></script>
|
||||
<script src="/static/js/vendor/jquery-ui.min.js"></script>
|
||||
<script src="/static/js/vendor/jquery.ui.touch-punch.js"></script>
|
||||
<script src="/static/js/vendor/jsonTree.js"></script>
|
||||
<script src="/static/js/vendor/fabric.js"></script>
|
||||
<script src="/static/js/vendor/tui-code-snippet.min.js"></script>
|
||||
<script src="/static/js/vendor/FileSaver.min.js"></script>
|
||||
<script src="/static/js/vendor/tui-color-picker.js"></script>
|
||||
<script src="/static/js/vendor/tui-image-editor.js"></script>
|
||||
<script src="/static/js/vendor/white-theme.js"></script>
|
||||
<script src="/static/js/vendor/black-theme.js"></script>
|
||||
<script src="/static/js/vendor/wavesurfer.min.js"></script>
|
||||
<script src="/static/js/vendor/p5.min.js"></script>
|
||||
<script src="/static/js/vendor/p5.sound.min.js"></script>
|
||||
<script src="/static/js/vendor/p5.dom.min.js"></script>
|
||||
<script src="/static/js/vendor/jexcel.min.js"></script>
|
||||
<script src="/static/js/vendor/jsuites.min.js"></script>
|
||||
|
||||
<script src="../static/js/utils.js"></script>
|
||||
<script src="../static/js/all_io.js"></script>
|
||||
<script src="../static/js/interfaces/input/csv.js"></script>
|
||||
<script src="../static/js/interfaces/input/image.js"></script>
|
||||
<script src="../static/js/vendor/sketchpad.js"></script>
|
||||
<script src="../static/js/interfaces/input/sketchpad.js"></script>
|
||||
<script src="../static/js/interfaces/input/textbox.js"></script>
|
||||
<script src="../static/js/interfaces/input/radio.js"></script>
|
||||
<script src="../static/js/interfaces/input/checkbox_group.js"></script>
|
||||
<script src="../static/js/interfaces/input/checkbox.js"></script>
|
||||
<script src="../static/js/interfaces/input/dropdown.js"></script>
|
||||
<script src="../static/js/interfaces/input/slider.js"></script>
|
||||
<script src="../static/js/interfaces/input/dataframe.js"></script>
|
||||
<script src="../static/js/interfaces/input/audio.js"></script>
|
||||
<script src="../static/js/interfaces/input/file.js"></script>
|
||||
<script src="../static/js/vendor/webcam.min.js"></script>
|
||||
<script src="../static/js/interfaces/input/webcam.js"></script>
|
||||
<script src="../static/js/interfaces/input/microphone.js"></script>
|
||||
<script src="../static/js/interfaces/output/image.js"></script>
|
||||
<script src="../static/js/interfaces/output/label.js"></script>
|
||||
<script src="../static/js/interfaces/output/key_values.js"></script>
|
||||
<script src="../static/js/interfaces/output/textbox.js"></script>
|
||||
<script src="../static/js/interfaces/output/highlighted_text.js"></script>
|
||||
<script src="../static/js/interfaces/output/audio.js"></script>
|
||||
<script src="../static/js/interfaces/output/json.js"></script>
|
||||
<script src="../static/js/interfaces/output/html.js"></script>
|
||||
<script src="../static/js/interfaces/output/dataframe.js"></script>
|
||||
<script src="../static/js/interfaces/output/file.js"></script>
|
||||
<script src="../static/js/gradio.js"></script>
|
||||
<script src="/static/js/utils.js"></script>
|
||||
<script src="/static/js/all_io.js"></script>
|
||||
<script src="/static/js/interfaces/input/csv.js"></script>
|
||||
<script src="/static/js/interfaces/input/image.js"></script>
|
||||
<script src="/static/js/vendor/sketchpad.js"></script>
|
||||
<script src="/static/js/interfaces/input/sketchpad.js"></script>
|
||||
<script src="/static/js/interfaces/input/textbox.js"></script>
|
||||
<script src="/static/js/interfaces/input/radio.js"></script>
|
||||
<script src="/static/js/interfaces/input/checkbox_group.js"></script>
|
||||
<script src="/static/js/interfaces/input/checkbox.js"></script>
|
||||
<script src="/static/js/interfaces/input/dropdown.js"></script>
|
||||
<script src="/static/js/interfaces/input/slider.js"></script>
|
||||
<script src="/static/js/interfaces/input/dataframe.js"></script>
|
||||
<script src="/static/js/interfaces/input/audio.js"></script>
|
||||
<script src="/static/js/interfaces/input/file.js"></script>
|
||||
<script src="/static/js/vendor/webcam.min.js"></script>
|
||||
<script src="/static/js/interfaces/input/webcam.js"></script>
|
||||
<script src="/static/js/interfaces/input/microphone.js"></script>
|
||||
<script src="/static/js/interfaces/output/image.js"></script>
|
||||
<script src="/static/js/interfaces/output/label.js"></script>
|
||||
<script src="/static/js/interfaces/output/key_values.js"></script>
|
||||
<script src="/static/js/interfaces/output/textbox.js"></script>
|
||||
<script src="/static/js/interfaces/output/highlighted_text.js"></script>
|
||||
<script src="/static/js/interfaces/output/audio.js"></script>
|
||||
<script src="/static/js/interfaces/output/json.js"></script>
|
||||
<script src="/static/js/interfaces/output/html.js"></script>
|
||||
<script src="/static/js/interfaces/output/dataframe.js"></script>
|
||||
<script src="/static/js/interfaces/output/file.js"></script>
|
||||
<script src="/static/js/gradio.js"></script>
|
||||
<script>
|
||||
$.getJSON("static/config.json", function(config) {
|
||||
io = gradio_url(config, "/api/predict/", "#interface_target");
|
||||
|
Loading…
Reference in New Issue
Block a user