This commit is contained in:
dawoodkhan82 2020-06-30 19:11:42 -04:00
commit 93de2b2411
8 changed files with 30 additions and 77 deletions

View File

@ -31,7 +31,7 @@ class Interface:
def __init__(self, fn, inputs, outputs, saliency=None, verbose=False, examples=None, def __init__(self, fn, inputs, outputs, saliency=None, verbose=False, examples=None,
live=False, show_input=True, show_output=True, live=False, show_input=True, show_output=True,
load_fn=None, capture_session=False, title=None, description=None, load_fn=None, capture_session=False, title=None, description=None,
server_name=LOCALHOST_IP): thumbnail=None, server_name=LOCALHOST_IP):
""" """
:param fn: a function that will process the input panel data from the interface and return the output panel data. :param fn: a function that will process the input panel data from the interface and return the output panel data.
:param inputs: a string or `AbstractInput` representing the input interface. :param inputs: a string or `AbstractInput` representing the input interface.
@ -68,8 +68,6 @@ class Interface:
fn = [fn] fn = [fn]
self.output_interfaces *= len(fn) self.output_interfaces *= len(fn)
self.predict = fn self.predict = fn
self.load_fn = load_fn
self.context = None
self.verbose = verbose self.verbose = verbose
self.status = "OFF" self.status = "OFF"
self.saliency = saliency self.saliency = saliency
@ -82,6 +80,7 @@ class Interface:
self.server_name = server_name self.server_name = server_name
self.title = title self.title = title
self.description = description self.description = description
self.thumbnail = thumbnail
self.examples = examples self.examples = examples
def get_config_file(self): def get_config_file(self):
@ -98,46 +97,34 @@ class Interface:
"show_output": self.show_output, "show_output": self.show_output,
"title": self.title, "title": self.title,
"description": self.description, "description": self.description,
"thumbnail": self.thumbnail
} }
def process(self, raw_input): def process(self, raw_input):
processed_input = [input_interface.preprocess( processed_input = [input_interface.preprocess(
raw_input[i]) for i, input_interface in enumerate(self.input_interfaces)] raw_input[i]) for i, input_interface in
enumerate(self.input_interfaces)]
predictions = [] predictions = []
for predict_fn in self.predict: for predict_fn in self.predict:
if self.context: if self.capture_session:
if self.capture_session: graph, sess = self.session
graph, sess = self.session with graph.as_default():
with graph.as_default(): with sess.as_default():
with sess.as_default(): prediction = predict_fn(*processed_input)
prediction = predict_fn(*processed_input,
self.context)
else:
try:
prediction = predict_fn(*processed_input, self.context)
except ValueError:
print("It looks like you might be "
"using tensorflow < 2.0. Please pass "
"capture_session=True in Interface to avoid "
"a 'Tensor is not an element of this graph.' "
"error.")
prediction = predict_fn(*processed_input, self.context)
else: else:
if self.capture_session: try:
graph, sess = self.session prediction = predict_fn(*processed_input)
with graph.as_default(): except ValueError as exception:
with sess.as_default(): if str(exception).endswith("is not an element of this "
prediction = predict_fn(*processed_input) "graph."):
else: raise ValueError("It looks like you might be using "
try: "tensorflow < 2.0. Please "
prediction = predict_fn(*processed_input) "pass capture_session=True in "
except ValueError: "Interface to avoid the 'Tensor is "
print("It looks like you might be " "not an element of this graph.' "
"using tensorflow < 2.0. Please pass " "error.")
"capture_session=True in Interface to avoid " else:
"a 'Tensor is not an element of this graph.' " raise exception
"error.")
prediction = predict_fn(*processed_input)
if len(self.output_interfaces) / \ if len(self.output_interfaces) / \
len(self.predict) == 1: len(self.predict) == 1:
@ -209,8 +196,6 @@ class Interface:
""" """
# if validate and not self.validate_flag: # if validate and not self.validate_flag:
# self.validate() # self.validate()
context = self.load_fn() if self.load_fn else None
self.context = context
if self.capture_session: if self.capture_session:
import tensorflow as tf import tensorflow as tf

