Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ __tmp/*
*.pyi
node_modules
flagged
gradio_cached_examples
gradio_cached_examples
.idea
.venv
69 changes: 54 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@

# `gradio_calendar`
<a href="https://pypi.org/project/gradio_calendar/" target="_blank"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/gradio_calendar"></a> <a href="https://github.com/freddyaboulton/gradio-calendar/issues" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/Issues-white?logo=github&logoColor=black"></a> <a href="https://huggingface.co/spaces/freddyaboulton/gradio_calendar/discussions" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/%F0%9F%A4%97%20Discuss-%23097EFF?style=flat&logoColor=black"></a>
# `gradio_flatpickr_calendar`
<a href="https://pypi.org/project/gradio_flatpickr_calendar/" target="_blank"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/gradio_flatpickr_calendar"></a> <a href="https://github.com/Florian-BACHO/gradio-flatpickr-calendar/issues" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/Issues-white?logo=github&logoColor=black"></a>

Gradio component for selecting dates with a calendar 📆
Gradio component for selecting dates or ranges of dates with a Flatpickr calendar 📆

## Installation

```bash
pip install gradio_calendar
pip install gradio_flatpickr_calendar
```

## Usage

```python
import gradio as gr
from gradio_calendar import Calendar
from gradio_flatpickr_calendar import Calendar
import datetime

def is_weekday(date: datetime.datetime):
return date.weekday() < 5

demo = gr.Interface(is_weekday,
[Calendar(type="datetime", label="Select a date", info="Click the calendar icon to bring up the calendar.")],
gr.Label(label="Is it a weekday?"),
examples=["2023-01-01", "2023-12-11"],
cache_examples=True,
title="Is it a weekday?")
def predict(date: datetime.datetime | tuple[datetime.datetime, datetime.datetime]) \
-> datetime.datetime | tuple[datetime.datetime, datetime.datetime]:
return date


demo = gr.Interface(fn=predict,
inputs=[Calendar(label="Select a date or a range of dates",
info="Click to bring up the calendar.",
mode="range", type="datetime")],
outputs=Calendar(label="Selected date(s)", info="Here are the date(s) you selected:"),
examples=["2023-01-01", ("2023-01-01", "2023-12-11")],
cache_examples=True,
title="Choose a date")

if __name__ == "__main__":
demo.launch()
Expand Down Expand Up @@ -72,6 +77,19 @@ str | datetime.datetime
<td align="left">None</td>
</tr>

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

```python
"date" | "range"
```

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

<tr>
<td align="left"><code>label</code></td>
<td align="left" style="width: 25%;">
Expand Down Expand Up @@ -243,6 +261,19 @@ float | None
<td align="left"><code>None</code></td>
<td align="left">None</td>
</tr>

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

```python
str
```

</td>
<td align="left"><code>"%Y-%m-%d"</code></td>
<td align="left">None</td>
</tr>
</tbody></table>


Expand Down Expand Up @@ -270,8 +301,16 @@ The code snippet below is accurate in cases where the component is used as both

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

Loading