A set of extension component, inluding components for conversational input and display in multimodal scenarios, as well as more components for vertical scenarios.
Project description
modelscope_studio
A set of extension component, inluding components for conversational input and display in multimodal scenarios, as well as more components for vertical scenarios.
Installation
pip install modelscope_studio
Usage
import gradio as gr
with gr.Blocks() as demo:
pass
if __name__ == '__main__':
demo.launch()
Chatbot
Initialization
name | type | default | description |
---|---|---|---|
value |
list[
list[
str
| tuple[str]
| tuple[str | pathlib.Path, str]
| None
]
]
| Callable
| None
|
None |
Default value to show in chatbot. If callable, the function will be called whenever the app loads to set the initial value of the component. |
label |
str | None
|
None |
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 |
float | None
|
None |
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 |
bool | None
|
None |
if True, will display label. |
container |
bool
|
True |
If True, will place the component in a container - providing some extra padding around the border. |
scale |
int | None
|
None |
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 |
int
|
160 |
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. |
visible |
bool
|
True |
If False, component will be hidden. |
elem_id |
str | None
|
None |
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 |
list[str] | str | None
|
None |
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 |
bool
|
True |
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. |
height |
int | None
|
None |
height of the component in pixels. |
rtl |
bool
|
False |
If True, sets the direction of the rendered text to right-to-left. Default is False, which renders text left-to-right. |
show_share_button |
bool | None
|
None |
If True, will show a share icon in the corner of the component that allows user to share outputs to Hugging Face Spaces Discussions. If False, icon does not appear. If set to None (default behavior), then the icon appears if this Gradio app is launched on Spaces, but not otherwise. |
show_copy_button |
bool
|
False |
If True, will show a copy button for each chatbot message. |
avatar_images |
tuple[
str | pathlib.Path | None | dict | list | tuple,
str | pathlib.Path | None | dict | list | tuple,
]
| None
|
None |
Tuple of two avatar image paths or URLs or dict ("avatar" and "name") or list (each item receives the previous parameters) for user(s) and bot(s) (in that order). Pass None for either the user or bot image to skip. Must be within the working directory of the Gradio app or an external URL and use `gr.update` to update. |
avatar_image_align |
"top" | "middle" | "bottom"
|
"bottom" |
Aligns the avatar images to the top, middle, or bottom of the message. |
avatar_image_width |
int
|
45 |
Width of the avatar image in pixels. |
sanitize_html |
bool
|
True |
If False, will disable HTML sanitization for chatbot messages. This is not recommended, as it can lead to security vulnerabilities. |
render_markdown |
bool
|
True |
If False, will disable Markdown rendering for chatbot messages. |
bubble_full_width |
bool
|
True |
If False, the chat bubble will fit to the content of the message. If True (default), the chat bubble will be the full width of the component. |
line_breaks |
bool
|
True |
If True (default), will enable Github-flavored Markdown line breaks in chatbot messages. If False, single new lines will be ignored. Only applies if `render_markdown` is True. |
likeable |
bool
|
False |
Whether the chat messages display a like or dislike button. Set automatically by the .like method but has to be present in the signature for it to show up in the config. |
layout |
"panel" | "bubble" | None
|
None |
If "panel", will display the chatbot in a llm style layout. If "bubble", will display the chatbot with message bubbles, with the user and bot messages on alterating sides. Will default to "bubble". |
flushing |
bool
|
True |
If True (default), will stream output the chatbot (not the user) messages to the frontend linearly when they are updated. Can be configured for each message. |
flushing_speed |
int
|
5 |
Range 1 to 10, default is 5. |
enable_base64 |
bool
|
False |
Enable base64 encoding for markdown rendering. |
enable_latex |
bool
|
True |
If True, will enable LaTeX rendering. |
latex_single_dollar_delimiter |
bool
|
True |
If True, will enable single dollar delimiter for LaTeX rendering. |
preview |
bool
|
True |
If True (default), will enable image preview. |
llm_thinking_presets |
list[dict]
|
[] |
llm presets, imported from modelscope_studio.Chatbot.llm_thinking_presets . |
data_postprocess |
Callable | None
|
None |
None |
data_preprocess |
Callable | None
|
None |
None |
custom_components |
dict[str, CustomComponentDict] | None
|
None |
Define custom tags for markdown rendering. |
Events
name | description |
---|---|
change |
Triggered when the value of the Chatbot changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See .input() for a listener that is only triggered by user input. |
select |
Event listener for when the user selects or deselects the Chatbot. Uses event data gradio.SelectData to carry value referring to the label of the Chatbot, and selected to refer to state of the Chatbot. See EventData documentation on how to use this event data |
like |
This listener is triggered when the user likes/dislikes from within the Chatbot. This event has EventData of type gradio.LikeData that carries information, accessible through LikeData.index and LikeData.value. See EventData documentation on how to use this event data. |
flushed |
|
custom |
User function
The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).
- When used as an Input, the component only impacts the input signature of the user function.
- When used as an output, the component only impacts the return signature of the user function.
The code snippet below is accurate in cases where the component is used as both an input and an output.
def predict(
value: list[list[MultimodalMessage | None]]
) -> list[
list[
str
| dict
| MultimodalInputData
| MultimodalMessage
| None
]
| tuple
]:
return value
Markdown
Initialization
name | type | default | description |
---|---|---|---|
value |
str | Callable
|
"" |
Value to show in Markdown component. If callable, the function will be called whenever the app loads to set the initial value of the component. |
label |
str | None
|
None |
The label for this component. Is 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 |
float | None
|
None |
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 |
bool | None
|
None |
This parameter has no effect. |
rtl |
bool
|
False |
If True, sets the direction of the rendered text to right-to-left. Default is False, which renders text left-to-right. |
visible |
bool
|
True |
None |
elem_id |
str | None
|
None |
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 |
list[str] | str | None
|
None |
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 |
bool
|
True |
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. |
sanitize_html |
bool
|
True |
If False, will disable HTML sanitization when converted from markdown. This is not recommended, as it can lead to security vulnerabilities. |
line_breaks |
bool
|
False |
If True, will enable Github-flavored Markdown line breaks in chatbot messages. If False (default), single new lines will be ignored. |
header_links |
bool
|
False |
If True, will automatically create anchors for headings, displaying a link icon on hover. |
enable_base64 |
bool
|
False |
Enable base64 encoding for markdown rendering. |
enable_latex |
bool
|
True |
If True, will enable LaTeX rendering. |
latex_single_dollar_delimiter |
bool
|
True |
If True, will enable single dollar delimiter for LaTeX rendering. |
preview |
bool
|
True |
If True (default), will enable image preview. |
data_postprocess |
Callable | None
|
None |
None |
data_preprocess |
Callable | None
|
None |
None |
custom_components |
dict[str, CustomComponentDict] | None
|
None |
Define custom tags for markdown rendering. |
Events
name | description |
---|---|
change |
Triggered when the value of the Markdown changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See .input() for a listener that is only triggered by user input. |
custom |
User function
The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).
- When used as an Input, the component only impacts the input signature of the user function.
- When used as an output, the component only impacts the return signature of the user function.
The code snippet below is accurate in cases where the component is used as both an input and an output.
def predict(
value: str | None
) -> str | None:
return value
MultimodalInput
Initialization
name | type | default | description |
---|---|---|---|
value |
MultimodalInputData | str | None
|
None |
default text to provide in textarea. If callable, the function will be called whenever the app loads to set the initial value of the component. |
lines |
int
|
1 |
minimum number of line rows to provide in textarea. |
max_lines |
int
|
20 |
maximum number of line rows to provide in textarea. |
placeholder |
str | None
|
None |
placeholder hint to provide behind textarea. |
label |
str | None
|
None |
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. |
info |
str | None
|
None |
additional component description. |
every |
float | None
|
None |
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 |
bool | None
|
None |
if True, will display label. |
container |
bool
|
True |
If True, will place the component in a container - providing some extra padding around the border. |
scale |
int | None
|
None |
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 |
int
|
160 |
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. |
interactive |
bool | None
|
None |
if True, will be rendered as an editable textbox; if False, editing will be disabled. If not provided, this is inferred based on whether the component is used as an input or output. |
visible |
bool
|
True |
If False, component will be hidden. |
elem_id |
str | None
|
None |
An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles. |
autofocus |
bool
|
False |
If True, will focus on the textbox when the page loads. Use this carefully, as it can cause usability issues for sighted and non-sighted users. |
autoscroll |
bool
|
True |
If True, will automatically scroll to the bottom of the textbox when the value changes, unless the user scrolls up. If False, will not scroll to the bottom of the textbox when the value changes. |
elem_classes |
list[str] | str | None
|
None |
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 |
bool
|
True |
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. |
type |
"text" | "password" | "email"
|
"text" |
The type of textbox. One of: 'text', 'password', 'email', Default is 'text'. |
text_align |
"left" | "right" | None
|
None |
How to align the text in the textbox, can be: "left", "right", or None (default). If None, the alignment is left if `rtl` is False, or right if `rtl` is True. Can only be changed if `type` is "text". |
rtl |
bool
|
False |
If True and `type` is "text", sets the direction of the text to right-to-left (cursor appears on the left of the text). Default is False, which renders cursor on the right. |
show_copy_button |
bool
|
False |
If True, includes a copy button to copy the text in the textbox. Only applies if show_label is True. |
data_postprocess |
Callable | None
|
None |
None |
data_preprocess |
Callable | None
|
None |
None |
sources |
list["upload" | "microphone" | "webcam"]
|
["upload"] |
A list of sources permitted. "upload" creates a upload button, "microphone" creates a microphone button. "webcam" creates a webcam button. |
upload_button_props |
dict | None
|
None |
gradio UploadButton props. |
submit_button_props |
dict | None
|
None |
gradio Button props. |
file_preview_props |
dict | None
|
None |
FilePreview will render if `value.files` is not empty, accepting the following props: height(int). |
webcam_props |
dict | None
|
None |
Webcam will render if `sources` contains "webcam", accepting the following props: mirror_webcam(bool), include_audio(bool). |
Events
name | description |
---|---|
change |
Triggered when the value of the MultimodalInput changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See .input() for a listener that is only triggered by user input. |
input |
This listener is triggered when the user changes the value of the MultimodalInput. |
select |
Event listener for when the user selects or deselects the MultimodalInput. Uses event data gradio.SelectData to carry value referring to the label of the MultimodalInput, and selected to refer to state of the MultimodalInput. See EventData documentation on how to use this event data |
submit |
This listener is triggered when the user presses the Enter key while the MultimodalInput is focused. |
focus |
This listener is triggered when the MultimodalInput is focused. |
blur |
This listener is triggered when the MultimodalInput is unfocused/blurred. |
upload |
This listener is triggered when the user uploads a file into the MultimodalInput. |
User function
The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).
- When used as an Input, the component only impacts the input signature of the user function.
- When used as an output, the component only impacts the return signature of the user function.
The code snippet below is accurate in cases where the component is used as both an input and an output.
def predict(
value: MultimodalInputData | None
) -> MultimodalInputData | dict | str | None:
return value
MultimodalInputData
class MultimodalInputData(GradioModel):
files: List[Union[FileData, str]] = []
text: str
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for modelscope_studio-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7358febab3a9b193cd8787ea269ddb72360c59c157b0f9c0531849b5ef5c0f4d |
|
MD5 | 661da23dc378b781d171cbb1674cc71a |
|
BLAKE2b-256 | 98729a2033cd6be4ab1f4eb291183d04d23b7d52e0398e809ac69da9feb76ec9 |