Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- .agents/skills/gradio/SKILL.md +245 -0
- .agents/skills/gradio/examples.md +613 -0
- .agents/skills/hf-cli/SKILL.md +157 -0
- .gitignore +219 -0
- .python-version +1 -0
- Makefile +2 -0
- README.md +0 -12
- app.py +7 -2
- requirements.txt +2 -1
- skills-lock.json +10 -0
.agents/skills/gradio/SKILL.md
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
name: gradio
|
| 3 |
+
description: Build Gradio web UIs and demos in Python. Use when creating or editing Gradio apps, components, event listeners, layouts, or chatbots.
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# Gradio
|
| 7 |
+
|
| 8 |
+
Gradio is a Python library for building interactive web UIs and ML demos. This skill covers the core API, patterns, and examples.
|
| 9 |
+
|
| 10 |
+
## Guides
|
| 11 |
+
|
| 12 |
+
Detailed guides on specific topics (read these when relevant):
|
| 13 |
+
|
| 14 |
+
- [Quickstart](https://www.gradio.app/guides/quickstart)
|
| 15 |
+
- [The Interface Class](https://www.gradio.app/guides/the-interface-class)
|
| 16 |
+
- [Blocks and Event Listeners](https://www.gradio.app/guides/blocks-and-event-listeners)
|
| 17 |
+
- [Controlling Layout](https://www.gradio.app/guides/controlling-layout)
|
| 18 |
+
- [More Blocks Features](https://www.gradio.app/guides/more-blocks-features)
|
| 19 |
+
- [Custom CSS and JS](https://www.gradio.app/guides/custom-CSS-and-JS)
|
| 20 |
+
- [Streaming Outputs](https://www.gradio.app/guides/streaming-outputs)
|
| 21 |
+
- [Streaming Inputs](https://www.gradio.app/guides/streaming-inputs)
|
| 22 |
+
- [Sharing Your App](https://www.gradio.app/guides/sharing-your-app)
|
| 23 |
+
- [Custom HTML Components](https://www.gradio.app/guides/custom-HTML-components)
|
| 24 |
+
- [Getting Started with the Python Client](https://www.gradio.app/guides/getting-started-with-the-python-client)
|
| 25 |
+
- [Getting Started with the JS Client](https://www.gradio.app/guides/getting-started-with-the-js-client)
|
| 26 |
+
|
| 27 |
+
## Core Patterns
|
| 28 |
+
|
| 29 |
+
**Interface** (high-level): wraps a function with input/output components.
|
| 30 |
+
|
| 31 |
+
```python
|
| 32 |
+
import gradio as gr
|
| 33 |
+
|
| 34 |
+
def greet(name):
|
| 35 |
+
return f"Hello {name}!"
|
| 36 |
+
|
| 37 |
+
gr.Interface(fn=greet, inputs="text", outputs="text").launch()
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
**Blocks** (low-level): flexible layout with explicit event wiring.
|
| 41 |
+
|
| 42 |
+
```python
|
| 43 |
+
import gradio as gr
|
| 44 |
+
|
| 45 |
+
with gr.Blocks() as demo:
|
| 46 |
+
name = gr.Textbox(label="Name")
|
| 47 |
+
output = gr.Textbox(label="Greeting")
|
| 48 |
+
btn = gr.Button("Greet")
|
| 49 |
+
btn.click(fn=lambda n: f"Hello {n}!", inputs=name, outputs=output)
|
| 50 |
+
|
| 51 |
+
demo.launch()
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
**ChatInterface**: high-level wrapper for chatbot UIs.
|
| 55 |
+
|
| 56 |
+
```python
|
| 57 |
+
import gradio as gr
|
| 58 |
+
|
| 59 |
+
def respond(message, history):
|
| 60 |
+
return f"You said: {message}"
|
| 61 |
+
|
| 62 |
+
gr.ChatInterface(fn=respond).launch()
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
## Key Component Signatures
|
| 66 |
+
|
| 67 |
+
### `Textbox(value: str | I18nData | Callable | None = None, type: Literal['text', 'password', 'email'] = "text", lines: int = 1, max_lines: int | None = None, placeholder: str | I18nData | None = None, label: str | I18nData | None = None, info: str | I18nData | None = None, every: Timer | float | None = None, inputs: Component | Sequence[Component] | set[Component] | None = None, show_label: bool | None = None, container: bool = True, scale: int | None = None, min_width: int = 160, interactive: bool | None = None, visible: bool | Literal['hidden'] = True, elem_id: str | None = None, autofocus: bool = False, autoscroll: bool = True, elem_classes: list[str] | str | None = None, render: bool = True, key: int | str | tuple[int | str, ...] | None = None, preserved_by_key: list[str] | str | None = "value", text_align: Literal['left', 'right'] | None = None, rtl: bool = False, buttons: list[Literal['copy'] | Button] | None = None, max_length: int | None = None, submit_btn: str | bool | None = False, stop_btn: str | bool | None = False, html_attributes: InputHTMLAttributes | None = None)`
|
| 68 |
+
Creates a textarea for user to enter string input or display string output..
|
| 69 |
+
|
| 70 |
+
### `Number(value: float | Callable | None = None, label: str | I18nData | None = None, placeholder: str | I18nData | None = None, info: str | I18nData | None = None, every: Timer | float | None = None, inputs: Component | Sequence[Component] | set[Component] | None = None, show_label: bool | None = None, container: bool = True, scale: int | None = None, min_width: int = 160, interactive: bool | None = None, visible: bool | Literal['hidden'] = True, elem_id: str | None = None, elem_classes: list[str] | str | None = None, render: bool = True, key: int | str | tuple[int | str, ...] | None = None, preserved_by_key: list[str] | str | None = "value", buttons: list[Button] | None = None, precision: int | None = None, minimum: float | None = None, maximum: float | None = None, step: float = 1)`
|
| 71 |
+
Creates a numeric field for user to enter numbers as input or display numeric output..
|
| 72 |
+
|
| 73 |
+
### `Slider(minimum: float = 0, maximum: float = 100, value: float | Callable | None = None, step: float | None = None, precision: int | None = None, label: str | I18nData | None = None, info: str | I18nData | None = None, every: Timer | float | None = None, inputs: Component | Sequence[Component] | set[Component] | None = None, show_label: bool | None = None, container: bool = True, scale: int | None = None, min_width: int = 160, interactive: bool | None = None, visible: bool | Literal['hidden'] = True, elem_id: str | None = None, elem_classes: list[str] | str | None = None, render: bool = True, key: int | str | tuple[int | str, ...] | None = None, preserved_by_key: list[str] | str | None = "value", randomize: bool = False, buttons: list[Literal['reset']] | None = None)`
|
| 74 |
+
Creates a slider that ranges from {minimum} to {maximum} with a step size of {step}..
|
| 75 |
+
|
| 76 |
+
### `Checkbox(value: bool | Callable = False, label: str | I18nData | None = None, info: str | I18nData | None = None, every: Timer | float | None = None, inputs: Component | Sequence[Component] | set[Component] | None = None, show_label: bool | None = None, container: bool = True, scale: int | None = None, min_width: int = 160, interactive: bool | None = None, visible: bool | Literal['hidden'] = True, elem_id: str | None = None, elem_classes: list[str] | str | None = None, render: bool = True, key: int | str | tuple[int | str, ...] | None = None, preserved_by_key: list[str] | str | None = "value", buttons: list[Button] | None = None)`
|
| 77 |
+
Creates a checkbox that can be set to `True` or `False`.
|
| 78 |
+
|
| 79 |
+
### `Dropdown(choices: Sequence[str | int | float | tuple[str, str | int | float]] | None = None, value: str | int | float | Sequence[str | int | float] | Callable | DefaultValue | None = DefaultValue(), type: Literal['value', 'index'] = "value", multiselect: bool | None = None, allow_custom_value: bool = False, max_choices: int | None = None, filterable: bool = True, label: str | I18nData | None = None, info: str | I18nData | None = None, every: Timer | float | None = None, inputs: Component | Sequence[Component] | set[Component] | None = None, show_label: bool | None = None, container: bool = True, scale: int | None = None, min_width: int = 160, interactive: bool | None = None, visible: bool | Literal['hidden'] = True, elem_id: str | None = None, elem_classes: list[str] | str | None = None, render: bool = True, key: int | str | tuple[int | str, ...] | None = None, preserved_by_key: list[str] | str | None = "value", buttons: list[Button] | None = None)`
|
| 80 |
+
Creates a dropdown of choices from which a single entry or multiple entries can be selected (as an input component) or displayed (as an output component)..
|
| 81 |
+
|
| 82 |
+
### `Radio(choices: Sequence[str | int | float | tuple[str, str | int | float]] | None = None, value: str | int | float | Callable | None = None, type: Literal['value', 'index'] = "value", label: str | I18nData | None = None, info: str | I18nData | None = None, every: Timer | float | None = None, inputs: Component | Sequence[Component] | set[Component] | None = None, show_label: bool | None = None, container: bool = True, scale: int | None = None, min_width: int = 160, interactive: bool | None = None, visible: bool | Literal['hidden'] = True, elem_id: str | None = None, elem_classes: list[str] | str | None = None, render: bool = True, key: int | str | tuple[int | str, ...] | None = None, preserved_by_key: list[str] | str | None = "value", rtl: bool = False, buttons: list[Button] | None = None)`
|
| 83 |
+
Creates a set of (string or numeric type) radio buttons of which only one can be selected..
|
| 84 |
+
|
| 85 |
+
### `Image(value: str | PIL.Image.Image | np.ndarray | Callable | None = None, format: str = "webp", height: int | str | None = None, width: int | str | None = None, image_mode: Literal['1', 'L', 'P', 'RGB', 'RGBA', 'CMYK', 'YCbCr', 'LAB', 'HSV', 'I', 'F'] | None = "RGB", sources: list[Literal['upload', 'webcam', 'clipboard']] | Literal['upload', 'webcam', 'clipboard'] | None = None, type: Literal['numpy', 'pil', 'filepath'] = "numpy", label: str | I18nData | None = None, every: Timer | float | None = None, inputs: Component | Sequence[Component] | set[Component] | None = None, show_label: bool | None = None, buttons: list[Literal['download', 'share', 'fullscreen'] | Button] | None = None, container: bool = True, scale: int | None = None, min_width: int = 160, interactive: bool | None = None, visible: bool | Literal['hidden'] = True, streaming: bool = False, elem_id: str | None = None, elem_classes: list[str] | str | None = None, render: bool = True, key: int | str | tuple[int | str, ...] | None = None, preserved_by_key: list[str] | str | None = "value", webcam_options: WebcamOptions | None = None, placeholder: str | None = None, watermark: WatermarkOptions | None = None)`
|
| 86 |
+
Creates an image component that can be used to upload images (as an input) or display images (as an output)..
|
| 87 |
+
|
| 88 |
+
### `Audio(value: str | Path | tuple[int, np.ndarray] | Callable | None = None, sources: list[Literal['upload', 'microphone']] | Literal['upload', 'microphone'] | None = None, type: Literal['numpy', 'filepath'] = "numpy", label: str | I18nData | None = None, every: Timer | float | None = None, inputs: Component | Sequence[Component] | set[Component] | None = None, show_label: bool | None = None, container: bool = True, scale: int | None = None, min_width: int = 160, interactive: bool | None = None, visible: bool | Literal['hidden'] = True, streaming: bool = False, elem_id: str | None = None, elem_classes: list[str] | str | None = None, render: bool = True, key: int | str | tuple[int | str, ...] | None = None, preserved_by_key: list[str] | str | None = "value", format: Literal['wav', 'mp3'] | None = None, autoplay: bool = False, editable: bool = True, buttons: list[Literal['download', 'share'] | Button] | None = None, waveform_options: WaveformOptions | dict | None = None, loop: bool = False, recording: bool = False, subtitles: str | Path | list[dict[str, Any]] | None = None, playback_position: float = 0)`
|
| 89 |
+
Creates an audio component that can be used to upload/record audio (as an input) or display audio (as an output)..
|
| 90 |
+
|
| 91 |
+
### `Video(value: str | Path | Callable | None = None, format: str | None = None, sources: list[Literal['upload', 'webcam']] | Literal['upload', 'webcam'] | None = None, height: int | str | None = None, width: int | str | None = None, label: str | I18nData | None = None, every: Timer | float | None = None, inputs: Component | Sequence[Component] | set[Component] | None = None, show_label: bool | None = None, container: bool = True, scale: int | None = None, min_width: int = 160, interactive: bool | None = None, visible: bool | Literal['hidden'] = True, elem_id: str | None = None, elem_classes: list[str] | str | None = None, render: bool = True, key: int | str | tuple[int | str, ...] | None = None, preserved_by_key: list[str] | str | None = "value", webcam_options: WebcamOptions | None = None, include_audio: bool | None = None, autoplay: bool = False, buttons: list[Literal['download', 'share'] | Button] | None = None, loop: bool = False, streaming: bool = False, watermark: WatermarkOptions | None = None, subtitles: str | Path | list[dict[str, Any]] | None = None, playback_position: float = 0)`
|
| 92 |
+
Creates a video component that can be used to upload/record videos (as an input) or display videos (as an output).
|
| 93 |
+
|
| 94 |
+
### `File(value: str | list[str] | Callable | None = None, file_count: Literal['single', 'multiple', 'directory'] = "single", file_types: list[str] | None = None, type: Literal['filepath', 'binary'] = "filepath", label: str | I18nData | None = None, every: Timer | float | None = None, inputs: Component | Sequence[Component] | set[Component] | None = None, show_label: bool | None = None, container: bool = True, scale: int | None = None, min_width: int = 160, height: int | str | float | None = None, interactive: bool | None = None, visible: bool | Literal['hidden'] = True, elem_id: str | None = None, elem_classes: list[str] | str | None = None, render: bool = True, key: int | str | tuple[int | str, ...] | None = None, preserved_by_key: list[str] | str | None = "value", allow_reordering: bool = False, buttons: list[Button] | None = None)`
|
| 95 |
+
Creates a file component that allows uploading one or more generic files (when used as an input) or displaying generic files or URLs for download (as output).
|
| 96 |
+
|
| 97 |
+
### `Chatbot(value: list[MessageDict | Message] | Callable | None = None, label: str | I18nData | None = None, every: Timer | float | None = None, inputs: Component | Sequence[Component] | set[Component] | None = None, show_label: bool | None = None, container: bool = True, scale: int | None = None, min_width: int = 160, visible: bool | Literal['hidden'] = True, elem_id: str | None = None, elem_classes: list[str] | str | None = None, autoscroll: bool = True, render: bool = True, key: int | str | tuple[int | str, ...] | None = None, preserved_by_key: list[str] | str | None = "value", height: int | str | None = 400, resizable: bool = False, max_height: int | str | None = None, min_height: int | str | None = None, editable: Literal['user', 'all'] | None = None, latex_delimiters: list[dict[str, str | bool]] | None = None, rtl: bool = False, buttons: list[Literal['share', 'copy', 'copy_all'] | Button] | None = None, watermark: str | None = None, avatar_images: tuple[str | Path | None, str | Path | None] | None = None, sanitize_html: bool = True, render_markdown: bool = True, feedback_options: list[str] | tuple[str, ...] | None = ('Like', 'Dislike'), feedback_value: Sequence[str | None] | None = None, line_breaks: bool = True, layout: Literal['panel', 'bubble'] | None = None, placeholder: str | None = None, examples: list[ExampleMessage] | None = None, allow_file_downloads: <class 'inspect._empty'> = True, group_consecutive_messages: bool = True, allow_tags: list[str] | bool = True, reasoning_tags: list[tuple[str, str]] | None = None, like_user_message: bool = False)`
|
| 98 |
+
Creates a chatbot that displays user-submitted messages and responses.
|
| 99 |
+
|
| 100 |
+
### `Button(value: str | I18nData | Callable = "Run", every: Timer | float | None = None, inputs: Component | Sequence[Component] | set[Component] | None = None, variant: Literal['primary', 'secondary', 'stop', 'huggingface'] = "secondary", size: Literal['sm', 'md', 'lg'] = "lg", icon: str | Path | None = None, link: str | None = None, link_target: Literal['_self', '_blank', '_parent', '_top'] = "_self", visible: bool | Literal['hidden'] = True, interactive: bool = True, elem_id: str | None = None, elem_classes: list[str] | str | None = None, render: bool = True, key: int | str | tuple[int | str, ...] | None = None, preserved_by_key: list[str] | str | None = "value", scale: int | None = None, min_width: int | None = None)`
|
| 101 |
+
Creates a button that can be assigned arbitrary .click() events.
|
| 102 |
+
|
| 103 |
+
### `Markdown(value: str | I18nData | Callable | None = None, label: str | I18nData | None = None, every: Timer | float | None = None, inputs: Component | Sequence[Component] | set[Component] | None = None, show_label: bool | None = None, rtl: bool = False, latex_delimiters: list[dict[str, str | bool]] | None = None, visible: bool | Literal['hidden'] = True, elem_id: str | None = None, elem_classes: list[str] | str | None = None, render: bool = True, key: int | str | tuple[int | str, ...] | None = None, preserved_by_key: list[str] | str | None = "value", sanitize_html: bool = True, line_breaks: bool = False, header_links: bool = False, height: int | str | None = None, max_height: int | str | None = None, min_height: int | str | None = None, buttons: list[Literal['copy']] | None = None, container: bool = False, padding: bool = False)`
|
| 104 |
+
Used to render arbitrary Markdown output.
|
| 105 |
+
|
| 106 |
+
### `HTML(value: Any | Callable | None = None, label: str | I18nData | None = None, html_template: str = "${value}", css_template: str = "", js_on_load: str | None = "element.addEventListener('click', function() { trigger('click') });", apply_default_css: bool = True, every: Timer | float | None = None, inputs: Component | Sequence[Component] | set[Component] | None = None, show_label: bool = False, visible: bool | Literal['hidden'] = True, elem_id: str | None = None, elem_classes: list[str] | str | None = None, render: bool = True, key: int | str | tuple[int | str, ...] | None = None, preserved_by_key: list[str] | str | None = "value", min_height: int | None = None, max_height: int | None = None, container: bool = False, padding: bool = False, autoscroll: bool = False, buttons: list[Button] | None = None, props: Any)`
|
| 107 |
+
Creates a component with arbitrary HTML.
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
## Custom HTML Components
|
| 111 |
+
|
| 112 |
+
If a task requires significant customization of an existing component or a component that doesn't exist in Gradio, you can create one with `gr.HTML`. It supports `html_template` (with `${}` JS expressions and `{{}}` Handlebars syntax), `css_template` for scoped styles, and `js_on_load` for interactivity — where `props.value` updates the component value and `trigger('event_name')` fires Gradio events. For reuse, subclass `gr.HTML` and define `api_info()` for API/MCP support. See the [full guide](https://www.gradio.app/guides/custom-HTML-components).
|
| 113 |
+
|
| 114 |
+
Here's an example that shows how to create and use these kinds of components:
|
| 115 |
+
|
| 116 |
+
```python
|
| 117 |
+
import gradio as gr
|
| 118 |
+
|
| 119 |
+
class StarRating(gr.HTML):
|
| 120 |
+
def __init__(self, label, value=0, **kwargs):
|
| 121 |
+
html_template = """
|
| 122 |
+
<h2>${label} rating:</h2>
|
| 123 |
+
${Array.from({length: 5}, (_, i) => `<img class='${i < value ? '' : 'faded'}' src='https://upload.wikimedia.org/wikipedia/commons/d/df/Award-star-gold-3d.svg'>`).join('')}
|
| 124 |
+
"""
|
| 125 |
+
css_template = """
|
| 126 |
+
img { height: 50px; display: inline-block; cursor: pointer; }
|
| 127 |
+
.faded { filter: grayscale(100%); opacity: 0.3; }
|
| 128 |
+
"""
|
| 129 |
+
js_on_load = """
|
| 130 |
+
const imgs = element.querySelectorAll('img');
|
| 131 |
+
imgs.forEach((img, index) => {
|
| 132 |
+
img.addEventListener('click', () => {
|
| 133 |
+
props.value = index + 1;
|
| 134 |
+
});
|
| 135 |
+
});
|
| 136 |
+
"""
|
| 137 |
+
super().__init__(value=value, label=label, html_template=html_template, css_template=css_template, js_on_load=js_on_load, **kwargs)
|
| 138 |
+
|
| 139 |
+
def api_info(self):
|
| 140 |
+
return {"type": "integer", "minimum": 0, "maximum": 5}
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
with gr.Blocks() as demo:
|
| 144 |
+
gr.Markdown("# Restaurant Review")
|
| 145 |
+
food_rating = StarRating(label="Food", value=3)
|
| 146 |
+
service_rating = StarRating(label="Service", value=3)
|
| 147 |
+
ambience_rating = StarRating(label="Ambience", value=3)
|
| 148 |
+
average_btn = gr.Button("Calculate Average Rating")
|
| 149 |
+
rating_output = StarRating(label="Average", value=3)
|
| 150 |
+
def calculate_average(food, service, ambience):
|
| 151 |
+
return round((food + service + ambience) / 3)
|
| 152 |
+
average_btn.click(
|
| 153 |
+
fn=calculate_average,
|
| 154 |
+
inputs=[food_rating, service_rating, ambience_rating],
|
| 155 |
+
outputs=rating_output
|
| 156 |
+
)
|
| 157 |
+
|
| 158 |
+
demo.launch()
|
| 159 |
+
```
|
| 160 |
+
|
| 161 |
+
## Event Listeners
|
| 162 |
+
|
| 163 |
+
All event listeners share the same signature:
|
| 164 |
+
|
| 165 |
+
```python
|
| 166 |
+
component.event_name(
|
| 167 |
+
fn: Callable | None | Literal["decorator"] = "decorator",
|
| 168 |
+
inputs: Component | Sequence[Component] | set[Component] | None = None,
|
| 169 |
+
outputs: Component | Sequence[Component] | set[Component] | None = None,
|
| 170 |
+
api_name: str | None = None,
|
| 171 |
+
api_description: str | None | Literal[False] = None,
|
| 172 |
+
scroll_to_output: bool = False,
|
| 173 |
+
show_progress: Literal["full", "minimal", "hidden"] = "full",
|
| 174 |
+
show_progress_on: Component | Sequence[Component] | None = None,
|
| 175 |
+
queue: bool = True,
|
| 176 |
+
batch: bool = False,
|
| 177 |
+
max_batch_size: int = 4,
|
| 178 |
+
preprocess: bool = True,
|
| 179 |
+
postprocess: bool = True,
|
| 180 |
+
cancels: dict[str, Any] | list[dict[str, Any]] | None = None,
|
| 181 |
+
trigger_mode: Literal["once", "multiple", "always_last"] | None = None,
|
| 182 |
+
js: str | Literal[True] | None = None,
|
| 183 |
+
concurrency_limit: int | None | Literal["default"] = "default",
|
| 184 |
+
concurrency_id: str | None = None,
|
| 185 |
+
api_visibility: Literal["public", "private", "undocumented"] = "public",
|
| 186 |
+
time_limit: int | None = None,
|
| 187 |
+
stream_every: float = 0.5,
|
| 188 |
+
key: int | str | tuple[int | str, ...] | None = None,
|
| 189 |
+
validator: Callable | None = None,
|
| 190 |
+
) -> Dependency
|
| 191 |
+
```
|
| 192 |
+
|
| 193 |
+
Supported events per component:
|
| 194 |
+
|
| 195 |
+
- **AnnotatedImage**: select
|
| 196 |
+
- **Audio**: stream, change, clear, play, pause, stop, pause, start_recording, pause_recording, stop_recording, upload, input
|
| 197 |
+
- **BarPlot**: select, double_click
|
| 198 |
+
- **BrowserState**: change
|
| 199 |
+
- **Button**: click
|
| 200 |
+
- **Chatbot**: change, select, like, retry, undo, example_select, option_select, clear, copy, edit
|
| 201 |
+
- **Checkbox**: change, input, select
|
| 202 |
+
- **CheckboxGroup**: change, input, select
|
| 203 |
+
- **ClearButton**: click
|
| 204 |
+
- **Code**: change, input, focus, blur
|
| 205 |
+
- **ColorPicker**: change, input, submit, focus, blur
|
| 206 |
+
- **Dataframe**: change, input, select, edit
|
| 207 |
+
- **Dataset**: click, select
|
| 208 |
+
- **DateTime**: change, submit
|
| 209 |
+
- **DeepLinkButton**: click
|
| 210 |
+
- **Dialogue**: change, input, submit
|
| 211 |
+
- **DownloadButton**: click
|
| 212 |
+
- **Dropdown**: change, input, select, focus, blur, key_up
|
| 213 |
+
- **DuplicateButton**: click
|
| 214 |
+
- **File**: change, select, clear, upload, delete, download
|
| 215 |
+
- **FileExplorer**: change, input, select
|
| 216 |
+
- **Gallery**: select, upload, change, delete, preview_close, preview_open
|
| 217 |
+
- **HTML**: change, input, click, double_click, submit, stop, edit, clear, play, pause, end, start_recording, pause_recording, stop_recording, focus, blur, upload, release, select, stream, like, example_select, option_select, load, key_up, apply, delete, tick, undo, retry, expand, collapse, download, copy
|
| 218 |
+
- **HighlightedText**: change, select
|
| 219 |
+
- **Image**: clear, change, stream, select, upload, input
|
| 220 |
+
- **ImageEditor**: clear, change, input, select, upload, apply
|
| 221 |
+
- **ImageSlider**: clear, change, stream, select, upload, input
|
| 222 |
+
- **JSON**: change
|
| 223 |
+
- **Label**: change, select
|
| 224 |
+
- **LinePlot**: select, double_click
|
| 225 |
+
- **LoginButton**: click
|
| 226 |
+
- **Markdown**: change, copy
|
| 227 |
+
- **Model3D**: change, upload, edit, clear
|
| 228 |
+
- **MultimodalTextbox**: change, input, select, submit, focus, blur, stop
|
| 229 |
+
- **Navbar**: change
|
| 230 |
+
- **Number**: change, input, submit, focus, blur
|
| 231 |
+
- **ParamViewer**: change, upload
|
| 232 |
+
- **Plot**: change
|
| 233 |
+
- **Radio**: select, change, input
|
| 234 |
+
- **ScatterPlot**: select, double_click
|
| 235 |
+
- **SimpleImage**: clear, change, upload
|
| 236 |
+
- **Slider**: change, input, release
|
| 237 |
+
- **State**: change
|
| 238 |
+
- **Textbox**: change, input, select, submit, focus, blur, stop, copy
|
| 239 |
+
- **Timer**: tick
|
| 240 |
+
- **UploadButton**: click, upload
|
| 241 |
+
- **Video**: change, clear, start_recording, stop_recording, stop, play, pause, end, upload, input
|
| 242 |
+
|
| 243 |
+
## Additional Reference
|
| 244 |
+
|
| 245 |
+
- [End-to-End Examples](examples.md) — complete working apps
|
.agents/skills/gradio/examples.md
ADDED
|
@@ -0,0 +1,613 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Gradio End-to-End Examples
|
| 2 |
+
|
| 3 |
+
Complete working Gradio apps for reference.
|
| 4 |
+
|
| 5 |
+
## Blocks Essay Simple
|
| 6 |
+
|
| 7 |
+
```python
|
| 8 |
+
import gradio as gr
|
| 9 |
+
|
| 10 |
+
def change_textbox(choice):
|
| 11 |
+
if choice == "short":
|
| 12 |
+
return gr.Textbox(lines=2, visible=True)
|
| 13 |
+
elif choice == "long":
|
| 14 |
+
return gr.Textbox(lines=8, visible=True, value="Lorem ipsum dolor sit amet")
|
| 15 |
+
else:
|
| 16 |
+
return gr.Textbox(visible=False)
|
| 17 |
+
|
| 18 |
+
with gr.Blocks() as demo:
|
| 19 |
+
radio = gr.Radio(
|
| 20 |
+
["short", "long", "none"], label="What kind of essay would you like to write?"
|
| 21 |
+
)
|
| 22 |
+
text = gr.Textbox(lines=2, interactive=True, buttons=["copy"])
|
| 23 |
+
radio.change(fn=change_textbox, inputs=radio, outputs=text)
|
| 24 |
+
|
| 25 |
+
demo.launch()
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
## Blocks Flipper
|
| 29 |
+
|
| 30 |
+
```python
|
| 31 |
+
import numpy as np
|
| 32 |
+
import gradio as gr
|
| 33 |
+
|
| 34 |
+
def flip_text(x):
|
| 35 |
+
return x[::-1]
|
| 36 |
+
|
| 37 |
+
def flip_image(x):
|
| 38 |
+
return np.fliplr(x)
|
| 39 |
+
|
| 40 |
+
with gr.Blocks() as demo:
|
| 41 |
+
gr.Markdown("Flip text or image files using this demo.")
|
| 42 |
+
with gr.Tab("Flip Text"):
|
| 43 |
+
text_input = gr.Textbox()
|
| 44 |
+
text_output = gr.Textbox()
|
| 45 |
+
text_button = gr.Button("Flip")
|
| 46 |
+
with gr.Tab("Flip Image"):
|
| 47 |
+
with gr.Row():
|
| 48 |
+
image_input = gr.Image()
|
| 49 |
+
image_output = gr.Image()
|
| 50 |
+
image_button = gr.Button("Flip")
|
| 51 |
+
|
| 52 |
+
with gr.Accordion("Open for More!", open=False):
|
| 53 |
+
gr.Markdown("Look at me...")
|
| 54 |
+
temp_slider = gr.Slider(
|
| 55 |
+
0, 1,
|
| 56 |
+
value=0.1,
|
| 57 |
+
step=0.1,
|
| 58 |
+
interactive=True,
|
| 59 |
+
label="Slide me",
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
text_button.click(flip_text, inputs=text_input, outputs=text_output)
|
| 63 |
+
image_button.click(flip_image, inputs=image_input, outputs=image_output)
|
| 64 |
+
|
| 65 |
+
demo.launch()
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
## Blocks Form
|
| 69 |
+
|
| 70 |
+
```python
|
| 71 |
+
import gradio as gr
|
| 72 |
+
|
| 73 |
+
with gr.Blocks() as demo:
|
| 74 |
+
name_box = gr.Textbox(label="Name")
|
| 75 |
+
age_box = gr.Number(label="Age", minimum=0, maximum=100)
|
| 76 |
+
symptoms_box = gr.CheckboxGroup(["Cough", "Fever", "Runny Nose"])
|
| 77 |
+
submit_btn = gr.Button("Submit")
|
| 78 |
+
|
| 79 |
+
with gr.Column(visible=False) as output_col:
|
| 80 |
+
diagnosis_box = gr.Textbox(label="Diagnosis")
|
| 81 |
+
patient_summary_box = gr.Textbox(label="Patient Summary")
|
| 82 |
+
|
| 83 |
+
def submit(name, age, symptoms):
|
| 84 |
+
return {
|
| 85 |
+
submit_btn: gr.Button(visible=False),
|
| 86 |
+
output_col: gr.Column(visible=True),
|
| 87 |
+
diagnosis_box: "covid" if "Cough" in symptoms else "flu",
|
| 88 |
+
patient_summary_box: f"{name}, {age} y/o",
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
submit_btn.click(
|
| 92 |
+
submit,
|
| 93 |
+
[name_box, age_box, symptoms_box],
|
| 94 |
+
[submit_btn, diagnosis_box, patient_summary_box, output_col],
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
demo.launch()
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
## Blocks Hello
|
| 101 |
+
|
| 102 |
+
```python
|
| 103 |
+
import gradio as gr
|
| 104 |
+
|
| 105 |
+
def welcome(name):
|
| 106 |
+
return f"Welcome to Gradio, {name}!"
|
| 107 |
+
|
| 108 |
+
with gr.Blocks() as demo:
|
| 109 |
+
gr.Markdown(
|
| 110 |
+
"""
|
| 111 |
+
# Hello World!
|
| 112 |
+
Start typing below to see the output.
|
| 113 |
+
""")
|
| 114 |
+
inp = gr.Textbox(placeholder="What is your name?")
|
| 115 |
+
out = gr.Textbox()
|
| 116 |
+
inp.change(welcome, inp, out)
|
| 117 |
+
|
| 118 |
+
demo.launch()
|
| 119 |
+
```
|
| 120 |
+
|
| 121 |
+
## Blocks Layout
|
| 122 |
+
|
| 123 |
+
```python
|
| 124 |
+
import gradio as gr
|
| 125 |
+
|
| 126 |
+
demo = gr.Blocks()
|
| 127 |
+
|
| 128 |
+
with demo:
|
| 129 |
+
with gr.Row():
|
| 130 |
+
gr.Image(interactive=True, scale=2)
|
| 131 |
+
gr.Image()
|
| 132 |
+
with gr.Row():
|
| 133 |
+
gr.Textbox(label="Text")
|
| 134 |
+
gr.Number(label="Count", scale=2)
|
| 135 |
+
gr.Radio(choices=["One", "Two"])
|
| 136 |
+
with gr.Row():
|
| 137 |
+
gr.Button("500", scale=0, min_width=500)
|
| 138 |
+
gr.Button("A", scale=0)
|
| 139 |
+
gr.Button("grow")
|
| 140 |
+
with gr.Row():
|
| 141 |
+
gr.Textbox()
|
| 142 |
+
gr.Textbox()
|
| 143 |
+
gr.Button()
|
| 144 |
+
with gr.Row():
|
| 145 |
+
with gr.Row():
|
| 146 |
+
with gr.Column():
|
| 147 |
+
gr.Textbox(label="Text")
|
| 148 |
+
gr.Number(label="Count")
|
| 149 |
+
gr.Radio(choices=["One", "Two"])
|
| 150 |
+
gr.Image()
|
| 151 |
+
with gr.Column():
|
| 152 |
+
gr.Image(interactive=True)
|
| 153 |
+
gr.Image()
|
| 154 |
+
gr.Image()
|
| 155 |
+
gr.Textbox(label="Text")
|
| 156 |
+
gr.Number(label="Count")
|
| 157 |
+
gr.Radio(choices=["One", "Two"])
|
| 158 |
+
|
| 159 |
+
demo.launch()
|
| 160 |
+
```
|
| 161 |
+
|
| 162 |
+
## Calculator
|
| 163 |
+
|
| 164 |
+
```python
|
| 165 |
+
import gradio as gr
|
| 166 |
+
|
| 167 |
+
def calculator(num1, operation, num2):
|
| 168 |
+
if operation == "add":
|
| 169 |
+
return num1 + num2
|
| 170 |
+
elif operation == "subtract":
|
| 171 |
+
return num1 - num2
|
| 172 |
+
elif operation == "multiply":
|
| 173 |
+
return num1 * num2
|
| 174 |
+
elif operation == "divide":
|
| 175 |
+
if num2 == 0:
|
| 176 |
+
raise gr.Error("Cannot divide by zero!")
|
| 177 |
+
return num1 / num2
|
| 178 |
+
|
| 179 |
+
demo = gr.Interface(
|
| 180 |
+
calculator,
|
| 181 |
+
[
|
| 182 |
+
"number",
|
| 183 |
+
gr.Radio(["add", "subtract", "multiply", "divide"]),
|
| 184 |
+
"number"
|
| 185 |
+
],
|
| 186 |
+
"number",
|
| 187 |
+
examples=[
|
| 188 |
+
[45, "add", 3],
|
| 189 |
+
[3.14, "divide", 2],
|
| 190 |
+
[144, "multiply", 2.5],
|
| 191 |
+
[0, "subtract", 1.2],
|
| 192 |
+
],
|
| 193 |
+
title="Toy Calculator",
|
| 194 |
+
description="Here's a sample toy calculator.",
|
| 195 |
+
api_name="predict"
|
| 196 |
+
)
|
| 197 |
+
|
| 198 |
+
demo.launch()
|
| 199 |
+
```
|
| 200 |
+
|
| 201 |
+
## Chatbot Simple
|
| 202 |
+
|
| 203 |
+
```python
|
| 204 |
+
import gradio as gr
|
| 205 |
+
import random
|
| 206 |
+
import time
|
| 207 |
+
|
| 208 |
+
with gr.Blocks() as demo:
|
| 209 |
+
chatbot = gr.Chatbot()
|
| 210 |
+
msg = gr.Textbox()
|
| 211 |
+
clear = gr.ClearButton([msg, chatbot])
|
| 212 |
+
|
| 213 |
+
def respond(message, chat_history):
|
| 214 |
+
bot_message = random.choice(["How are you?", "Today is a great day", "I'm very hungry"])
|
| 215 |
+
chat_history.append({"role": "user", "content": message})
|
| 216 |
+
chat_history.append({"role": "assistant", "content": bot_message})
|
| 217 |
+
time.sleep(2)
|
| 218 |
+
return "", chat_history
|
| 219 |
+
|
| 220 |
+
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
| 221 |
+
|
| 222 |
+
demo.launch()
|
| 223 |
+
```
|
| 224 |
+
|
| 225 |
+
## Chatbot Streaming
|
| 226 |
+
|
| 227 |
+
```python
|
| 228 |
+
import gradio as gr
|
| 229 |
+
import random
|
| 230 |
+
import time
|
| 231 |
+
|
| 232 |
+
with gr.Blocks() as demo:
|
| 233 |
+
chatbot = gr.Chatbot()
|
| 234 |
+
msg = gr.Textbox()
|
| 235 |
+
clear = gr.Button("Clear")
|
| 236 |
+
|
| 237 |
+
def user(user_message, history: list):
|
| 238 |
+
return "", history + [{"role": "user", "content": user_message}]
|
| 239 |
+
|
| 240 |
+
def bot(history: list):
|
| 241 |
+
bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
|
| 242 |
+
history.append({"role": "assistant", "content": ""})
|
| 243 |
+
for character in bot_message:
|
| 244 |
+
history[-1]['content'] += character
|
| 245 |
+
time.sleep(0.05)
|
| 246 |
+
yield history
|
| 247 |
+
|
| 248 |
+
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
| 249 |
+
bot, chatbot, chatbot
|
| 250 |
+
)
|
| 251 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
| 252 |
+
|
| 253 |
+
demo.launch()
|
| 254 |
+
```
|
| 255 |
+
|
| 256 |
+
## Custom Css
|
| 257 |
+
|
| 258 |
+
```python
|
| 259 |
+
import gradio as gr
|
| 260 |
+
|
| 261 |
+
with gr.Blocks() as demo:
|
| 262 |
+
with gr.Column(elem_classes="cool-col"):
|
| 263 |
+
gr.Markdown("### Gradio Demo with Custom CSS", elem_classes="darktest")
|
| 264 |
+
gr.Markdown(
|
| 265 |
+
elem_classes="markdown",
|
| 266 |
+
value="Resize the browser window to see the CSS media query in action.",
|
| 267 |
+
)
|
| 268 |
+
|
| 269 |
+
if __name__ == "__main__":
|
| 270 |
+
demo.launch(css_paths=["demo/custom_css/custom_css.css"])
|
| 271 |
+
```
|
| 272 |
+
|
| 273 |
+
## Fake Diffusion
|
| 274 |
+
|
| 275 |
+
```python
|
| 276 |
+
import gradio as gr
|
| 277 |
+
import numpy as np
|
| 278 |
+
import time
|
| 279 |
+
|
| 280 |
+
def fake_diffusion(steps):
|
| 281 |
+
rng = np.random.default_rng()
|
| 282 |
+
for i in range(steps):
|
| 283 |
+
time.sleep(1)
|
| 284 |
+
image = rng.random(size=(600, 600, 3))
|
| 285 |
+
yield image
|
| 286 |
+
image = np.ones((1000,1000,3), np.uint8)
|
| 287 |
+
image[:] = [255, 124, 0]
|
| 288 |
+
yield image
|
| 289 |
+
|
| 290 |
+
demo = gr.Interface(fake_diffusion,
|
| 291 |
+
inputs=gr.Slider(1, 10, 3, step=1),
|
| 292 |
+
outputs="image",
|
| 293 |
+
api_name="predict")
|
| 294 |
+
|
| 295 |
+
demo.launch()
|
| 296 |
+
```
|
| 297 |
+
|
| 298 |
+
## Hello World
|
| 299 |
+
|
| 300 |
+
```python
|
| 301 |
+
import gradio as gr
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
def greet(name):
|
| 305 |
+
return "Hello " + name + "!"
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
demo = gr.Interface(fn=greet, inputs="textbox", outputs="textbox", api_name="predict")
|
| 309 |
+
|
| 310 |
+
demo.launch()
|
| 311 |
+
```
|
| 312 |
+
|
| 313 |
+
## Image Editor
|
| 314 |
+
|
| 315 |
+
```python
|
| 316 |
+
import gradio as gr
|
| 317 |
+
import time
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
def sleep(im):
|
| 321 |
+
time.sleep(5)
|
| 322 |
+
return [im["background"], im["layers"][0], im["layers"][1], im["composite"]]
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
def predict(im):
|
| 326 |
+
return im["composite"]
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
with gr.Blocks() as demo:
|
| 330 |
+
with gr.Row():
|
| 331 |
+
im = gr.ImageEditor(
|
| 332 |
+
type="numpy",
|
| 333 |
+
)
|
| 334 |
+
im_preview = gr.Image()
|
| 335 |
+
n_upload = gr.Number(0, label="Number of upload events", step=1)
|
| 336 |
+
n_change = gr.Number(0, label="Number of change events", step=1)
|
| 337 |
+
n_input = gr.Number(0, label="Number of input events", step=1)
|
| 338 |
+
|
| 339 |
+
im.upload(lambda x: x + 1, outputs=n_upload, inputs=n_upload)
|
| 340 |
+
im.change(lambda x: x + 1, outputs=n_change, inputs=n_change)
|
| 341 |
+
im.input(lambda x: x + 1, outputs=n_input, inputs=n_input)
|
| 342 |
+
im.change(predict, outputs=im_preview, inputs=im, show_progress="hidden")
|
| 343 |
+
|
| 344 |
+
demo.launch()
|
| 345 |
+
```
|
| 346 |
+
|
| 347 |
+
## On Listener Decorator
|
| 348 |
+
|
| 349 |
+
```python
|
| 350 |
+
import gradio as gr
|
| 351 |
+
|
| 352 |
+
with gr.Blocks() as demo:
|
| 353 |
+
name = gr.Textbox(label="Name")
|
| 354 |
+
output = gr.Textbox(label="Output Box")
|
| 355 |
+
greet_btn = gr.Button("Greet")
|
| 356 |
+
|
| 357 |
+
@gr.on(triggers=[name.submit, greet_btn.click], inputs=name, outputs=output)
|
| 358 |
+
def greet(name):
|
| 359 |
+
return "Hello " + name + "!"
|
| 360 |
+
|
| 361 |
+
demo.launch()
|
| 362 |
+
```
|
| 363 |
+
|
| 364 |
+
## Render Merge
|
| 365 |
+
|
| 366 |
+
```python
|
| 367 |
+
import gradio as gr
|
| 368 |
+
import time
|
| 369 |
+
|
| 370 |
+
with gr.Blocks() as demo:
|
| 371 |
+
text_count = gr.Slider(1, 5, value=1, step=1, label="Textbox Count")
|
| 372 |
+
|
| 373 |
+
@gr.render(inputs=text_count)
|
| 374 |
+
def render_count(count):
|
| 375 |
+
boxes = []
|
| 376 |
+
for i in range(count):
|
| 377 |
+
box = gr.Textbox(label=f"Box {i}")
|
| 378 |
+
boxes.append(box)
|
| 379 |
+
|
| 380 |
+
def merge(*args):
|
| 381 |
+
time.sleep(0.2) # simulate a delay
|
| 382 |
+
return " ".join(args)
|
| 383 |
+
|
| 384 |
+
merge_btn.click(merge, boxes, output)
|
| 385 |
+
|
| 386 |
+
def clear():
|
| 387 |
+
time.sleep(0.2) # simulate a delay
|
| 388 |
+
return [" "] * count
|
| 389 |
+
|
| 390 |
+
clear_btn.click(clear, None, boxes)
|
| 391 |
+
|
| 392 |
+
def countup():
|
| 393 |
+
time.sleep(0.2) # simulate a delay
|
| 394 |
+
return list(range(count))
|
| 395 |
+
|
| 396 |
+
count_btn.click(countup, None, boxes, queue=False)
|
| 397 |
+
|
| 398 |
+
with gr.Row():
|
| 399 |
+
merge_btn = gr.Button("Merge")
|
| 400 |
+
clear_btn = gr.Button("Clear")
|
| 401 |
+
count_btn = gr.Button("Count")
|
| 402 |
+
|
| 403 |
+
output = gr.Textbox()
|
| 404 |
+
|
| 405 |
+
demo.launch()
|
| 406 |
+
```
|
| 407 |
+
|
| 408 |
+
## Reverse Audio 2
|
| 409 |
+
|
| 410 |
+
```python
|
| 411 |
+
import gradio as gr
|
| 412 |
+
import numpy as np
|
| 413 |
+
|
| 414 |
+
def reverse_audio(audio):
|
| 415 |
+
sr, data = audio
|
| 416 |
+
return (sr, np.flipud(data))
|
| 417 |
+
|
| 418 |
+
demo = gr.Interface(fn=reverse_audio,
|
| 419 |
+
inputs="microphone",
|
| 420 |
+
outputs="audio", api_name="predict")
|
| 421 |
+
|
| 422 |
+
demo.launch()
|
| 423 |
+
```
|
| 424 |
+
|
| 425 |
+
## Sepia Filter
|
| 426 |
+
|
| 427 |
+
```python
|
| 428 |
+
import numpy as np
|
| 429 |
+
import gradio as gr
|
| 430 |
+
|
| 431 |
+
def sepia(input_img):
|
| 432 |
+
sepia_filter = np.array([
|
| 433 |
+
[0.393, 0.769, 0.189],
|
| 434 |
+
[0.349, 0.686, 0.168],
|
| 435 |
+
[0.272, 0.534, 0.131]
|
| 436 |
+
])
|
| 437 |
+
sepia_img = input_img.dot(sepia_filter.T)
|
| 438 |
+
sepia_img /= sepia_img.max()
|
| 439 |
+
return sepia_img
|
| 440 |
+
|
| 441 |
+
demo = gr.Interface(sepia, gr.Image(), "image", api_name="predict")
|
| 442 |
+
demo.launch()
|
| 443 |
+
```
|
| 444 |
+
|
| 445 |
+
## Sort Records
|
| 446 |
+
|
| 447 |
+
```python
|
| 448 |
+
import gradio as gr
|
| 449 |
+
|
| 450 |
+
def sort_records(records):
|
| 451 |
+
return records.sort("Quantity")
|
| 452 |
+
|
| 453 |
+
demo = gr.Interface(
|
| 454 |
+
sort_records,
|
| 455 |
+
gr.Dataframe(
|
| 456 |
+
headers=["Item", "Quantity"],
|
| 457 |
+
datatype=["str", "number"],
|
| 458 |
+
row_count=3,
|
| 459 |
+
column_count=2,
|
| 460 |
+
column_limits=(2, 2),
|
| 461 |
+
type="polars"
|
| 462 |
+
),
|
| 463 |
+
"dataframe",
|
| 464 |
+
description="Sort by Quantity"
|
| 465 |
+
)
|
| 466 |
+
|
| 467 |
+
demo.launch()
|
| 468 |
+
```
|
| 469 |
+
|
| 470 |
+
## Streaming Simple
|
| 471 |
+
|
| 472 |
+
```python
|
| 473 |
+
import gradio as gr
|
| 474 |
+
|
| 475 |
+
with gr.Blocks() as demo:
|
| 476 |
+
with gr.Row():
|
| 477 |
+
with gr.Column():
|
| 478 |
+
input_img = gr.Image(label="Input", sources="webcam")
|
| 479 |
+
with gr.Column():
|
| 480 |
+
output_img = gr.Image(label="Output")
|
| 481 |
+
input_img.stream(lambda s: s, input_img, output_img, time_limit=15, stream_every=0.1, concurrency_limit=30)
|
| 482 |
+
|
| 483 |
+
if __name__ == "__main__":
|
| 484 |
+
|
| 485 |
+
demo.launch()
|
| 486 |
+
```
|
| 487 |
+
|
| 488 |
+
## Tabbed Interface Lite
|
| 489 |
+
|
| 490 |
+
```python
|
| 491 |
+
import gradio as gr
|
| 492 |
+
|
| 493 |
+
hello_world = gr.Interface(lambda name: "Hello " + name, "text", "text", api_name="predict")
|
| 494 |
+
bye_world = gr.Interface(lambda name: "Bye " + name, "text", "text", api_name="predict")
|
| 495 |
+
chat = gr.ChatInterface(lambda *args: "Hello " + args[0], api_name="chat")
|
| 496 |
+
|
| 497 |
+
demo = gr.TabbedInterface([hello_world, bye_world, chat], ["Hello World", "Bye World", "Chat"])
|
| 498 |
+
|
| 499 |
+
demo.launch()
|
| 500 |
+
```
|
| 501 |
+
|
| 502 |
+
## Tax Calculator
|
| 503 |
+
|
| 504 |
+
```python
|
| 505 |
+
import gradio as gr
|
| 506 |
+
|
| 507 |
+
def tax_calculator(income, marital_status, assets):
|
| 508 |
+
tax_brackets = [(10, 0), (25, 8), (60, 12), (120, 20), (250, 30)]
|
| 509 |
+
total_deductible = sum(cost for cost, deductible in zip(assets["Cost"], assets["Deductible"]) if deductible)
|
| 510 |
+
taxable_income = income - total_deductible
|
| 511 |
+
|
| 512 |
+
total_tax = 0
|
| 513 |
+
for bracket, rate in tax_brackets:
|
| 514 |
+
if taxable_income > bracket:
|
| 515 |
+
total_tax += (taxable_income - bracket) * rate / 100
|
| 516 |
+
|
| 517 |
+
if marital_status == "Married":
|
| 518 |
+
total_tax *= 0.75
|
| 519 |
+
elif marital_status == "Divorced":
|
| 520 |
+
total_tax *= 0.8
|
| 521 |
+
|
| 522 |
+
return round(total_tax)
|
| 523 |
+
|
| 524 |
+
demo = gr.Interface(
|
| 525 |
+
tax_calculator,
|
| 526 |
+
[
|
| 527 |
+
"number",
|
| 528 |
+
gr.Radio(["Single", "Married", "Divorced"]),
|
| 529 |
+
gr.Dataframe(
|
| 530 |
+
headers=["Item", "Cost", "Deductible"],
|
| 531 |
+
datatype=["str", "number", "bool"],
|
| 532 |
+
label="Assets Purchased this Year",
|
| 533 |
+
),
|
| 534 |
+
],
|
| 535 |
+
gr.Number(label="Tax due"),
|
| 536 |
+
examples=[
|
| 537 |
+
[10000, "Married", [["Suit", 5000, True], ["Laptop (for work)", 800, False], ["Car", 1800, True]]],
|
| 538 |
+
[80000, "Single", [["Suit", 800, True], ["Watch", 1800, True], ["Food", 800, True]]],
|
| 539 |
+
],
|
| 540 |
+
live=True,
|
| 541 |
+
api_name="predict"
|
| 542 |
+
)
|
| 543 |
+
|
| 544 |
+
demo.launch()
|
| 545 |
+
```
|
| 546 |
+
|
| 547 |
+
## Timer Simple
|
| 548 |
+
|
| 549 |
+
```python
|
| 550 |
+
import gradio as gr
|
| 551 |
+
import random
|
| 552 |
+
import time
|
| 553 |
+
|
| 554 |
+
with gr.Blocks() as demo:
|
| 555 |
+
timer = gr.Timer(1)
|
| 556 |
+
timestamp = gr.Number(label="Time")
|
| 557 |
+
timer.tick(lambda: round(time.time()), outputs=timestamp, api_name="timestamp")
|
| 558 |
+
|
| 559 |
+
number = gr.Number(lambda: random.randint(1, 10), every=timer, label="Random Number")
|
| 560 |
+
with gr.Row():
|
| 561 |
+
gr.Button("Start").click(lambda: gr.Timer(active=True), None, timer)
|
| 562 |
+
gr.Button("Stop").click(lambda: gr.Timer(active=False), None, timer)
|
| 563 |
+
gr.Button("Go Fast").click(lambda: 0.2, None, timer)
|
| 564 |
+
|
| 565 |
+
if __name__ == "__main__":
|
| 566 |
+
demo.launch()
|
| 567 |
+
```
|
| 568 |
+
|
| 569 |
+
## Variable Outputs
|
| 570 |
+
|
| 571 |
+
```python
|
| 572 |
+
import gradio as gr
|
| 573 |
+
|
| 574 |
+
max_textboxes = 10
|
| 575 |
+
|
| 576 |
+
def variable_outputs(k):
|
| 577 |
+
k = int(k)
|
| 578 |
+
return [gr.Textbox(visible=True)]*k + [gr.Textbox(visible=False)]*(max_textboxes-k)
|
| 579 |
+
|
| 580 |
+
with gr.Blocks() as demo:
|
| 581 |
+
s = gr.Slider(1, max_textboxes, value=max_textboxes, step=1, label="How many textboxes to show:")
|
| 582 |
+
textboxes = []
|
| 583 |
+
for i in range(max_textboxes):
|
| 584 |
+
t = gr.Textbox(f"Textbox {i}")
|
| 585 |
+
textboxes.append(t)
|
| 586 |
+
|
| 587 |
+
s.change(variable_outputs, s, textboxes)
|
| 588 |
+
|
| 589 |
+
if __name__ == "__main__":
|
| 590 |
+
demo.launch()
|
| 591 |
+
```
|
| 592 |
+
|
| 593 |
+
## Video Identity
|
| 594 |
+
|
| 595 |
+
```python
|
| 596 |
+
import gradio as gr
|
| 597 |
+
from gradio.media import get_video
|
| 598 |
+
|
| 599 |
+
def video_identity(video):
|
| 600 |
+
return video
|
| 601 |
+
|
| 602 |
+
# get_video() returns file paths to sample media included with Gradio
|
| 603 |
+
demo = gr.Interface(video_identity,
|
| 604 |
+
gr.Video(),
|
| 605 |
+
"playable_video",
|
| 606 |
+
examples=[
|
| 607 |
+
get_video("world.mp4")
|
| 608 |
+
],
|
| 609 |
+
cache_examples=True,
|
| 610 |
+
api_name="predict",)
|
| 611 |
+
|
| 612 |
+
demo.launch()
|
| 613 |
+
```
|
.agents/skills/hf-cli/SKILL.md
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
name: hf-cli
|
| 3 |
+
description: "Hugging Face Hub CLI (`hf`) for downloading, uploading, and managing repositories, models, datasets, and Spaces on the Hugging Face Hub. Replaces now deprecated `huggingface-cli` command."
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
Install: `curl -LsSf https://hf.co/cli/install.sh | bash -s`.
|
| 7 |
+
|
| 8 |
+
The Hugging Face Hub CLI tool `hf` is available. IMPORTANT: The `hf` command replaces the deprecated `huggingface-cli` command.
|
| 9 |
+
|
| 10 |
+
Use `hf --help` to view available functions. Note that auth commands are now all under `hf auth` e.g. `hf auth whoami`.
|
| 11 |
+
|
| 12 |
+
Generated with `huggingface_hub v1.6.0`. Run `hf skills add --force` to regenerate.
|
| 13 |
+
|
| 14 |
+
## Commands
|
| 15 |
+
|
| 16 |
+
- `hf download REPO_ID` — Download files from the Hub.
|
| 17 |
+
- `hf env` — Print information about the environment.
|
| 18 |
+
- `hf sync` — Sync files between local directory and a bucket.
|
| 19 |
+
- `hf upload REPO_ID` — Upload a file or a folder to the Hub. Recommended for single-commit uploads.
|
| 20 |
+
- `hf upload-large-folder REPO_ID LOCAL_PATH` — Upload a large folder to the Hub. Recommended for resumable uploads.
|
| 21 |
+
- `hf version` — Print information about the hf version.
|
| 22 |
+
|
| 23 |
+
### `hf auth` — Manage authentication (login, logout, etc.).
|
| 24 |
+
|
| 25 |
+
- `hf auth list` — List all stored access tokens.
|
| 26 |
+
- `hf auth login` — Login using a token from huggingface.co/settings/tokens.
|
| 27 |
+
- `hf auth logout` — Logout from a specific token.
|
| 28 |
+
- `hf auth switch` — Switch between access tokens.
|
| 29 |
+
- `hf auth whoami` — Find out which huggingface.co account you are logged in as.
|
| 30 |
+
|
| 31 |
+
### `hf buckets` — Commands to interact with buckets.
|
| 32 |
+
|
| 33 |
+
- `hf buckets cp SRC` — Copy a single file to or from a bucket.
|
| 34 |
+
- `hf buckets create BUCKET_ID` — Create a new bucket.
|
| 35 |
+
- `hf buckets delete BUCKET_ID` — Delete a bucket.
|
| 36 |
+
- `hf buckets info BUCKET_ID` — Get info about a bucket.
|
| 37 |
+
- `hf buckets list` — List buckets or files in a bucket.
|
| 38 |
+
- `hf buckets move FROM_ID TO_ID` — Move (rename) a bucket to a new name or namespace.
|
| 39 |
+
- `hf buckets remove ARGUMENT` — Remove files from a bucket.
|
| 40 |
+
- `hf buckets sync` — Sync files between local directory and a bucket.
|
| 41 |
+
|
| 42 |
+
### `hf cache` — Manage local cache directory.
|
| 43 |
+
|
| 44 |
+
- `hf cache ls` — List cached repositories or revisions.
|
| 45 |
+
- `hf cache prune` — Remove detached revisions from the cache.
|
| 46 |
+
- `hf cache rm TARGETS` — Remove cached repositories or revisions.
|
| 47 |
+
- `hf cache verify REPO_ID` — Verify checksums for a single repo revision from cache or a local directory.
|
| 48 |
+
|
| 49 |
+
### `hf collections` — Interact with collections on the Hub.
|
| 50 |
+
|
| 51 |
+
- `hf collections add-item COLLECTION_SLUG ITEM_ID ITEM_TYPE` — Add an item to a collection.
|
| 52 |
+
- `hf collections create TITLE` — Create a new collection on the Hub.
|
| 53 |
+
- `hf collections delete COLLECTION_SLUG` — Delete a collection from the Hub.
|
| 54 |
+
- `hf collections delete-item COLLECTION_SLUG ITEM_OBJECT_ID` — Delete an item from a collection.
|
| 55 |
+
- `hf collections info COLLECTION_SLUG` — Get info about a collection on the Hub.
|
| 56 |
+
- `hf collections ls` — List collections on the Hub.
|
| 57 |
+
- `hf collections update COLLECTION_SLUG` — Update a collection's metadata on the Hub.
|
| 58 |
+
- `hf collections update-item COLLECTION_SLUG ITEM_OBJECT_ID` — Update an item in a collection.
|
| 59 |
+
|
| 60 |
+
### `hf datasets` — Interact with datasets on the Hub.
|
| 61 |
+
|
| 62 |
+
- `hf datasets info DATASET_ID` — Get info about a dataset on the Hub.
|
| 63 |
+
- `hf datasets ls` — List datasets on the Hub.
|
| 64 |
+
- `hf datasets parquet DATASET_ID` — List parquet file URLs available for a dataset.
|
| 65 |
+
- `hf datasets sql SQL` — Execute a raw SQL query with DuckDB against dataset parquet URLs.
|
| 66 |
+
|
| 67 |
+
### `hf discussions` — Manage discussions and pull requests on the Hub.
|
| 68 |
+
|
| 69 |
+
- `hf discussions close REPO_ID NUM` — Close a discussion or pull request.
|
| 70 |
+
- `hf discussions comment REPO_ID NUM` — Comment on a discussion or pull request.
|
| 71 |
+
- `hf discussions create REPO_ID title` — Create a new discussion or pull request on a repo.
|
| 72 |
+
- `hf discussions diff REPO_ID NUM` — Show the diff of a pull request.
|
| 73 |
+
- `hf discussions info REPO_ID NUM` — Get info about a discussion or pull request.
|
| 74 |
+
- `hf discussions list REPO_ID` — List discussions and pull requests on a repo.
|
| 75 |
+
- `hf discussions merge REPO_ID NUM` — Merge a pull request.
|
| 76 |
+
- `hf discussions rename REPO_ID NUM NEW_TITLE` — Rename a discussion or pull request.
|
| 77 |
+
- `hf discussions reopen REPO_ID NUM` — Reopen a closed discussion or pull request.
|
| 78 |
+
|
| 79 |
+
### `hf endpoints` — Manage Hugging Face Inference Endpoints.
|
| 80 |
+
|
| 81 |
+
- `hf endpoints catalog` — Interact with the Inference Endpoints catalog.
|
| 82 |
+
- `hf endpoints delete NAME` — Delete an Inference Endpoint permanently.
|
| 83 |
+
- `hf endpoints deploy NAME repo framework accelerator instance_size instance_type region vendor` — Deploy an Inference Endpoint from a Hub repository.
|
| 84 |
+
- `hf endpoints describe NAME` — Get information about an existing endpoint.
|
| 85 |
+
- `hf endpoints ls` — Lists all Inference Endpoints for the given namespace.
|
| 86 |
+
- `hf endpoints pause NAME` — Pause an Inference Endpoint.
|
| 87 |
+
- `hf endpoints resume NAME` — Resume an Inference Endpoint.
|
| 88 |
+
- `hf endpoints scale-to-zero NAME` — Scale an Inference Endpoint to zero.
|
| 89 |
+
- `hf endpoints update NAME` — Update an existing endpoint.
|
| 90 |
+
|
| 91 |
+
### `hf extensions` — Manage hf CLI extensions.
|
| 92 |
+
|
| 93 |
+
- `hf extensions exec NAME` — Execute an installed extension.
|
| 94 |
+
- `hf extensions install REPO_ID` — Install an extension from a public GitHub repository.
|
| 95 |
+
- `hf extensions list` — List installed extension commands.
|
| 96 |
+
- `hf extensions remove NAME` — Remove an installed extension.
|
| 97 |
+
|
| 98 |
+
### `hf jobs` — Run and manage Jobs on the Hub.
|
| 99 |
+
|
| 100 |
+
- `hf jobs cancel JOB_ID` — Cancel a Job
|
| 101 |
+
- `hf jobs hardware` — List available hardware options for Jobs
|
| 102 |
+
- `hf jobs inspect JOB_IDS` — Display detailed information on one or more Jobs
|
| 103 |
+
- `hf jobs logs JOB_ID` — Fetch the logs of a Job.
|
| 104 |
+
- `hf jobs ps` — List Jobs.
|
| 105 |
+
- `hf jobs run IMAGE COMMAND` — Run a Job.
|
| 106 |
+
- `hf jobs scheduled` — Create and manage scheduled Jobs on the Hub.
|
| 107 |
+
- `hf jobs stats` — Fetch the resource usage statistics and metrics of Jobs
|
| 108 |
+
- `hf jobs uv` — Run UV scripts (Python with inline dependencies) on HF infrastructure.
|
| 109 |
+
|
| 110 |
+
### `hf models` — Interact with models on the Hub.
|
| 111 |
+
|
| 112 |
+
- `hf models info MODEL_ID` — Get info about a model on the Hub.
|
| 113 |
+
- `hf models ls` — List models on the Hub.
|
| 114 |
+
|
| 115 |
+
### `hf papers` — Interact with papers on the Hub.
|
| 116 |
+
|
| 117 |
+
- `hf papers ls` — List daily papers on the Hub.
|
| 118 |
+
|
| 119 |
+
### `hf repos` — Manage repos on the Hub.
|
| 120 |
+
|
| 121 |
+
- `hf repos branch` — Manage branches for a repo on the Hub.
|
| 122 |
+
- `hf repos create REPO_ID` — Create a new repo on the Hub.
|
| 123 |
+
- `hf repos delete REPO_ID` — Delete a repo from the Hub. This is an irreversible operation.
|
| 124 |
+
- `hf repos delete-files REPO_ID PATTERNS` — Delete files from a repo on the Hub.
|
| 125 |
+
- `hf repos duplicate FROM_ID` — Duplicate a repo on the Hub (model, dataset, or Space).
|
| 126 |
+
- `hf repos move FROM_ID TO_ID` — Move a repository from a namespace to another namespace.
|
| 127 |
+
- `hf repos settings REPO_ID` — Update the settings of a repository.
|
| 128 |
+
- `hf repos tag` — Manage tags for a repo on the Hub.
|
| 129 |
+
|
| 130 |
+
### `hf skills` — Manage skills for AI assistants.
|
| 131 |
+
|
| 132 |
+
- `hf skills add` — Download a skill and install it for an AI assistant.
|
| 133 |
+
- `hf skills preview` — Print the generated SKILL.md to stdout.
|
| 134 |
+
|
| 135 |
+
### `hf spaces` — Interact with spaces on the Hub.
|
| 136 |
+
|
| 137 |
+
- `hf spaces dev-mode SPACE_ID` — Enable or disable dev mode on a Space.
|
| 138 |
+
- `hf spaces hot-reload SPACE_ID` — Hot-reload any Python file of a Space without a full rebuild + restart.
|
| 139 |
+
- `hf spaces info SPACE_ID` — Get info about a space on the Hub.
|
| 140 |
+
- `hf spaces ls` — List spaces on the Hub.
|
| 141 |
+
|
| 142 |
+
### `hf webhooks` — Manage webhooks on the Hub.
|
| 143 |
+
|
| 144 |
+
- `hf webhooks create watch` — Create a new webhook.
|
| 145 |
+
- `hf webhooks delete WEBHOOK_ID` — Delete a webhook permanently.
|
| 146 |
+
- `hf webhooks disable WEBHOOK_ID` — Disable an active webhook.
|
| 147 |
+
- `hf webhooks enable WEBHOOK_ID` — Enable a disabled webhook.
|
| 148 |
+
- `hf webhooks info WEBHOOK_ID` — Show full details for a single webhook as JSON.
|
| 149 |
+
- `hf webhooks list` — List all webhooks for the current user.
|
| 150 |
+
- `hf webhooks update WEBHOOK_ID` — Update an existing webhook. Only provided options are changed.
|
| 151 |
+
|
| 152 |
+
## Tips
|
| 153 |
+
|
| 154 |
+
- Use `hf <command> --help` for full options, usage, and real-world examples
|
| 155 |
+
- Use `--format json` for machine-readable output on list commands
|
| 156 |
+
- Use `-q` / `--quiet` to print only IDs
|
| 157 |
+
- Authenticate with `HF_TOKEN` env var (recommended) or with `--token`
|
.gitignore
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Outputs
|
| 2 |
+
outputs/
|
| 3 |
+
|
| 4 |
+
# Byte-compiled / optimized / DLL files
|
| 5 |
+
__pycache__/
|
| 6 |
+
*.py[codz]
|
| 7 |
+
*$py.class
|
| 8 |
+
|
| 9 |
+
# C extensions
|
| 10 |
+
*.so
|
| 11 |
+
|
| 12 |
+
# Distribution / packaging
|
| 13 |
+
.Python
|
| 14 |
+
build/
|
| 15 |
+
develop-eggs/
|
| 16 |
+
dist/
|
| 17 |
+
downloads/
|
| 18 |
+
eggs/
|
| 19 |
+
.eggs/
|
| 20 |
+
lib/
|
| 21 |
+
lib64/
|
| 22 |
+
parts/
|
| 23 |
+
sdist/
|
| 24 |
+
var/
|
| 25 |
+
wheels/
|
| 26 |
+
share/python-wheels/
|
| 27 |
+
*.egg-info/
|
| 28 |
+
.installed.cfg
|
| 29 |
+
*.egg
|
| 30 |
+
MANIFEST
|
| 31 |
+
|
| 32 |
+
# PyInstaller
|
| 33 |
+
# Usually these files are written by a python script from a template
|
| 34 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
| 35 |
+
*.manifest
|
| 36 |
+
*.spec
|
| 37 |
+
|
| 38 |
+
# Installer logs
|
| 39 |
+
pip-log.txt
|
| 40 |
+
pip-delete-this-directory.txt
|
| 41 |
+
|
| 42 |
+
# Unit test / coverage reports
|
| 43 |
+
htmlcov/
|
| 44 |
+
.tox/
|
| 45 |
+
.nox/
|
| 46 |
+
.coverage
|
| 47 |
+
.coverage.*
|
| 48 |
+
.cache
|
| 49 |
+
nosetests.xml
|
| 50 |
+
coverage.xml
|
| 51 |
+
*.cover
|
| 52 |
+
*.py.cover
|
| 53 |
+
.hypothesis/
|
| 54 |
+
.pytest_cache/
|
| 55 |
+
cover/
|
| 56 |
+
|
| 57 |
+
# Translations
|
| 58 |
+
*.mo
|
| 59 |
+
*.pot
|
| 60 |
+
|
| 61 |
+
# Django stuff:
|
| 62 |
+
*.log
|
| 63 |
+
local_settings.py
|
| 64 |
+
db.sqlite3
|
| 65 |
+
db.sqlite3-journal
|
| 66 |
+
|
| 67 |
+
# Flask stuff:
|
| 68 |
+
instance/
|
| 69 |
+
.webassets-cache
|
| 70 |
+
|
| 71 |
+
# Scrapy stuff:
|
| 72 |
+
.scrapy
|
| 73 |
+
|
| 74 |
+
# Sphinx documentation
|
| 75 |
+
docs/_build/
|
| 76 |
+
|
| 77 |
+
# PyBuilder
|
| 78 |
+
.pybuilder/
|
| 79 |
+
target/
|
| 80 |
+
|
| 81 |
+
# Jupyter Notebook
|
| 82 |
+
.ipynb_checkpoints
|
| 83 |
+
|
| 84 |
+
# IPython
|
| 85 |
+
profile_default/
|
| 86 |
+
ipython_config.py
|
| 87 |
+
|
| 88 |
+
# pyenv
|
| 89 |
+
# For a library or package, you might want to ignore these files since the code is
|
| 90 |
+
# intended to run in multiple environments; otherwise, check them in:
|
| 91 |
+
# .python-version
|
| 92 |
+
|
| 93 |
+
# pipenv
|
| 94 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
| 95 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
| 96 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
| 97 |
+
# install all needed dependencies.
|
| 98 |
+
# Pipfile.lock
|
| 99 |
+
|
| 100 |
+
# UV
|
| 101 |
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
| 102 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
| 103 |
+
# commonly ignored for libraries.
|
| 104 |
+
# uv.lock
|
| 105 |
+
|
| 106 |
+
# poetry
|
| 107 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
| 108 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
| 109 |
+
# commonly ignored for libraries.
|
| 110 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
| 111 |
+
# poetry.lock
|
| 112 |
+
# poetry.toml
|
| 113 |
+
|
| 114 |
+
# pdm
|
| 115 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
| 116 |
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
| 117 |
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
| 118 |
+
# pdm.lock
|
| 119 |
+
# pdm.toml
|
| 120 |
+
.pdm-python
|
| 121 |
+
.pdm-build/
|
| 122 |
+
|
| 123 |
+
# pixi
|
| 124 |
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
| 125 |
+
# pixi.lock
|
| 126 |
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
| 127 |
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
| 128 |
+
.pixi
|
| 129 |
+
|
| 130 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
| 131 |
+
__pypackages__/
|
| 132 |
+
|
| 133 |
+
# Celery stuff
|
| 134 |
+
celerybeat-schedule
|
| 135 |
+
celerybeat.pid
|
| 136 |
+
|
| 137 |
+
# Redis
|
| 138 |
+
*.rdb
|
| 139 |
+
*.aof
|
| 140 |
+
*.pid
|
| 141 |
+
|
| 142 |
+
# RabbitMQ
|
| 143 |
+
mnesia/
|
| 144 |
+
rabbitmq/
|
| 145 |
+
rabbitmq-data/
|
| 146 |
+
|
| 147 |
+
# ActiveMQ
|
| 148 |
+
activemq-data/
|
| 149 |
+
|
| 150 |
+
# SageMath parsed files
|
| 151 |
+
*.sage.py
|
| 152 |
+
|
| 153 |
+
# Environments
|
| 154 |
+
.env
|
| 155 |
+
.envrc
|
| 156 |
+
.venv
|
| 157 |
+
env/
|
| 158 |
+
venv/
|
| 159 |
+
ENV/
|
| 160 |
+
env.bak/
|
| 161 |
+
venv.bak/
|
| 162 |
+
|
| 163 |
+
# Spyder project settings
|
| 164 |
+
.spyderproject
|
| 165 |
+
.spyproject
|
| 166 |
+
|
| 167 |
+
# Rope project settings
|
| 168 |
+
.ropeproject
|
| 169 |
+
|
| 170 |
+
# mkdocs documentation
|
| 171 |
+
/site
|
| 172 |
+
|
| 173 |
+
# mypy
|
| 174 |
+
.mypy_cache/
|
| 175 |
+
.dmypy.json
|
| 176 |
+
dmypy.json
|
| 177 |
+
|
| 178 |
+
# Pyre type checker
|
| 179 |
+
.pyre/
|
| 180 |
+
|
| 181 |
+
# pytype static type analyzer
|
| 182 |
+
.pytype/
|
| 183 |
+
|
| 184 |
+
# Cython debug symbols
|
| 185 |
+
cython_debug/
|
| 186 |
+
|
| 187 |
+
# PyCharm
|
| 188 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
| 189 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
| 190 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
| 191 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
| 192 |
+
# .idea/
|
| 193 |
+
|
| 194 |
+
# Abstra
|
| 195 |
+
# Abstra is an AI-powered process automation framework.
|
| 196 |
+
# Ignore directories containing user credentials, local state, and settings.
|
| 197 |
+
# Learn more at https://abstra.io/docs
|
| 198 |
+
.abstra/
|
| 199 |
+
|
| 200 |
+
# Visual Studio Code
|
| 201 |
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
| 202 |
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
| 203 |
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
| 204 |
+
# you could uncomment the following to ignore the entire vscode folder
|
| 205 |
+
# .vscode/
|
| 206 |
+
|
| 207 |
+
# Ruff stuff:
|
| 208 |
+
.ruff_cache/
|
| 209 |
+
|
| 210 |
+
# PyPI configuration file
|
| 211 |
+
.pypirc
|
| 212 |
+
|
| 213 |
+
# Marimo
|
| 214 |
+
marimo/_static/
|
| 215 |
+
marimo/_lsp/
|
| 216 |
+
__marimo__/
|
| 217 |
+
|
| 218 |
+
# Streamlit
|
| 219 |
+
.streamlit/secrets.toml
|
.python-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
3.13
|
Makefile
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
run:
|
| 2 |
+
conda run -n ml python app.py
|
README.md
CHANGED
|
@@ -1,12 +0,0 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: FastMedExtract
|
| 3 |
-
emoji: 🏃
|
| 4 |
-
colorFrom: indigo
|
| 5 |
-
colorTo: purple
|
| 6 |
-
sdk: gradio
|
| 7 |
-
sdk_version: 6.9.0
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
-
---
|
| 11 |
-
|
| 12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
|
@@ -7,13 +7,17 @@ model = GLiNER.from_pretrained("Ihor/gliner-biomed-base-v1.0")
|
|
| 7 |
MAX_LABELS = 12
|
| 8 |
|
| 9 |
PALETTE = [
|
| 10 |
-
"#
|
| 11 |
-
"#
|
| 12 |
]
|
| 13 |
|
| 14 |
DEFAULT_LABELS = ["patient_name", "age", "sex", "symptom", "diagnosis", "medication", "vital_sign", "procedure"]
|
| 15 |
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
def extract(text, labels_list, threshold):
|
| 18 |
labels = [l for l in labels_list if l][:MAX_LABELS]
|
| 19 |
if not labels or not text.strip():
|
|
@@ -136,6 +140,7 @@ with gr.Blocks(title="GLiNER Biomedical NER") as demo:
|
|
| 136 |
highlight_output = gr.HighlightedText(label="Entities", combine_adjacent=False, show_legend=True)
|
| 137 |
table_output = gr.Dataframe(headers=["Label", "Text", "Score"], label="Extracted Entities")
|
| 138 |
|
|
|
|
| 139 |
run_btn.click(extract, inputs=[text_input, labels_input, threshold], outputs=[highlight_output, table_output, latency_output])
|
| 140 |
gr.Examples(EXAMPLES, inputs=[text_input, labels_input, threshold])
|
| 141 |
|
|
|
|
| 7 |
MAX_LABELS = 12
|
| 8 |
|
| 9 |
PALETTE = [
|
| 10 |
+
"#FF6B6B", "#4ECDC4", "#45B7D1", "#FFA07A", "#98D8C8", "#F7DC6F",
|
| 11 |
+
"#BB8FCE", "#85C1E9", "#F0B27A", "#76D7C4", "#F1948A", "#82E0AA",
|
| 12 |
]
|
| 13 |
|
| 14 |
DEFAULT_LABELS = ["patient_name", "age", "sex", "symptom", "diagnosis", "medication", "vital_sign", "procedure"]
|
| 15 |
|
| 16 |
|
| 17 |
+
def filter_choices(selected):
|
| 18 |
+
return gr.Dropdown(choices=[l for l in DEFAULT_LABELS if l not in selected])
|
| 19 |
+
|
| 20 |
+
|
| 21 |
def extract(text, labels_list, threshold):
|
| 22 |
labels = [l for l in labels_list if l][:MAX_LABELS]
|
| 23 |
if not labels or not text.strip():
|
|
|
|
| 140 |
highlight_output = gr.HighlightedText(label="Entities", combine_adjacent=False, show_legend=True)
|
| 141 |
table_output = gr.Dataframe(headers=["Label", "Text", "Score"], label="Extracted Entities")
|
| 142 |
|
| 143 |
+
labels_input.change(filter_choices, inputs=[labels_input], outputs=[labels_input])
|
| 144 |
run_btn.click(extract, inputs=[text_input, labels_input, threshold], outputs=[highlight_output, table_output, latency_output])
|
| 145 |
gr.Examples(EXAMPLES, inputs=[text_input, labels_input, threshold])
|
| 146 |
|
requirements.txt
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
-
|
|
|
|
|
|
| 1 |
+
gradio==6.9.0
|
| 2 |
+
gliner==0.2.25
|
skills-lock.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"version": 1,
|
| 3 |
+
"skills": {
|
| 4 |
+
"hf-cli": {
|
| 5 |
+
"source": "huggingface/skills",
|
| 6 |
+
"sourceType": "github",
|
| 7 |
+
"computedHash": "0d20bb5d20960b7fdef4148f805a26a861a10e301c88261ca5f9614f63ed9494"
|
| 8 |
+
}
|
| 9 |
+
}
|
| 10 |
+
}
|