Blocks-Backend-Components-v2

- Resolve Components imports in inputs and outputs
This commit is contained in:
Ömer Faruk Özdemir 2022-03-22 16:40:06 +03:00
parent 21b6dcc39c
commit d9cd56ec3b
2 changed files with 57 additions and 61 deletions

View File

@ -9,25 +9,23 @@ from __future__ import annotations
import warnings
from typing import Any, List, Optional, Tuple
from gradio.components import (
Audio,
Checkbox,
CheckboxGroup,
Dataframe,
Dropdown,
File,
Image,
Number,
Radio,
Slider,
State,
Textbox,
Timeseries,
Video,
)
from gradio.components import Audio as C_Audio
from gradio.components import Checkbox as C_Checkbox
from gradio.components import CheckboxGroup as C_CheckboxGroup
from gradio.components import Dataframe as C_Dataframe
from gradio.components import Dropdown as C_Dropdown
from gradio.components import File as C_File
from gradio.components import Image as C_Image
from gradio.components import Number as C_Number
from gradio.components import Radio as C_Radio
from gradio.components import Slider as C_Slider
from gradio.components import State as C_State
from gradio.components import Textbox as C_Textbox
from gradio.components import Timeseries as C_Timeseries
from gradio.components import Video as C_Video
class Textbox(Textbox):
class Textbox(C_Textbox):
def __init__(
self,
lines: int = 1,
@ -53,7 +51,7 @@ class Textbox(Textbox):
)
class Number(Number):
class Number(C_Number):
"""
Component creates a field for user to enter numeric input. Provides a number as an argument to the wrapped function.
Input type: float
@ -79,7 +77,7 @@ class Number(Number):
super().__init__(default_value=default, label=label, optional=optional)
class Slider(Slider):
class Slider(C_Slider):
"""
Component creates a slider that ranges from `minimum` to `maximum`. Provides a number as an argument to the wrapped function.
Input type: float
@ -119,7 +117,7 @@ class Slider(Slider):
)
class Checkbox(Checkbox):
class Checkbox(C_Checkbox):
"""
Component creates a checkbox that can be set to `True` or `False`. Provides a boolean as an argument to the wrapped function.
Input type: bool
@ -145,7 +143,7 @@ class Checkbox(Checkbox):
super().__init__(default_value=default, label=label, optional=optional)
class CheckboxGroup(CheckboxGroup):
class CheckboxGroup(C_CheckboxGroup):
"""
Component creates a set of checkboxes of which a subset can be selected. Provides a list of strings representing the selected choices as an argument to the wrapped function.
Input type: Union[List[str], List[int]]
@ -181,7 +179,7 @@ class CheckboxGroup(CheckboxGroup):
)
class Radio(Radio):
class Radio(C_Radio):
"""
Component creates a set of radio buttons of which only one can be selected. Provides string representing selected choice as an argument to the wrapped function.
Input type: Union[str, int]
@ -217,7 +215,7 @@ class Radio(Radio):
)
class Dropdown(Dropdown):
class Dropdown(C_Dropdown):
"""
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: Union[str, int]
@ -253,7 +251,7 @@ class Dropdown(Dropdown):
)
class Image(Image):
class Image(C_Image):
"""
Component creates an image upload box with editing capabilities.
Input type: Union[numpy.array, PIL.Image, file-object]
@ -298,7 +296,7 @@ class Image(Image):
)
class Video(Video):
class Video(C_Video):
"""
Component creates a video file upload that is converted to a file path.
@ -327,7 +325,7 @@ class Video(Video):
super().__init__(type=type, source=source, label=label, optional=optional)
class Audio(Audio):
class Audio(C_Audio):
"""
Component accepts audio input files.
Input type: Union[Tuple[int, numpy.array], file-object, numpy.array]
@ -355,7 +353,7 @@ class Audio(Audio):
super().__init__(source=source, type=type, label=label, optional=optional)
class File(File):
class File(C_File):
"""
Component accepts generic file uploads.
Input type: Union[file-object, bytes, List[Union[file-object, bytes]]]
@ -391,7 +389,7 @@ class File(File):
)
class Dataframe(Dataframe):
class Dataframe(C_Dataframe):
"""
Component accepts 2D input through a spreadsheet interface.
Input type: Union[pandas.DataFrame, numpy.array, List[Union[str, float]], List[List[Union[str, float]]]]
@ -439,7 +437,7 @@ class Dataframe(Dataframe):
)
class Timeseries(Timeseries):
class Timeseries(C_Timeseries):
"""
Component accepts pandas.DataFrame uploaded as a timeseries csv file.
Input type: pandas.DataFrame
@ -467,7 +465,7 @@ class Timeseries(Timeseries):
super().__init__(x=x, y=y, label=label, optional=optional)
class State(State):
class State(C_State):
"""
Special hidden component that stores state across runs of the interface.
Input type: Any

View File

@ -9,26 +9,24 @@ from __future__ import annotations
import warnings
from typing import Dict, List, Optional
from gradio.components import (
HTML,
JSON,
Audio,
Carousel,
Chatbot,
Component,
Dataframe,
File,
HighlightedText,
Image,
Label,
State,
Textbox,
Timeseries,
Video,
)
from gradio.components import HTML as C_HTML
from gradio.components import JSON as C_JSON
from gradio.components import Audio as C_Audio
from gradio.components import Carousel as C_Carousel
from gradio.components import Chatbot as C_Chatbot
from gradio.components import Component as Component
from gradio.components import Dataframe as C_Dataframe
from gradio.components import File as C_File
from gradio.components import HighlightedText as C_HighlightedText
from gradio.components import Image as C_Image
from gradio.components import Label as C_Label
from gradio.components import State as C_State
from gradio.components import Textbox as C_Textbox
from gradio.components import Timeseries as C_Timeseries
from gradio.components import Video as C_Video
class Textbox(Textbox):
class Textbox(C_Textbox):
def __init__(
self,
type: str = "auto",
@ -41,7 +39,7 @@ class Textbox(Textbox):
super().__init__(label=label, type=type)
class Image(Image):
class Image(C_Image):
"""
Component displays an output image.
Output type: Union[numpy.array, PIL.Image, str, matplotlib.pyplot, Tuple[Union[numpy.array, PIL.Image, str], List[Tuple[str, float, float, float, float]]]]
@ -64,7 +62,7 @@ class Image(Image):
super().__init__(type=type, label=label, plot=plot)
class Video(Video):
class Video(C_Video):
"""
Used for video output.
Output type: filepath
@ -84,7 +82,7 @@ class Video(Video):
super().__init__(type=type, label=label)
class Audio(Audio):
class Audio(C_Audio):
"""
Creates an audio player that plays the output audio.
Output type: Union[Tuple[int, numpy.array], str]
@ -104,7 +102,7 @@ class Audio(Audio):
super().__init__(type=type, label=label)
class File(File):
class File(C_File):
"""
Used for file output.
Output type: Union[file-like, str]
@ -123,7 +121,7 @@ class File(File):
super().__init__(label=label)
class Dataframe(Dataframe):
class Dataframe(C_Dataframe):
"""
Component displays 2D output through a spreadsheet interface.
Output type: Union[pandas.DataFrame, numpy.array, List[Union[str, float]], List[List[Union[str, float]]]]
@ -162,7 +160,7 @@ class Dataframe(Dataframe):
)
class Timeseries(Timeseries):
class Timeseries(C_Timeseries):
"""
Component accepts pandas.DataFrame.
Output type: pandas.DataFrame
@ -185,7 +183,7 @@ class Timeseries(Timeseries):
super().__init__(x=x, y=y, label=label)
class State(State):
class State(C_State):
"""
Special hidden component that stores state across runs of the interface.
Output type: Any
@ -204,7 +202,7 @@ class State(State):
super().__init__(label=label)
class Label(Label):
class Label(C_Label):
"""
Component outputs a classification label, along with confidence scores of top categories if provided. Confidence scores are represented as a dictionary mapping labels to scores between 0 and 1.
Output type: Union[Dict[str, float], str, int, float]
@ -251,7 +249,7 @@ class KeyValues:
)
class HighlightedText(HighlightedText):
class HighlightedText(C_HighlightedText):
"""
Component creates text that contains spans that are highlighted by category or numerical value.
Output is represent as a list of Tuple pairs, where the first element represents the span of text represented by the tuple, and the second element represents the category or value of the text.
@ -278,7 +276,7 @@ class HighlightedText(HighlightedText):
super().__init__(color_map=color_map, label=label, show_legend=show_legend)
class JSON(JSON):
class JSON(C_JSON):
"""
Used for JSON output. Expects a JSON string or a Python object that is JSON serializable.
Output type: Union[str, Any]
@ -297,7 +295,7 @@ class JSON(JSON):
super().__init__(label=label)
class HTML(HTML):
class HTML(C_HTML):
"""
Used for HTML output. Expects an HTML valid string.
Output type: str
@ -312,7 +310,7 @@ class HTML(HTML):
super().__init__(label=label)
class Carousel(Carousel):
class Carousel(C_Carousel):
"""
Component displays a set of output components that can be scrolled through.
Output type: List[List[Any]]
@ -336,7 +334,7 @@ class Carousel(Carousel):
super().__init__(components=components, label=label)
class Chatbot(Chatbot):
class Chatbot(C_Chatbot):
"""
Component displays a chatbot output showing both user submitted messages and responses
Output type: List[Tuple[str, str]]