class_docstr: Creates a file explorer component that allows users to browse and select files on the machine hosting the Gradio app.
  Preprocessing: passes the selected file or directory as a {str} path (relative to root) or {list[str}} depending on `file_count`
  Postprocessing: expects function to return a {str} path to a file, or {List[str]} consisting of paths to files.
  Examples-format: a {str} path to a local file that populates the component.
  Demos: zip_to_json, zip_files
class_docstr_tok: ["Creates","a","file","explorer","component","that","allows","users","to","browse","and","select","files","on","the","machine","hosting","the","Gradio","app",".","Preprocessing",":","passes","the","selected","file","or","directory","as","a","{","str","}","path","(","relative","to","root",")","or","{","list","[","str","}","}","depending","on","`","file_count","`","Postprocessing",":","expects","function","to","return","a","{","str","}","path","to","a","file",",","or","{","List","[","str","]","}","consisting","of","paths","to","files",".","Examples-format",":","a","{","str","}","path","to","a","local","file","that","populates","the","component",".","Demos",":","zip_to_json",",","zip_files"]
docstr: Parameters:
      glob: The glob-style pattern used to select which files to display, e.g. "*" to match all files, "*.png" to match all .png files, "**/*.txt" to match any .txt file in any subdirectory, etc. The default value matches all files and folders recursively. See the Python glob documentation at https://docs.python.org/3/library/glob.html for more information.
      value: The file (or list of files, depending on the `file_count` parameter) to show as "selected" when the component is first loaded. If a callable is provided, it will be called when the app loads to set the initial value of the component. If not provided, no files are shown as selected.
      file_count: Whether to allow single or multiple files to be selected. If "single", the component will return a single absolute file path as a string. If "multiple", the component will return a list of absolute file paths as a list of strings.
      root_dir: Path to root directory to select files from. If not provided, defaults to current working directory.
      ignore_glob: The glob-tyle pattern that will be used to exclude files from the list. For example, "*.py" will exclude all .py files from the list. See the Python glob documentation at https://docs.python.org/3/library/glob.html for more information.
      label: The label for this component. Appears above the component and is also used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component is assigned to.
      every: If `value` is a callable, run the function 'every' number of seconds while the client connection is open. Has no effect otherwise. Queue must be enabled. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute.
      show_label: if True, will display label.
      container: If True, will place the component in a container - providing some extra padding around the border.
      scale: relative width compared to adjacent Components in a Row. For example, if Component A has scale=2, and Component B has scale=1, A will be twice as wide as B. Should be an integer.
      min_width: minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.
      height: The maximum height of the file component, specified in pixels if a number is passed, or in CSS units if a string is passed. If more files are uploaded than can fit in the height, a scrollbar will appear.
      interactive: if True, will allow users to upload a file; if False, can only be used to display files. If not provided, this is inferred based on whether the component is used as an input or output.
      visible: If False, component will be hidden.
      elem_id: An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.
      elem_classes: An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.
      render: If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.
