diff --git a/build/lib/gradio/inputs.py b/build/lib/gradio/inputs.py index ea7304b1f0..7ff2589d8a 100644 --- a/build/lib/gradio/inputs.py +++ b/build/lib/gradio/inputs.py @@ -241,12 +241,15 @@ class Image(AbstractInput): def __init__(self, shape=(224, 224), image_mode='RGB', label=None): ''' Parameters: - shape (Tuple[int, int]): shape to crop and resize image to. + 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. label (str): component name in interface. ''' - self.image_width = shape[0] - self.image_height = shape[1] + if shape is None: + self.image_width, self.image_height = None, None + else: + self.image_width = shape[0] + self.image_height = shape[1] self.image_mode = image_mode super().__init__(label) @@ -272,9 +275,13 @@ class Image(AbstractInput): with warnings.catch_warnings(): warnings.simplefilter("ignore") im = im.convert(self.image_mode) - + image_width, image_height = self.image_width, self.image_height + if image_width is None: + image_width = im.size[0] + if image_height is None: + image_height = im.size[1] im = preprocessing_utils.resize_and_crop( - im, (self.image_width, self.image_height)) + im, (image_width, image_height)) return np.array(im) def process_example(self, example): diff --git a/build/lib/gradio/interface.py b/build/lib/gradio/interface.py index 8e8c162197..542927a096 100644 --- a/build/lib/gradio/interface.py +++ b/build/lib/gradio/interface.py @@ -40,7 +40,7 @@ class Interface: 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, - thumbnail=None, server_name=networking.LOCALHOST_NAME): + thumbnail=None, server_port=None, server_name=networking.LOCALHOST_NAME): """ Parameters: fn (Callable): the function to wrap an interface around. @@ -97,7 +97,7 @@ class Interface: self.description = description self.thumbnail = thumbnail self.examples = examples - self.server_port = None + self.server_port = server_port self.simple_server = None Interface.instances.add(self) @@ -270,7 +270,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, self.server_name) + server_port, httpd = networking.start_simple_server(self, output_directory, self.server_name, + server_port=self.server_port) path_to_local_server = "http://{}:{}/".format(self.server_name, server_port) networking.build_template(output_directory) diff --git a/build/lib/gradio/networking.py b/build/lib/gradio/networking.py index a7b366b76c..9b69b9ba50 100644 --- a/build/lib/gradio/networking.py +++ b/build/lib/gradio/networking.py @@ -18,13 +18,12 @@ import sys import analytics -INITIAL_PORT_VALUE = ( - 7860 -) # The http server will try to open on port 7860. If not available, 7861, 7862, etc. -TRY_NUM_PORTS = ( - 100 -) # Number of ports to try before giving up and throwing an exception. -LOCALHOST_NAME = os.getenv('GRADIO_SERVER_NAME', "127.0.0.1") +INITIAL_PORT_VALUE = int(os.getenv( + 'GRADIO_SERVER_PORT', "7860")) # The http server will try to open on port 7860. If not available, 7861, 7862, etc. +TRY_NUM_PORTS = int(os.getenv( + 'GRADIO_NUM_PORTS', "100")) # Number of ports to try before giving up and throwing an exception. +LOCALHOST_NAME = os.getenv( + 'GRADIO_SERVER_NAME', "127.0.0.1") GRADIO_API_SERVER = "https://api.gradio.app/v1/tunnel-request" STATIC_TEMPLATE_LIB = pkg_resources.resource_filename("gradio", "templates/") @@ -231,9 +230,11 @@ def serve_files_in_background(interface, port, directory_to_serve=None, server_n return httpd -def start_simple_server(interface, directory_to_serve=None, server_name=None): +def start_simple_server(interface, directory_to_serve=None, server_name=None, server_port=None): + if server_port is None: + server_port = INITIAL_PORT_VALUE port = get_first_available_port( - INITIAL_PORT_VALUE, INITIAL_PORT_VALUE + TRY_NUM_PORTS + server_port, server_port + TRY_NUM_PORTS ) httpd = serve_files_in_background(interface, port, directory_to_serve, server_name) return port, httpd diff --git a/gradio.egg-info/PKG-INFO b/gradio.egg-info/PKG-INFO index 52c9d4d86e..a938b7e5fd 100644 --- a/gradio.egg-info/PKG-INFO +++ b/gradio.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 1.0 Name: gradio -Version: 1.0.0 +Version: 1.0.1 Summary: Python library for easily interacting with trained machine learning models Home-page: https://github.com/gradio-app/gradio-UI Author: Abubakar Abid