gradio-datetimerange


Namegradio-datetimerange JSON
Version 0.0.1 PyPI version JSON
download
home_pageNone
SummaryComponent to create time ranges.
upload_time2024-07-23 18:38:44
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords gradio-custom-component gradio-template-datetime
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ---
tags: [gradio-custom-component, DateTime]
title: gradio_datetimerange
short_description: Component to create time ranges.
colorFrom: blue
colorTo: yellow
sdk: gradio
pinned: false
app_file: space.py
---

# `gradio_datetimerange`
<img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0.1%20-%20orange">  

Component to create time ranges.

## Installation

```bash
pip install gradio_datetimerange
```

## Usage

```python

import gradio as gr
from gradio_datetimerange import DateTimeRange
import pandas as pd
from random import randint

temp_sensor_data = pd.DataFrame(
    {
        "time": pd.date_range("2021-01-01", end="2021-01-05", periods=200),
        "temperature": [randint(50 + 10 * (i % 2), 65 + 15 * (i % 2)) for i in range(200)],
        "humidity": [randint(50 + 10 * (i % 2), 65 + 15 * (i % 2)) for i in range(200)],
        "location": ["indoor", "outdoor"] * 100,
    }
)

with gr.Blocks() as demo:
    date = DateTimeRange(["2021-01-01 00:00:00", "2021-01-07 00:00:00"])
    merged_temp_plot = gr.LinePlot(
        temp_sensor_data,
        x="time",
        y="temperature",
    )
    split_temp_plot = gr.LinePlot(
        temp_sensor_data,
        x="time",
        y="temperature",
        color="location",
    )
    with gr.Row():
        humidity_bar_plot = gr.BarPlot(
            temp_sensor_data,
            x="time",
            y="humidity",
            color="location",
            x_bin="1h",
        )
        humidity_scatter_plot = gr.ScatterPlot(
            temp_sensor_data,
            x="time",
            y="humidity",
            color="location",
        )
    
    date.bind([merged_temp_plot, split_temp_plot, humidity_bar_plot, humidity_scatter_plot])


if __name__ == "__main__":
    demo.launch()

```

## `DateTimeRange`

### Initialization

<table>
<thead>
<tr>
<th align="left">name</th>
<th align="left" style="width: 25%;">type</th>
<th align="left">default</th>
<th align="left">description</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left"><code>value</code></td>
<td align="left" style="width: 25%;">

```python
tuple[float | str | datetime, float | str | datetime] | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">default value for datetime.</td>
</tr>

<tr>
<td align="left"><code>include_time</code></td>
<td align="left" style="width: 25%;">

```python
bool
```

</td>
<td align="left"><code>True</code></td>
<td align="left">If True, the component will include time selection. If False, only date selection will be available.</td>
</tr>

<tr>
<td align="left"><code>type</code></td>
<td align="left" style="width: 25%;">

```python
Literal["timestamp", "datetime", "string"]
```

</td>
<td align="left"><code>"timestamp"</code></td>
<td align="left">The type of the value. Can be "timestamp", "datetime", or "string". If "timestamp", the value will be a number representing the start and end date in seconds since epoch. If "datetime", the value will be a datetime object. If "string", the value will be the date entered by the user.</td>
</tr>

<tr>
<td align="left"><code>timezone</code></td>
<td align="left" style="width: 25%;">

```python
str | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">The timezone to use for timestamps, such as "US/Pacific" or "Europe/Paris". If None, the timezone will be the local timezone.</td>
</tr>

<tr>
<td align="left"><code>quick_ranges</code></td>
<td align="left" style="width: 25%;">

```python
list[str] | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">List of strings representing quick ranges to display, such as ["30s", "1h", "24h", "7d"]. Set to [] to clear.</td>
</tr>

<tr>
<td align="left"><code>label</code></td>
<td align="left" style="width: 25%;">

```python
str | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">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.</td>
</tr>

<tr>
<td align="left"><code>show_label</code></td>
<td align="left" style="width: 25%;">

```python
bool | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">if True, will display label.</td>
</tr>

<tr>
<td align="left"><code>info</code></td>
<td align="left" style="width: 25%;">

```python
str | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">additional component description.</td>
</tr>

<tr>
<td align="left"><code>every</code></td>
<td align="left" style="width: 25%;">

```python
float | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">If `value` is a callable, run the function 'every' number of seconds while the client connection is open. Has no effect otherwise. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute.</td>
</tr>

<tr>
<td align="left"><code>scale</code></td>
<td align="left" style="width: 25%;">

```python
int | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. scale applies in Rows, and to top-level Components in Blocks where fill_height=True.</td>
</tr>

<tr>
<td align="left"><code>min_width</code></td>
<td align="left" style="width: 25%;">

