mirror of
https://github.com/gradio-app/gradio.git
synced 2024-12-03 01:50:59 +08:00
Adds variant
and interactive
props to gr.UploadButton
(#4436)
* upload button * fix index * changelog * formatting * cleanup
This commit is contained in:
parent
e06317bd00
commit
9c45aceb30
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
## New Features:
|
## New Features:
|
||||||
|
|
||||||
No changes to highlight.
|
- The `gr.UploadButton` component now supports the `variant` and `interactive` parameters by [@abidlabs](https://github.com/abidlabs) in [PR 4436](https://github.com/gradio-app/gradio/pull/4436).
|
||||||
|
|
||||||
## Bug Fixes:
|
## Bug Fixes:
|
||||||
|
|
||||||
|
@ -3337,7 +3337,7 @@ class Button(Clickable, IOComponent, StringSerializable):
|
|||||||
self,
|
self,
|
||||||
value: str | Callable = "Run",
|
value: str | Callable = "Run",
|
||||||
*,
|
*,
|
||||||
variant: str = "secondary",
|
variant: Literal["primary", "secondary", "stop"] = "secondary",
|
||||||
visible: bool = True,
|
visible: bool = True,
|
||||||
interactive: bool = True,
|
interactive: bool = True,
|
||||||
elem_id: str | None = None,
|
elem_id: str | None = None,
|
||||||
@ -3378,7 +3378,7 @@ class Button(Clickable, IOComponent, StringSerializable):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def update(
|
def update(
|
||||||
value: str | Literal[_Keywords.NO_VALUE] | None = _Keywords.NO_VALUE,
|
value: str | Literal[_Keywords.NO_VALUE] | None = _Keywords.NO_VALUE,
|
||||||
variant: str | None = None,
|
variant: Literal["primary", "secondary", "stop"] | None = None,
|
||||||
visible: bool | None = None,
|
visible: bool | None = None,
|
||||||
interactive: bool | None = None,
|
interactive: bool | None = None,
|
||||||
):
|
):
|
||||||
@ -3394,7 +3394,7 @@ class Button(Clickable, IOComponent, StringSerializable):
|
|||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
full_width: bool | None = None,
|
full_width: bool | None = None,
|
||||||
size: Literal["sm"] | Literal["lg"] | None = None,
|
size: Literal["sm", "lg"] | None = None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
@ -3427,7 +3427,9 @@ class UploadButton(Clickable, Uploadable, IOComponent, FileSerializable):
|
|||||||
label: str = "Upload a File",
|
label: str = "Upload a File",
|
||||||
value: str | list[str] | Callable | None = None,
|
value: str | list[str] | Callable | None = None,
|
||||||
*,
|
*,
|
||||||
|
variant: Literal["primary", "secondary", "stop"] = "secondary",
|
||||||
visible: bool = True,
|
visible: bool = True,
|
||||||
|
interactive: bool = True,
|
||||||
elem_id: str | None = None,
|
elem_id: str | None = None,
|
||||||
elem_classes: list[str] | str | None = None,
|
elem_classes: list[str] | str | None = None,
|
||||||
type: str = "file",
|
type: str = "file",
|
||||||
@ -3437,12 +3439,14 @@ class UploadButton(Clickable, Uploadable, IOComponent, FileSerializable):
|
|||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Parameters:
|
Parameters:
|
||||||
value: Default text for the button to display.
|
label: Text to display on the button. Defaults to "Upload a File".
|
||||||
|
value: File or list of files to upload by default.
|
||||||
|
variant: 'primary' for main call-to-action, 'secondary' for a more subdued style, 'stop' for a stop button.
|
||||||
type: Type of value to be returned by component. "file" returns a temporary file object with the same base name as the uploaded file, whose full path can be retrieved by file_obj.name, "binary" returns an bytes object.
|
type: Type of value to be returned by component. "file" returns a temporary file object with the same base name as the uploaded file, whose full path can be retrieved by file_obj.name, "binary" returns an bytes object.
|
||||||
file_count: if single, allows user to upload one file. If "multiple", user uploads multiple files. If "directory", user uploads all files in selected directory. Return type will be list for each file in case of "multiple" or "directory".
|
file_count: if single, allows user to upload one file. If "multiple", user uploads multiple files. If "directory", user uploads all files in selected directory. Return type will be list for each file in case of "multiple" or "directory".
|
||||||
file_types: List of type of files to be uploaded. "file" allows any file to be uploaded, "image" allows only image files to be uploaded, "audio" allows only audio files to be uploaded, "video" allows only video files to be uploaded, "text" allows only text files to be uploaded.
|
file_types: List of type of files to be uploaded. "file" allows any file to be uploaded, "image" allows only image files to be uploaded, "audio" allows only audio files to be uploaded, "video" allows only video files to be uploaded, "text" allows only text files to be uploaded.
|
||||||
label: Text to display on the button. Defaults to "Upload a File".
|
|
||||||
visible: If False, component will be hidden.
|
visible: If False, component will be hidden.
|
||||||
|
interactive: If False, the UploadButton will be in a disabled state.
|
||||||
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_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.
|
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.
|
||||||
"""
|
"""
|
||||||
@ -3458,6 +3462,7 @@ class UploadButton(Clickable, Uploadable, IOComponent, FileSerializable):
|
|||||||
)
|
)
|
||||||
self.file_types = file_types
|
self.file_types = file_types
|
||||||
self.label = label
|
self.label = label
|
||||||
|
self.variant = variant
|
||||||
IOComponent.__init__(
|
IOComponent.__init__(
|
||||||
self,
|
self,
|
||||||
label=label,
|
label=label,
|
||||||
@ -3465,6 +3470,7 @@ class UploadButton(Clickable, Uploadable, IOComponent, FileSerializable):
|
|||||||
elem_id=elem_id,
|
elem_id=elem_id,
|
||||||
elem_classes=elem_classes,
|
elem_classes=elem_classes,
|
||||||
value=value,
|
value=value,
|
||||||
|
interactive=interactive,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -3472,18 +3478,25 @@ class UploadButton(Clickable, Uploadable, IOComponent, FileSerializable):
|
|||||||
return {
|
return {
|
||||||
"label": self.label,
|
"label": self.label,
|
||||||
"value": self.value,
|
"value": self.value,
|
||||||
|
"variant": self.variant,
|
||||||
"file_count": self.file_count,
|
"file_count": self.file_count,
|
||||||
"file_types": self.file_types,
|
"file_types": self.file_types,
|
||||||
|
"interactive": self.interactive,
|
||||||
**Component.get_config(self),
|
**Component.get_config(self),
|
||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def update(
|
def update(
|
||||||
value: str | Literal[_Keywords.NO_VALUE] | None = _Keywords.NO_VALUE,
|
value: str
|
||||||
|
| list[str]
|
||||||
|
| Literal[_Keywords.NO_VALUE]
|
||||||
|
| None = _Keywords.NO_VALUE,
|
||||||
|
variant: Literal["primary", "secondary", "stop"] | None = None,
|
||||||
interactive: bool | None = None,
|
interactive: bool | None = None,
|
||||||
visible: bool | None = None,
|
visible: bool | None = None,
|
||||||
):
|
):
|
||||||
return {
|
return {
|
||||||
|
"variant": variant,
|
||||||
"interactive": interactive,
|
"interactive": interactive,
|
||||||
"visible": visible,
|
"visible": visible,
|
||||||
"value": value,
|
"value": value,
|
||||||
@ -3556,7 +3569,7 @@ class UploadButton(Clickable, Uploadable, IOComponent, FileSerializable):
|
|||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
full_width: bool | None = None,
|
full_width: bool | None = None,
|
||||||
size: Literal["sm"] | Literal["lg"] | None = None,
|
size: Literal["sm", "lg"] | None = None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
|
@ -6,7 +6,7 @@ import sys
|
|||||||
import time
|
import time
|
||||||
from asyncio import TimeoutError as AsyncTimeOutError
|
from asyncio import TimeoutError as AsyncTimeOutError
|
||||||
from collections import deque
|
from collections import deque
|
||||||
from typing import Any, Deque
|
from typing import Any
|
||||||
|
|
||||||
import fastapi
|
import fastapi
|
||||||
import httpx
|
import httpx
|
||||||
@ -46,7 +46,7 @@ class Queue:
|
|||||||
max_size: int | None,
|
max_size: int | None,
|
||||||
blocks_dependencies: list,
|
blocks_dependencies: list,
|
||||||
):
|
):
|
||||||
self.event_queue: Deque[Event] = deque()
|
self.event_queue: deque[Event] = deque()
|
||||||
self.events_pending_reconnection = []
|
self.events_pending_reconnection = []
|
||||||
self.stopped = False
|
self.stopped = False
|
||||||
self.max_thread_count = concurrency_count
|
self.max_thread_count = concurrency_count
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
export let file_count: string;
|
export let file_count: string;
|
||||||
export let file_types: Array<string> = ["file"];
|
export let file_types: Array<string> = ["file"];
|
||||||
export let root: string;
|
export let root: string;
|
||||||
|
export let mode: "static" | "dynamic" = "dynamic";
|
||||||
|
export let variant: "primary" | "secondary" | "stop" = "secondary";
|
||||||
|
|
||||||
async function handle_upload({ detail }: CustomEvent<FileData>) {
|
async function handle_upload({ detail }: CustomEvent<FileData>) {
|
||||||
value = detail;
|
value = detail;
|
||||||
@ -59,6 +61,8 @@
|
|||||||
{visible}
|
{visible}
|
||||||
{file_count}
|
{file_count}
|
||||||
{file_types}
|
{file_types}
|
||||||
|
{mode}
|
||||||
|
{variant}
|
||||||
on:click
|
on:click
|
||||||
on:load={handle_upload}
|
on:load={handle_upload}
|
||||||
>
|
>
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
export { default as Component } from "./UploadButton.svelte";
|
export { default as Component } from "./UploadButton.svelte";
|
||||||
export const modes = ["static"];
|
export const modes = ["static", "dynamic"];
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
export let file_count: string;
|
export let file_count: string;
|
||||||
export let file_types: Array<string> = ["file"];
|
export let file_types: Array<string> = ["file"];
|
||||||
export let include_file_metadata = true;
|
export let include_file_metadata = true;
|
||||||
|
export let mode: "static" | "dynamic" = "dynamic";
|
||||||
|
export let variant: "primary" | "secondary" | "stop" = "secondary";
|
||||||
|
|
||||||
let hidden_upload: HTMLInputElement;
|
let hidden_upload: HTMLInputElement;
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
@ -83,12 +85,13 @@
|
|||||||
|
|
||||||
<Button
|
<Button
|
||||||
{size}
|
{size}
|
||||||
variant="secondary"
|
{variant}
|
||||||
{elem_id}
|
{elem_id}
|
||||||
{elem_classes}
|
{elem_classes}
|
||||||
{visible}
|
{visible}
|
||||||
on:click={openFileUpload}
|
on:click={openFileUpload}
|
||||||
{style}
|
{style}
|
||||||
|
disabled={mode === "static"}
|
||||||
>
|
>
|
||||||
<slot />
|
<slot />
|
||||||
</Button>
|
</Button>
|
||||||
|
Loading…
Reference in New Issue
Block a user