upgraded to 0.9.2

This commit is contained in:
Abubakar Abid 2020-06-17 23:02:39 -05:00
parent 2252191a75
commit 528a17c582
8 changed files with 25 additions and 15 deletions

View File

@ -17,7 +17,7 @@ import random
import time
from IPython import get_ipython
LOCALHOST_IP = "127.0.0.1"
LOCALHOST_IP = "0.0.0.0"
TRY_NUM_PORTS = 100
PKG_VERSION_URL = "https://gradio.app/api/pkg-version"
@ -29,7 +29,8 @@ class Interface:
"""
def __init__(self, fn, inputs, outputs, saliency=None, verbose=False,
live=False, show_input=True, show_output=True):
live=False, show_input=True, show_output=True,
load_fn=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 inputs: a string or `AbstractInput` representing the input interface.
@ -63,6 +64,8 @@ class Interface:
fn = [fn]
self.output_interfaces *= len(fn)
self.predict = fn
self.load_fn = load_fn
self.context = None
self.verbose = verbose
self.status = "OFF"
self.saliency = saliency
@ -70,6 +73,7 @@ class Interface:
self.show_input = show_input
self.show_output = show_output
self.flag_hash = random.getrandbits(32)
self.server_name = server_name
def update_config_file(self, output_directory):
config = {
@ -148,6 +152,8 @@ class Interface:
"""
# if validate and not self.validate_flag:
# self.validate()
context = self.load_fn() if self.load_fn else None
self.context = context
# If an existing interface is running with this instance, close it.
if self.status == "RUNNING":
@ -161,8 +167,8 @@ class Interface:
output_directory = tempfile.mkdtemp()
# Set up a port to serve the directory containing the static files with interface.
server_port, httpd = networking.start_simple_server(self, output_directory)
path_to_local_server = "http://localhost:{}/".format(server_port)
server_port, httpd = networking.start_simple_server(self, output_directory, self.server_name)
path_to_local_server = "http://{}:{}/".format(self.server_name, server_port)
networking.build_template(output_directory)
self.update_config_file(output_directory)

View File

@ -20,7 +20,7 @@ INITIAL_PORT_VALUE = (
TRY_NUM_PORTS = (
100
) # Number of ports to try before giving up and throwing an exception.
LOCALHOST_NAME = "localhost"
LOCALHOST_NAME = "0.0.0.0"
GRADIO_API_SERVER = "https://api.gradio.app/v1/tunnel-request"
STATIC_TEMPLATE_LIB = pkg_resources.resource_filename("gradio", "templates/")
@ -109,7 +109,7 @@ def get_first_available_port(initial, final):
)
def serve_files_in_background(interface, port, directory_to_serve=None):
def serve_files_in_background(interface, port, directory_to_serve=None, server_name=LOCALHOST_NAME):
class HTTPHandler(SimpleHTTPRequestHandler):
"""This handler uses server.base_path instead of always using os.getcwd()"""
@ -139,7 +139,11 @@ def serve_files_in_background(interface, port, directory_to_serve=None):
processed_input = [input_interface.preprocess(raw_input[i]) for i, input_interface in enumerate(interface.input_interfaces)]
predictions = []
for predict_fn in interface.predict:
prediction = predict_fn(*processed_input)
if interface.context:
prediction = predict_fn(*processed_input,
interface.context)
else:
prediction = predict_fn(*processed_input)
if len(interface.output_interfaces) / len(interface.predict) == 1:
prediction = [prediction]
predictions.extend(prediction)
@ -260,7 +264,7 @@ def serve_files_in_background(interface, port, directory_to_serve=None):
self.base_path = base_path
BaseHTTPServer.__init__(self, server_address, RequestHandlerClass)
httpd = HTTPServer(directory_to_serve, (LOCALHOST_NAME, port))
httpd = HTTPServer(directory_to_serve, (server_name, port))
# Now loop forever
def serve_forever():
@ -277,11 +281,11 @@ def serve_files_in_background(interface, port, directory_to_serve=None):
return httpd
def start_simple_server(interface, directory_to_serve=None):
def start_simple_server(interface, directory_to_serve=None, server_name=None):
port = get_first_available_port(
INITIAL_PORT_VALUE, INITIAL_PORT_VALUE + TRY_NUM_PORTS
)
httpd = serve_files_in_background(interface, port, directory_to_serve)
httpd = serve_files_in_background(interface, port, directory_to_serve, server_name)
return port, httpd

Binary file not shown.

Binary file not shown.

View File

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

View File

@ -17,7 +17,7 @@ import random
import time
from IPython import get_ipython
LOCALHOST_IP = "127.0.0.1"
LOCALHOST_IP = "0.0.0.0"
TRY_NUM_PORTS = 100
PKG_VERSION_URL = "https://gradio.app/api/pkg-version"
@ -30,7 +30,7 @@ class Interface:
def __init__(self, fn, inputs, outputs, saliency=None, verbose=False,
live=False, show_input=True, show_output=True,
load_fn=None, server_name=None):
load_fn=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 inputs: a string or `AbstractInput` representing the input interface.

View File

@ -20,7 +20,7 @@ INITIAL_PORT_VALUE = (
TRY_NUM_PORTS = (
100
) # Number of ports to try before giving up and throwing an exception.
LOCALHOST_NAME = "localhost"
LOCALHOST_NAME = "0.0.0.0"
GRADIO_API_SERVER = "https://api.gradio.app/v1/tunnel-request"
STATIC_TEMPLATE_LIB = pkg_resources.resource_filename("gradio", "templates/")

View File

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