docstr_tok: ["Parameters",":","glob",":","The","glob-style","pattern","used","to","select","which","files","to","display",",","e.g",".","``","*","''","to","match","all","files",",","``","*",".png","''","to","match","all",".png","files",",","``","*","*","\/","*",".txt","''","to","match","any",".txt","file","in","any","subdirectory",",","etc",".","The","default","value","matches","all","files","and","folders","recursively",".","See","the","Python","glob","documentation","at","https",":","\/\/docs.python.org\/3\/library\/glob.html","for","more","information",".","value",":","The","file","(","or","list","of","files",",","depending","on","the","`","file_count","`","parameter",")","to","show","as","``","selected","''","when","the","component","is","first","loaded",".","If","a","callable","is","provided",",","it","will","be","called","when","the","app","loads","to","set","the","initial","value","of","the","component",".","If","not","provided",",","no","files","are","shown","as","selected",".","file_count",":","Whether","to","allow","single","or","multiple","files","to","be","selected",".","If","``","single","''",",","the","component","will","return","a","single","absolute","file","path","as","a","string",".","If","``","multiple","''",",","the","component","will","return","a","list","of","absolute","file","paths","as","a","list","of","strings",".","root_dir",":","Path","to","root","directory","to","select","files","from",".","If","not","provided",",","defaults","to","current","working","directory",".","ignore_glob",":","The","glob-tyle","pattern","that","will","be","used","to","exclude","files","from","the","list",".","For","example",",","``","*",".py","''","will","exclude","all",".py","files","from","the","list",".","See","the","Python","glob","documentation","at","https",":","\/\/docs.python.org\/3\/library\/glob.html","for","more","information",".","label",":","The","label","for","this","component",".","Appears","above","the","component","and","is","also","used","as","the","header","if","there","are","a","table","of","examples","for","this","component",".","If","None","and","used","in","a","`","gr.Interface","`",",","the","label","will","be","the","name","of","the","parameter","this","component","is","assigned","to",".","every",":","If","`","value","`","is","a","callable",",","run","the","function","'every","'","number","of","seconds","while","the","client","connection","is","open",".","Has","no","effect","otherwise",".","Queue","must","be","enabled",".","The","event","can","be","accessed","(","e.g",".","to","cancel","it",")","via","this","component","'s",".load_event","attribute",".","show_label",":","if","True",",","will","display","label",".","container",":","If","True",",","will","place","the","component","in","a","container","-","providing","some","extra","padding","around","the","border",".","scale",":","relative","width","compared","to","adjacent","Components","in","a","Row",".","For","example",",","if","Component","A","has","scale=2",",","and","Component","B","has","scale=1",",","A","will","be","twice","as","wide","as","B",".","Should","be","an","integer",".","min_width",":","minimum","pixel","width",",","will","wrap","if","not","sufficient","screen","space","to","satisfy","this","value",".","If","a","certain","scale","value","results","in","this","Component","being","narrower","than","min_width",",","the","min_width","parameter","will","be","respected","first",".","height",":","The","maximum","height","of","the","file","component",",","specified","in","pixels","if","a","number","is","passed",",","or","in","CSS","units","if","a","string","is","passed",".","If","more","files","are","uploaded","than","can","fit","in","the","height",",","a","scrollbar","will","appear",".","interactive",":","if","True",",","will","allow","users","to","upload","a","file",";","if","False",",","can","only","be","used","to","display","files",".","If","not","provided",",","this","is","inferred","based","on","whether","the","component","is","used","as","an","input","or","output",".","visible",":","If","False",",","component","will","be","hidden",".","elem_id",":","An","optional","string","that","is","assigned","as","the","id","of","this","component","in","the","HTML","DOM",".","Can","be","used","for","targeting","CSS","styles",".","elem_classes",":","An","optional","list","of","strings","that","are","assigned","as","the","classes","of","this","component","in","the","HTML","DOM",".","Can","be","used","for","targeting","CSS","styles",".","render",":","If","False",",","component","will","not","render","be","rendered","in","the","Blocks","context",".","Should","be","used","if","the","intention","is","to","assign","event","listeners","now","but","render","the","component","later","."]
code: def __init__(
      self,
      glob: str = "**/*.*",
      *,
      value: str | list[str] | Callable | None = None,
      file_count: Literal["single", "multiple"] = "multiple",
      root_dir: str | Path = ".",
      ignore_glob: str | None = None,
      label: str | None = None,
      every: float | None = None,
      show_label: bool | None = None,
      container: bool = True,
      scale: int | None = None,
      min_width: int = 160,
      height: int | float | None = None,
      interactive: bool | None = None,
      visible: bool = True,
      elem_id: str | None = None,
      elem_classes: list[str] | str | None = None,
      render: bool = True,
      root: None = None,
  ):
      """
      Parameters:
          glob: The glob-style pattern used to select which files to display, e.g. "*" to match all files, "*.png" to match all .png files, "**/*.txt" to match any .txt file in any subdirectory, etc. The default value matches all files and folders recursively. See the Python glob documentation at https://docs.python.org/3/library/glob.html for more information.
          value: The file (or list of files, depending on the `file_count` parameter) to show as "selected" when the component is first loaded. If a callable is provided, it will be called when the app loads to set the initial value of the component. If not provided, no files are shown as selected.
          file_count: Whether to allow single or multiple files to be selected. If "single", the component will return a single absolute file path as a string. If "multiple", the component will return a list of absolute file paths as a list of strings.
          root_dir: Path to root directory to select files from. If not provided, defaults to current working directory.
          ignore_glob: The glob-tyle pattern that will be used to exclude files from the list. For example, "*.py" will exclude all .py files from the list. See the Python glob documentation at https://docs.python.org/3/library/glob.html for more information.
          label: The label for this component. Appears above the component and is also used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component is assigned to.
          every: If `value` is a callable, run the function 'every' number of seconds while the client connection is open. Has no effect otherwise. Queue must be enabled. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute.
          show_label: if True, will display label.
          container: If True, will place the component in a container - providing some extra padding around the border.
          scale: relative width compared to adjacent Components in a Row. For example, if Component A has scale=2, and Component B has scale=1, A will be twice as wide as B. Should be an integer.
          min_width: minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.
          height: The maximum height of the file component, specified in pixels if a number is passed, or in CSS units if a string is passed. If more files are uploaded than can fit in the height, a scrollbar will appear.
          interactive: if True, will allow users to upload a file; if False, can only be used to display files. If not provided, this is inferred based on whether the component is used as an input or output.
          visible: If False, component will be hidden.
          elem_id: An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.
          elem_classes: An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.
          render: If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.
      """
      if root is not None:
          warnings.warn(
              "The `root` parameter has been deprecated. Please use `root_dir` instead."
          )
          root_dir = root
          self._constructor_args[0]["root_dir"] = root
      self.root_dir = os.path.abspath(root_dir)
      self.glob = glob
      self.ignore_glob = ignore_glob
      valid_file_count = ["single", "multiple", "directory"]
      if file_count not in valid_file_count:
          raise ValueError(
              f"Invalid value for parameter `type`: {type}. Please choose from one of: {valid_file_count}"
          )
      self.file_count = file_count
      self.height = height
  
      super().__init__(
          label=label,
          every=every,
          show_label=show_label,
          container=container,
          scale=scale,
          min_width=min_width,
          interactive=interactive,
          visible=visible,
          elem_id=elem_id,
          elem_classes=elem_classes,
          render=render,
          value=value,
      )
  
imports: from __future__ import annotations
  import itertools
  import os
  import re
  import warnings
  from pathlib import Path
  from typing import Any, Callable, List, Literal
  from gradio_client.documentation import document, set_documentation_group
  from gradio.components.base import Component, server
  from gradio.data_classes import GradioRootModel
label_desc: Use image node_id 1 to create a new FileExplorer object from inherited base classes: Component with example: obj = FileExplorer(glob)