BIN
dist/gradio-0.9.4.tar.gz vendored Normal file

Binary file not shown.

View File

@ -1,6 +1,6 @@
Metadata-Version: 1.0 Metadata-Version: 1.0
Name: gradio Name: gradio
Version: 0.9.3 Version: 0.9.4
Summary: Python library for easily interacting with trained machine learning models Summary: Python library for easily interacting with trained machine learning models
Home-page: https://github.com/abidlabs/gradio Home-page: https://github.com/abidlabs/gradio
Author: Abubakar Abid Author: Abubakar Abid

View File

@ -2,7 +2,6 @@ MANIFEST.in
README.md README.md
setup.py setup.py
gradio/__init__.py gradio/__init__.py
gradio/hosted.py
gradio/inputs.py gradio/inputs.py
gradio/interface.py gradio/interface.py
gradio/networking.py gradio/networking.py

View File

@ -29,8 +29,9 @@ class Interface:
""" """
def __init__(self, fn, inputs, outputs, saliency=None, verbose=False, examples=None, def __init__(self, fn, inputs, outputs, saliency=None, verbose=False, examples=None,
live=False, show_input=True, show_output=True, capture_session=False, title=None, description=None, live=False, show_input=True, show_output=True,
server_name=LOCALHOST_IP): load_fn=None, capture_session=False, title=None, description=None,
thumbnail=None, server_name=LOCALHOST_IP):
""" """
:param fn: a function that will process the input panel data from the interface and return the output panel data. :param fn: a function that will process the input panel data from the interface and return the output panel data.
:param inputs: a string or `AbstractInput` representing the input interface. :param inputs: a string or `AbstractInput` representing the input interface.
@ -79,6 +80,7 @@ class Interface:
self.server_name = server_name self.server_name = server_name
self.title = title self.title = title
self.description = description self.description = description
self.thumbnail = thumbnail
self.examples = examples self.examples = examples
def get_config_file(self): def get_config_file(self):
@ -95,6 +97,7 @@ class Interface:
"show_output": self.show_output, "show_output": self.show_output,
"title": self.title, "title": self.title,
"description": self.description, "description": self.description,
"thumbnail": self.thumbnail
} }
def process(self, raw_input): def process(self, raw_input):

View File

@ -5,7 +5,7 @@ except ImportError:
setup( setup(
name='gradio', name='gradio',
version='0.9.3', version='0.9.4',
include_package_data=True, include_package_data=True,
description='Python library for easily interacting with trained machine learning models', description='Python library for easily interacting with trained machine learning models',
author='Abubakar Abid', author='Abubakar Abid',

34
size.sh
View File

@ -1,34 +0,0 @@
#!/bin/bash
#set -x
# Shows you the largest objects in your repo's pack file.
# Written for osx.
#
# @see https://stubbisms.wordpress.com/2009/07/10/git-script-to-show-largest-pack-objects-and-trim-your-waist-line/
# @author Antony Stubbs
# set the internal field separator to line break, so that we can iterate easily over the verify-pack output
IFS=$'\n';
# list all objects including their size, sort by size, take top 10
objects=`git verify-pack -v .git/objects/pack/pack-*.idx | grep -v chain | sort -k3nr | head`
echo "All sizes are in kB's. The pack column is the size of the object, compressed, inside the pack file."
output="size,pack,SHA,location"
allObjects=`git rev-list --all --objects`
for y in $objects
do
# extract the size in bytes
size=$((`echo $y | cut -f 5 -d ' '`/1024))
# extract the compressed size in bytes
compressedSize=$((`echo $y | cut -f 6 -d ' '`/1024))
# extract the SHA
sha=`echo $y | cut -f 1 -d ' '`
# find the objects location in the repository tree
other=`echo "${allObjects}" | grep $sha`
#lineBreak=`echo -e "\n"`
output="${output}\n${size},${compressedSize},${other}"
done
echo -e $output | column -t -s ', '