diff --git a/build/lib/gradio/cors.py b/build/lib/gradio/cors.py new file mode 100644 index 0000000000..7b153b9ab4 --- /dev/null +++ b/build/lib/gradio/cors.py @@ -0,0 +1,43 @@ +import SimpleHTTPServer +class CORSHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): + def send_head(self): + """Common code for GET and HEAD commands. + This sends the response code and MIME headers. + Return value is either a file object (which has to be copied + to the outputfile by the caller unless the command was HEAD, + and must be closed by the caller under all circumstances), or + None, in which case the caller has nothing further to do. + """ + path = self.translate_path(self.path) + f = None + if os.path.isdir(path): + if not self.path.endswith('/'): + # redirect browser - doing basically what apache does + self.send_response(301) + self.send_header("Location", self.path + "/") + self.end_headers() + return None + for index in "index.html", "index.htm": + index = os.path.join(path, index) + if os.path.exists(index): + path = index + break + else: + return self.list_directory(path) + ctype = self.guess_type(path) + try: + # Always read in binary mode. Opening files in text mode may cause + # newline translations, making the actual size of the content + # transmitted *less* than the content-length! + f = open(path, 'rb') + except IOError: + self.send_error(404, "File not found") + return None + self.send_response(200) + self.send_header("Content-type", ctype) + fs = os.fstat(f.fileno()) + self.send_header("Content-Length", str(fs[6])) + self.send_header("Last-Modified", self.date_time_string(fs.st_mtime)) + self.send_header("Access-Control-Allow-Origin", "*") + self.end_headers() + return f diff --git a/build/lib/gradio/generate_docs.py b/build/lib/gradio/generate_docs.py index 6cce3115e9..30a798666b 100644 --- a/build/lib/gradio/generate_docs.py +++ b/build/lib/gradio/generate_docs.py @@ -39,6 +39,8 @@ def document(cls_set): inp = {} inp["name"] = cls.__name__ doc = inspect.getdoc(cls) + if doc.startswith("DEPRECATED"): + continue inp["doc"] = "\n".join(doc.split("\n")[:-1]) inp["type"] = doc.split("\n")[-1].split("type: ")[-1] inp["params"], inp["params_doc"] = get_params(cls.__init__) diff --git a/build/lib/gradio/inputs.py b/build/lib/gradio/inputs.py index 9e29b64ea5..401c8cda3e 100644 --- a/build/lib/gradio/inputs.py +++ b/build/lib/gradio/inputs.py @@ -206,7 +206,7 @@ class Radio(InputComponent): class Dropdown(InputComponent): """ Component creates a dropdown of which only one can be selected. Provides string representing selected choice as an argument to the wrapped function. - Input type: str + Input type: Union[str, int] """ def __init__(self, choices, type="value", label=None): diff --git a/build/lib/gradio/interface.py b/build/lib/gradio/interface.py index 13dd8ded21..62e2ca0185 100644 --- a/build/lib/gradio/interface.py +++ b/build/lib/gradio/interface.py @@ -58,8 +58,6 @@ class Interface: verbose (bool): whether to print detailed information during launch. examples (List[List[Any]]): sample inputs for the function; if provided, appears below the UI components and can be used to populate the interface. Should be nested list, in which the outer list consists of samples and each inner list consists of an input corresponding to each input component. live (bool): whether the interface should automatically reload on change. - show_input (bool): if False, removes the input from the interface and underlays it in the output. - show_output (bool): if False, removes the output from the interface and overlays it in the input. capture_session (bool): if True, captures the default graph and session (needed for Tensorflow 1.x) title (str): a title for the interface; if provided, appears above the input and output components. description (str): a description for the interface; if provided, appears above the input and output components. diff --git a/build/lib/gradio/networking.py b/build/lib/gradio/networking.py index 4e518a1e94..858e148c0f 100644 --- a/build/lib/gradio/networking.py +++ b/build/lib/gradio/networking.py @@ -151,6 +151,12 @@ def serve_files_in_background(interface, port, directory_to_serve=None, server_n self.send_header("Content-type", "application/json") self.end_headers() + def end_headers(self): + self.send_header('Access-Control-Allow-Origin', '*') + self.send_header('Access-Control-Allow-Methods', 'GET, POST') + self.send_header('Cache-Control', 'no-store, no-cache, must-revalidate') + return super(HTTPHandler, self).end_headers() + def translate_path(self, path): path = SimpleHTTPRequestHandler.translate_path(self, path) relpath = os.path.relpath(path, os.getcwd()) diff --git a/gradio/generate_docs.py b/gradio/generate_docs.py index 6cce3115e9..30a798666b 100644 --- a/gradio/generate_docs.py +++ b/gradio/generate_docs.py @@ -39,6 +39,8 @@ def document(cls_set): inp = {} inp["name"] = cls.__name__ doc = inspect.getdoc(cls) + if doc.startswith("DEPRECATED"): + continue inp["doc"] = "\n".join(doc.split("\n")[:-1]) inp["type"] = doc.split("\n")[-1].split("type: ")[-1] inp["params"], inp["params_doc"] = get_params(cls.__init__) diff --git a/gradio/inputs.py b/gradio/inputs.py index 9e29b64ea5..401c8cda3e 100644 --- a/gradio/inputs.py +++ b/gradio/inputs.py @@ -206,7 +206,7 @@ class Radio(InputComponent): class Dropdown(InputComponent): """ Component creates a dropdown of which only one can be selected. Provides string representing selected choice as an argument to the wrapped function. - Input type: str + Input type: Union[str, int] """ def __init__(self, choices, type="value", label=None): diff --git a/gradio/interface.py b/gradio/interface.py index 13dd8ded21..62e2ca0185 100644 --- a/gradio/interface.py +++ b/gradio/interface.py @@ -58,8 +58,6 @@ class Interface: verbose (bool): whether to print detailed information during launch. examples (List[List[Any]]): sample inputs for the function; if provided, appears below the UI components and can be used to populate the interface. Should be nested list, in which the outer list consists of samples and each inner list consists of an input corresponding to each input component. live (bool): whether the interface should automatically reload on change. - show_input (bool): if False, removes the input from the interface and underlays it in the output. - show_output (bool): if False, removes the output from the interface and overlays it in the input. capture_session (bool): if True, captures the default graph and session (needed for Tensorflow 1.x) title (str): a title for the interface; if provided, appears above the input and output components. description (str): a description for the interface; if provided, appears above the input and output components. diff --git a/gradio/networking.py b/gradio/networking.py index 4e518a1e94..858e148c0f 100644 --- a/gradio/networking.py +++ b/gradio/networking.py @@ -151,6 +151,12 @@ def serve_files_in_background(interface, port, directory_to_serve=None, server_n self.send_header("Content-type", "application/json") self.end_headers() + def end_headers(self): + self.send_header('Access-Control-Allow-Origin', '*') + self.send_header('Access-Control-Allow-Methods', 'GET, POST') + self.send_header('Cache-Control', 'no-store, no-cache, must-revalidate') + return super(HTTPHandler, self).end_headers() + def translate_path(self, path): path = SimpleHTTPRequestHandler.translate_path(self, path) relpath = os.path.relpath(path, os.getcwd())