```python
int
```

</td>
<td align="left"><code>160</code></td>
<td align="left">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.</td>
</tr>

<tr>
<td align="left"><code>visible</code></td>
<td align="left" style="width: 25%;">

```python
bool
```

</td>
<td align="left"><code>True</code></td>
<td align="left">If False, component will be hidden.</td>
</tr>

<tr>
<td align="left"><code>elem_id</code></td>
<td align="left" style="width: 25%;">

```python
str | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">None</td>
</tr>

<tr>
<td align="left"><code>elem_classes</code></td>
<td align="left" style="width: 25%;">

```python
list[str] | str | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">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.</td>
</tr>

<tr>
<td align="left"><code>render</code></td>
<td align="left" style="width: 25%;">

```python
bool
```

</td>
<td align="left"><code>True</code></td>
<td align="left">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.</td>
</tr>

<tr>
<td align="left"><code>key</code></td>
<td align="left" style="width: 25%;">

```python
int | str | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">if assigned, will be used to assume identity across a re-render. Components that have the same key across a re-render will have their value preserved.</td>
</tr>
</tbody></table>


### Events

| name | description |
|:-----|:------------|
| `change` | Triggered when the value of the DateTimeRange 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. |



### 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.

- **As output:** Is passed, passes text value as a {str} into the function.
- **As input:** Should return, expects a tuple pair of datetimes.

 ```python
 def predict(
     value: tuple[str | float | datetime, str | float | datetime] | None
 ) -> tuple[float | datetime | str, float | datetime | str] | None:
     return value
 ```
 

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "gradio-datetimerange",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "gradio-custom-component, gradio-template-DateTime",
    "author": null,
    "author_email": "YOUR NAME <YOUREMAIL@domain.com>",
    "download_url": "https://files.pythonhosted.org/packages/f0/69/16716f237c8be6e07bc4d1d57df83cf60d7ec757d1b2cc1df8ff1f04130d/gradio_datetimerange-0.0.1.tar.gz",
    "platform": null,
    "description": "---\ntags: [gradio-custom-component, DateTime]\ntitle: gradio_datetimerange\nshort_description: Component to create time ranges.\ncolorFrom: blue\ncolorTo: yellow\nsdk: gradio\npinned: false\napp_file: space.py\n---\n\n# `gradio_datetimerange`\n<img alt=\"Static Badge\" src=\"https://img.shields.io/badge/version%20-%200.0.1%20-%20orange\">  \n\nComponent to create time ranges.\n\n## Installation\n\n```bash\npip install gradio_datetimerange\n```\n\n## Usage\n\n```python\n\nimport gradio as gr\nfrom gradio_datetimerange import DateTimeRange\nimport pandas as pd\nfrom random import randint\n\ntemp_sensor_data = pd.DataFrame(\n    {\n        \"time\": pd.date_range(\"2021-01-01\", end=\"2021-01-05\", periods=200),\n        \"temperature\": [randint(50 + 10 * (i % 2), 65 + 15 * (i % 2)) for i in range(200)],\n        \"humidity\": [randint(50 + 10 * (i % 2), 65 + 15 * (i % 2)) for i in range(200)],\n        \"location\": [\"indoor\", \"outdoor\"] * 100,\n    }\n)\n\nwith gr.Blocks() as demo:\n    date = DateTimeRange([\"2021-01-01 00:00:00\", \"2021-01-07 00:00:00\"])\n    merged_temp_plot = gr.LinePlot(\n        temp_sensor_data,\n        x=\"time\",\n        y=\"temperature\",\n    )\n    split_temp_plot = gr.LinePlot(\n        temp_sensor_data,\n        x=\"time\",\n        y=\"temperature\",\n        color=\"location\",\n    )\n    with gr.Row():\n        humidity_bar_plot = gr.BarPlot(\n            temp_sensor_data,\n            x=\"time\",\n            y=\"humidity\",\n            color=\"location\",\n            x_bin=\"1h\",\n        )\n        humidity_scatter_plot = gr.ScatterPlot(\n            temp_sensor_data,\n            x=\"time\",\n            y=\"humidity\",\n            color=\"location\",\n        )\n    \n    date.bind([merged_temp_plot, split_temp_plot, humidity_bar_plot, humidity_scatter_plot])\n\n\nif __name__ == \"__main__\":\n    demo.launch()\n\n```\n\n## `DateTimeRange`\n\n### Initialization\n\n<table>\n<thead>\n<tr>\n<th align=\"left\">name</th>\n<th align=\"left\" style=\"width: 25%;\">type</th>\n<th align=\"left\">default</th>\n<th align=\"left\">description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td align=\"left\"><code>value</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\ntuple[float | str | datetime, float | str | datetime] | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">default value for datetime.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>include_time</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nbool\n```\n\n</td>\n<td align=\"left\"><code>True</code></td>\n<td align=\"left\">If True, the component will include time selection. If False, only date selection will be available.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>type</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nLiteral[\"timestamp\", \"datetime\", \"string\"]\n```\n\n</td>\n<td align=\"left\"><code>\"timestamp\"</code></td>\n<td align=\"left\">The type of the value. Can be \"timestamp\", \"datetime\", or \"string\". If \"timestamp\", the value will be a number representing the start and end date in seconds since epoch. If \"datetime\", the value will be a datetime object. If \"string\", the value will be the date entered by the user.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>timezone</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nstr | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">The timezone to use for timestamps, such as \"US/Pacific\" or \"Europe/Paris\". If None, the timezone will be the local timezone.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>quick_ranges</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nlist[str] | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">List of strings representing quick ranges to display, such as [\"30s\", \"1h\", \"24h\", \"7d\"]. Set to [] to clear.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>label</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nstr | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">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.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>show_label</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nbool | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">if True, will display label.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>info</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nstr | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">additional component description.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>every</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nfloat | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">If `value` is a callable, run the function 'every' number of seconds while the client connection is open. Has no effect otherwise. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>scale</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nint | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. scale applies in Rows, and to top-level Components in Blocks where fill_height=True.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>min_width</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nint\n```\n\n</td>\n<td align=\"left\"><code>160</code></td>\n<td align=\"left\">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.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>visible</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nbool\n```\n\n</td>\n<td align=\"left\"><code>True</code></td>\n<td align=\"left\">If False, component will be hidden.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>elem_id</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nstr | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>elem_classes</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nlist[str] | str | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">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.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>render</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nbool\n```\n\n</td>\n<td align=\"left\"><code>True</code></td>\n<td align=\"left\">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.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>key</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nint | str | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">if assigned, will be used to assume identity across a re-render. Components that have the same key across a re-render will have their value preserved.</td>\n</tr>\n</tbody></table>\n\n\n### Events\n\n| name | description |\n|:-----|:------------|\n| `change` | Triggered when the value of the DateTimeRange 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. |\n\n\n\n### User function\n\nThe impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).\n\n- When used as an Input, the component only impacts the input signature of the user function.\n- When used as an output, the component only impacts the return signature of the user function.\n\nThe code snippet below is accurate in cases where the component is used as both an input and an output.\n\n- **As output:** Is passed, passes text value as a {str} into the function.\n- **As input:** Should return, expects a tuple pair of datetimes.\n\n ```python\n def predict(\n     value: tuple[str | float | datetime, str | float | datetime] | None\n ) -> tuple[float | datetime | str, float | datetime | str] | None:\n     return value\n ```\n \n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Component to create time ranges.",
    "version": "0.0.1",
    "project_urls": null,
    "split_keywords": [
        "gradio-custom-component",
        " gradio-template-datetime"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b6478a8828a430803763c4ac51a13f5ae949054e964ad494eeab138bc8f9fbbf",
                "md5": "a89f47f62f6350c8b74ad238dc48badc",
                "sha256": "85c40d123afcba31971e3c4eee7d6a8d36b062c410fd6342a7e88f0852e11f5b"
            },
            "downloads": -1,
            "filename": "gradio_datetimerange-0.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a89f47f62f6350c8b74ad238dc48badc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 23958,
            "upload_time": "2024-07-23T18:38:42",
            "upload_time_iso_8601": "2024-07-23T18:38:42.848592Z",
            "url": "https://files.pythonhosted.org/packages/b6/47/8a8828a430803763c4ac51a13f5ae949054e964ad494eeab138bc8f9fbbf/gradio_datetimerange-0.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f06916716f237c8be6e07bc4d1d57df83cf60d7ec757d1b2cc1df8ff1f04130d",
                "md5": "bf9c0140cba1209c946b6f115eded75a",
                "sha256": "5789b642c054815c4fe5ec06c865d7b481422bb98267c1ce11fc936e984f050f"
            },
            "downloads": -1,
            "filename": "gradio_datetimerange-0.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "bf9c0140cba1209c946b6f115eded75a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 62911,
            "upload_time": "2024-07-23T18:38:44",
            "upload_time_iso_8601": "2024-07-23T18:38:44.137677Z",
            "url": "https://files.pythonhosted.org/packages/f0/69/16716f237c8be6e07bc4d1d57df83cf60d7ec757d1b2cc1df8ff1f04130d/gradio_datetimerange-0.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-23 18:38:44",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "gradio-datetimerange"
}
        
Elapsed time: 4.85391s