mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-24 10:54:04 +08:00
cleanups
This commit is contained in:
parent
185d998cd2
commit
ad952b7981
@ -2098,36 +2098,9 @@ class KeyValues(Component):
|
|||||||
default (str): IGNORED
|
default (str): IGNORED
|
||||||
label (str): component name in interface.
|
label (str): component name in interface.
|
||||||
"""
|
"""
|
||||||
super().__init__(label=label, **kwargs)
|
raise DeprecationWarning(
|
||||||
|
"The KeyValues component is deprecated. Please use the DataFrame or JSON "
|
||||||
def postprocess(self, y):
|
"components instead.")
|
||||||
"""
|
|
||||||
Parameters:
|
|
||||||
y (Union[Dict, List[Tuple[str, Union[str, int, float]]]]): dictionary or tuple list representing key value pairs
|
|
||||||
Returns:
|
|
||||||
(List[Tuple[str, Union[str, number]]]): list of key value pairs
|
|
||||||
"""
|
|
||||||
if isinstance(y, dict):
|
|
||||||
return list(y.items())
|
|
||||||
elif isinstance(y, list):
|
|
||||||
return y
|
|
||||||
else:
|
|
||||||
raise ValueError(
|
|
||||||
"The `KeyValues` output interface expects an output that is a dictionary whose keys are "
|
|
||||||
"labels and values are corresponding values."
|
|
||||||
)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get_shortcut_implementations(cls):
|
|
||||||
return {
|
|
||||||
"key_values": {},
|
|
||||||
}
|
|
||||||
|
|
||||||
def save_flagged(self, dir, label, data, encryption_key):
|
|
||||||
return json.dumps(data)
|
|
||||||
|
|
||||||
def restore_flagged(self, dir, data, encryption_key):
|
|
||||||
return json.loads(data)
|
|
||||||
|
|
||||||
|
|
||||||
class HighlightedText(Component):
|
class HighlightedText(Component):
|
||||||
|
@ -7,13 +7,12 @@ automatically added to a registry, which allows them to be easily referenced in
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import warnings
|
import warnings
|
||||||
from typing import TYPE_CHECKING, Any, List, Optional, Tuple
|
from typing import Any, List, Optional, Tuple
|
||||||
|
|
||||||
from gradio.components import (
|
from gradio.components import (
|
||||||
Audio,
|
Audio,
|
||||||
Checkbox,
|
Checkbox,
|
||||||
CheckboxGroup,
|
CheckboxGroup,
|
||||||
Component,
|
|
||||||
Dataframe,
|
Dataframe,
|
||||||
Dropdown,
|
Dropdown,
|
||||||
File,
|
File,
|
||||||
@ -24,10 +23,10 @@ from gradio.components import (
|
|||||||
State,
|
State,
|
||||||
Textbox,
|
Textbox,
|
||||||
Timeseries,
|
Timeseries,
|
||||||
|
Video,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# TODO: (faruk) Remove this file in version 3.0
|
|
||||||
class Textbox(Textbox):
|
class Textbox(Textbox):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@ -287,7 +286,7 @@ class Image(Image):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Video(Component):
|
class Video(Video):
|
||||||
"""
|
"""
|
||||||
Component creates a video file upload that is converted to a file path.
|
Component creates a video file upload that is converted to a file path.
|
||||||
|
|
||||||
|
@ -6,21 +6,9 @@ automatically added to a registry, which allows them to be easily referenced in
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import json
|
from typing import Dict, List, Optional
|
||||||
import operator
|
|
||||||
import os
|
|
||||||
import tempfile
|
|
||||||
import warnings
|
import warnings
|
||||||
from numbers import Number
|
|
||||||
from types import ModuleType
|
|
||||||
from typing import TYPE_CHECKING, Dict, List, Optional
|
|
||||||
|
|
||||||
import numpy as np
|
|
||||||
import pandas as pd
|
|
||||||
import PIL
|
|
||||||
from ffmpy import FFmpeg
|
|
||||||
|
|
||||||
from gradio import processing_utils
|
|
||||||
from gradio.components import (
|
from gradio.components import (
|
||||||
HTML,
|
HTML,
|
||||||
JSON,
|
JSON,
|
||||||
@ -40,18 +28,12 @@ from gradio.components import (
|
|||||||
Video,
|
Video,
|
||||||
)
|
)
|
||||||
|
|
||||||
if TYPE_CHECKING: # Only import for type checking (is False at runtime).
|
|
||||||
from gradio import Interface
|
|
||||||
|
|
||||||
|
|
||||||
# TODO: (faruk) Remove this file in version 3.0
|
|
||||||
class Textbox(Textbox):
|
class Textbox(Textbox):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
type: str = "auto",
|
type: str = "auto",
|
||||||
label: Optional[str] = None,
|
label: Optional[str] = None,
|
||||||
):
|
):
|
||||||
# TODO: (faruk) Remove this file in version 3.0
|
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"Usage of gradio.outputs is deprecated, and will not be supported in the future, please import your components from gradio.components",
|
"Usage of gradio.outputs is deprecated, and will not be supported in the future, please import your components from gradio.components",
|
||||||
DeprecationWarning,
|
DeprecationWarning,
|
||||||
@ -351,56 +333,6 @@ class Carousel(Carousel):
|
|||||||
)
|
)
|
||||||
super().__init__(label=label, components=components)
|
super().__init__(label=label, components=components)
|
||||||
|
|
||||||
def get_template_context(self):
|
|
||||||
return {
|
|
||||||
"components": [
|
|
||||||
component.get_template_context() for component in self.components
|
|
||||||
],
|
|
||||||
**super().get_template_context(),
|
|
||||||
}
|
|
||||||
|
|
||||||
def postprocess(self, y):
|
|
||||||
"""
|
|
||||||
Parameters:
|
|
||||||
y (List[List[Any]]): carousel output
|
|
||||||
Returns:
|
|
||||||
(List[List[Any]]): 2D array, where each sublist represents one set of outputs or 'slide' in the carousel
|
|
||||||
"""
|
|
||||||
if isinstance(y, list):
|
|
||||||
if len(y) != 0 and not isinstance(y[0], list):
|
|
||||||
y = [[z] for z in y]
|
|
||||||
output = []
|
|
||||||
for row in y:
|
|
||||||
output_row = []
|
|
||||||
for i, cell in enumerate(row):
|
|
||||||
output_row.append(self.components[i].postprocess(cell))
|
|
||||||
output.append(output_row)
|
|
||||||
return output
|
|
||||||
else:
|
|
||||||
raise ValueError("Unknown type. Please provide a list for the Carousel.")
|
|
||||||
|
|
||||||
def save_flagged(self, dir, label, data, encryption_key):
|
|
||||||
return json.dumps(
|
|
||||||
[
|
|
||||||
[
|
|
||||||
component.save_flagged(
|
|
||||||
dir, f"{label}_{j}", data[i][j], encryption_key
|
|
||||||
)
|
|
||||||
for j, component in enumerate(self.components)
|
|
||||||
]
|
|
||||||
for i, _ in enumerate(data)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
def restore_flagged(self, dir, data, encryption_key):
|
|
||||||
return [
|
|
||||||
[
|
|
||||||
component.restore_flagged(dir, sample, encryption_key)
|
|
||||||
for component, sample in zip(self.components, sample_set)
|
|
||||||
]
|
|
||||||
for sample_set in json.loads(data)
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class Chatbot(Chatbot):
|
class Chatbot(Chatbot):
|
||||||
"""
|
"""
|
||||||
@ -420,21 +352,3 @@ class Chatbot(Chatbot):
|
|||||||
)
|
)
|
||||||
super().__init__(label=label)
|
super().__init__(label=label)
|
||||||
|
|
||||||
def get_template_context(self):
|
|
||||||
return {**super().get_template_context()}
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get_shortcut_implementations(cls):
|
|
||||||
return {
|
|
||||||
"chatbot": {},
|
|
||||||
}
|
|
||||||
|
|
||||||
def postprocess(self, y):
|
|
||||||
"""
|
|
||||||
Parameters:
|
|
||||||
y (List[Tuple[str, str]]): List of tuples representing the message and response
|
|
||||||
Returns:
|
|
||||||
(List[Tuple[str, str]]): Returns same list of tuples
|
|
||||||
|
|
||||||
"""
|
|
||||||
return y
|
|
||||||
|
Loading…
Reference in New Issue
Block a user