demo updates

This commit is contained in:
Ali Abid 2020-08-21 16:17:11 -07:00
parent cbdfcd5dc7
commit d39eb9ea3f
9 changed files with 43 additions and 10 deletions

3
.gitignore vendored
View File

@ -20,4 +20,5 @@ demo/models/*
dist/*
*.h5
docs.json
*.bak
*.bak
demo/tmp.zip

View File

@ -1,4 +1,4 @@
# Demo (Dataframe, Dropdown) -> (Dataframe)
# Demo: (Dataframe, Dropdown) -> (Dataframe)
import gradio as gr
import numpy as np

View File

Before

Width:  |  Height:  |  Size: 800 KiB

After

Width:  |  Height:  |  Size: 800 KiB

View File

@ -1,4 +1,4 @@
# (Radio, CheckboxGroup, Slider, Dropdown) -> (Image)
# Demo: (Radio, CheckboxGroup, Slider, Dropdown) -> (Image)
import gradio as gr
import random

View File

@ -1,7 +1,9 @@
# Demo: (Image) -> (HighlightedText, KeyValues, HTML)
import gradio as gr
import numpy as np
def snap(image):
return image
return np.flipud(image)
gr.Interface(snap, gr.inputs.Image(shape=(100,100), image_mode="L", source="webcam"), "image").launch()

View File

@ -1,3 +1,5 @@
# Demo: (File) -> (JSON)
import gradio as gr
from zipfile import ZipFile

View File

@ -1,3 +1,5 @@
# Demo: (File, File) -> (File)
import gradio as gr
from zipfile import ZipFile

View File

@ -3,6 +3,31 @@ from gradio.inputs import InputComponent
from gradio.outputs import OutputComponent
from gradio.interface import Interface
import inspect
from os import listdir
from os.path import join
import re
in_demos, out_demos = {}, {}
demo_regex = "# Demo: \((.*)\) -> \((.*)\)"
for demo in listdir("demo"):
if demo.endswith(".py"):
screenshots = listdir(join("demo/screenshots", demo[:-3]))
demoset = [demo, screenshots]
with open(join("demo", demo)) as demo_file:
first_line = demo_file.readline()
match = re.match(demo_regex, first_line)
inputs = match.group(1).split(", ")
outputs = match.group(2).split(", ")
for i in inputs:
if i not in in_demos:
in_demos[i] = []
elif demoset not in in_demos[i]:
in_demos[i].append(demoset)
for o in outputs:
if o not in out_demos:
out_demos[o] = []
elif demoset not in out_demos[o]:
out_demos[o].append(demoset)
def get_params(func):
params_str = inspect.getdoc(func)
@ -33,7 +58,7 @@ def get_params(func):
param_set.insert(0, (params.args[neg_index],))
return param_set, params_doc
def document(cls_set):
def document(cls_set, demos):
docset = []
for cls in cls_set:
inp = {}
@ -45,11 +70,14 @@ def document(cls_set):
inp["type"] = doc.split("\n")[-1].split("type: ")[-1]
inp["params"], inp["params_doc"] = get_params(cls.__init__)
inp["shortcuts"] = list(cls.get_shortcut_implementations().items())
cls_name = cls.__name__
if cls_name in demos:
inp["demos"] = demos.get(cls_name, [])
docset.append(inp)
return docset
inputs = document(InputComponent.__subclasses__())
outputs = document(OutputComponent.__subclasses__())
inputs = document(InputComponent.__subclasses__(), in_demos)
outputs = document(OutputComponent.__subclasses__(), out_demos)
interface_params = get_params(Interface.__init__)
interface = {
"doc": inspect.getdoc(Interface),
@ -67,6 +95,6 @@ with open("docs.json", "w") as docs:
"inputs": inputs,
"outputs": outputs,
"interface": interface,
"launch": launch
"launch": launch,
}, docs)

View File

@ -151,13 +151,11 @@ def serve_files_in_background(interface, port, directory_to_serve=None, server_n
if self.path == "/api/predict/":
# Make the prediction.
self._set_headers()
print("in")
data_string = self.rfile.read(
int(self.headers["Content-Length"]))
msg = json.loads(data_string)
raw_input = msg["data"]
prediction, durations = interface.process(raw_input)
print("prediction")
output = {"data": prediction, "durations": durations}
self.wfile.write(json.dumps(output).encode())