How to use the gradio.networking.build_template function in gradio

To help you get started, we’ve selected a few gradio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gradio-app / gradio-UI / test / test_networking.py View on Github external
def test_set_sample_data(self):
        test_array = ["test1", "test2", "test3"]
        temp_dir = tempfile.mkdtemp()
        inp = inputs.Sketchpad()
        out = outputs.Label()
        networking.build_template(temp_dir, inp, out)
        networking.set_sample_data_in_config_file(temp_dir, test_array)
        # We need to come up with a better way so that the config file isn't invalid json unless
        # the following parameters are set... (TODO: abidlabs)
        networking.set_always_flagged_in_config_file(temp_dir, False)
        networking.set_disabled_in_config_file(temp_dir, False)
        config_file = os.path.join(temp_dir, 'static/config.json')
        with open(config_file) as json_file:
            data = json.load(json_file)
            self.assertTrue(test_array == data["sample_inputs"])
github gradio-app / gradio-UI / build / lib / gradio / interface.py View on Github external
# If an existing interface is running with this instance, close it.
        if self.status == self.STATUS_TYPES["RUNNING"]:
            if self.verbose:
                print("Closing existing server...")
            if self.simple_server is not None:
                try:
                    networking.close_server(self.simple_server)
                except OSError:
                    pass

        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)
        networking.build_template(
            output_directory, self.input_interface, self.output_interface
        )

        networking.set_interface_types_in_config_file(
            output_directory,
            self.input_interface.__class__.__name__.lower(),
            self.output_interface.__class__.__name__.lower(),
        )
        self.status = self.STATUS_TYPES["RUNNING"]
        self.simple_server = httpd

        is_colab = False
        try:  # Check if running interactively using ipython.
            from_ipynb = get_ipython()
            if "google.colab" in str(from_ipynb):
                is_colab = True
github gradio-app / gradio-UI / gradio / interface.py View on Github external
# If an existing interface is running with this instance, close it.
        if self.status == self.STATUS_TYPES["RUNNING"]:
            if self.verbose:
                print("Closing existing server...")
            if self.simple_server is not None:
                try:
                    networking.close_server(self.simple_server)
                except OSError:
                    pass

        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)
        networking.build_template(
            output_directory, self.input_interface, self.output_interface
        )

        self.update_config_file(output_directory)

        self.status = self.STATUS_TYPES["RUNNING"]
        self.simple_server = httpd

        is_colab = False
        try:  # Check if running interactively using ipython.
            from_ipynb = get_ipython()
            if "google.colab" in str(from_ipynb):
                is_colab = True
        except NameError:
            pass