freddyaboulton HF staff commited on
Commit
4360c2e
β€’
1 Parent(s): c403458

Upload folder using huggingface_hub

Browse files
README.md CHANGED
@@ -2,8 +2,8 @@
2
  ---
3
  tags: [gradio-custom-component,gradio-template-Fallback,time,calendar,forms]
4
  title: gradio_calendar V0.0.2
5
- colorFrom: yellow
6
- colorTo: gray
7
  sdk: docker
8
  pinned: false
9
  license: apache-2.0
 
2
  ---
3
  tags: [gradio-custom-component,gradio-template-Fallback,time,calendar,forms]
4
  title: gradio_calendar V0.0.2
5
+ colorFrom: green
6
+ colorTo: red
7
  sdk: docker
8
  pinned: false
9
  license: apache-2.0
__pycache__/_app.cpython-39.pyc ADDED
Binary file (684 Bytes). View file
 
_app.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from gradio_calendar import Calendar
3
+ import datetime
4
+
5
+ def is_weekday(date: datetime.datetime):
6
+ return date.weekday() < 5
7
+
8
+ demo = gr.Interface(is_weekday,
9
+ [Calendar(type="datetime", label="Select a date", info="Click the calendar icon to bring up the calendar.")],
10
+ gr.Label(label="Is it a weekday?"),
11
+ examples=["2023-01-01", "2023-12-11"],
12
+ cache_examples=True,
13
+ title="Is it a weekday?")
14
+
15
+ if __name__ == "__main__":
16
+ demo.launch()
app.py CHANGED
@@ -1,3 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  from gradio_calendar import Calendar
3
  import datetime
@@ -12,5 +52,86 @@ demo = gr.Interface(is_weekday,
12
  cache_examples=True,
13
  title="Is it a weekday?")
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  demo.launch()
 
1
+
2
+ import gradio as gr
3
+ from _app import demo as app
4
+ import os
5
+
6
+ _docs = {'Calendar': {'description': 'A calendar component that allows users to select a date.\n\ndepending on the value of the type parameter.\n\n\n value: The default date value, formatted as YYYY-MM-DD. Can be either a string or datetime.datetime object.\n type: The type of the value to pass to the python function. Either "string" or "datetime".\n label: The label for the component.\n info: Extra text to render below the component.\n show_label: Whether to show the label for the component.\n container: Whether to show the component in a container.\n scale: The relative size of the component compared to other components in the same row.\n min_width: The minimum width of the component.\n interactive: Whether to allow the user to interact with the component.\n visible: Whether to show the component.\n elem_id: The id of the component. Useful for custom js or css.\n elem_classes: The classes of the component. Useful for custom js or css.\n render: Whether to render the component in the parent Blocks scope.\n load_fn: A function to run when the component is first loaded onto the page to set the intial value.\n every: Whether load_fn should be run on a fixed time interval.', 'members': {'__init__': {'value': {'type': 'str | datetime.datetime', 'default': 'None', 'description': None}, 'type': {'type': 'Literal["string", "datetime"]', 'default': '"datetime"', 'description': None}, 'label': {'type': 'str | None', 'default': 'None', 'description': None}, 'info': {'type': 'str | None', 'default': 'None', 'description': None}, 'show_label': {'type': 'bool | None', 'default': 'None', 'description': None}, 'container': {'type': 'bool', 'default': 'True', 'description': None}, 'scale': {'type': 'int | None', 'default': 'None', 'description': None}, 'min_width': {'type': 'int | None', 'default': 'None', 'description': None}, 'interactive': {'type': 'bool | None', 'default': 'None', 'description': None}, 'visible': {'type': 'bool', 'default': 'True', 'description': None}, 'elem_id': {'type': 'str | None', 'default': 'None', 'description': None}, 'elem_classes': {'type': 'list[str] | str | None', 'default': 'None', 'description': None}, 'render': {'type': 'bool', 'default': 'True', 'description': None}, 'load_fn': {'type': 'Callable[..., Any] | None', 'default': 'None', 'description': None}, 'every': {'type': 'float | None', 'default': 'None', 'description': None}}, 'postprocess': {'value': {'type': 'str | datetime.datetime | None', 'description': None}}, 'preprocess': {'return': {'type': 'str | datetime.datetime | None', 'description': None}, 'value': None}}, 'events': {'change': {'type': None, 'default': None, 'description': ''}, 'input': {'type': None, 'default': None, 'description': ''}, 'submit': {'type': None, 'default': None, 'description': ''}}}, '__meta__': {'additional_interfaces': {}, 'user_fn_refs': {'Calendar': []}}}
7
+
8
+ abs_path = os.path.join(os.path.dirname(__file__), "css.css")
9
+
10
+ with gr.Blocks(
11
+ css=abs_path,
12
+ theme=gr.themes.Default(
13
+ font_mono=[
14
+ gr.themes.GoogleFont("Inconsolata"),
15
+ "monospace",
16
+ ],
17
+ ),
18
+ ) as demo:
19
+ gr.Markdown(
20
+ """
21
+ # `gradio_calendar`
22
+
23
+ <div style="display: flex; gap: 7px;">
24
+ <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/settings/discussions" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/%F0%9F%A4%97%20Discuss-%23097EFF?style=flat&logoColor=black"></a>
25
+ </div>
26
+
27
+ Gradio component for selecting dates with a calendar πŸ“†
28
+ """, elem_classes=["md-custom"], header_links=True)
29
+ app.render()
30
+ gr.Markdown(
31
+ """
32
+ ## Installation
33
+
34
+ ```bash
35
+ pip install gradio_calendar
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ ```python
41
  import gradio as gr
42
  from gradio_calendar import Calendar
43
  import datetime
 
52
  cache_examples=True,
53
  title="Is it a weekday?")
54
 
55
+ if __name__ == "__main__":
56
+ demo.launch()
57
+
58
+ ```
59
+ """, elem_classes=["md-custom"], header_links=True)
60
+
61
+
62
+ gr.Markdown("""
63
+ ## `Calendar`
64
+
65
+ ### Initialization
66
+ """, elem_classes=["md-custom"], header_links=True)
67
+
68
+ gr.ParamViewer(value=_docs["Calendar"]["members"]["__init__"], linkify=[])
69
+
70
+
71
+ gr.Markdown("### Events")
72
+ gr.ParamViewer(value=_docs["Calendar"]["events"], linkify=['Event'])
73
+
74
+
75
+
76
+
77
+ gr.Markdown("""
78
+
79
+ ### User function
80
+
81
+ 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).
82
+
83
+ - When used as an Input, the component only impacts the input signature of the user function.
84
+ - When used as an output, the component only impacts the return signature of the user function.
85
+
86
+ The code snippet below is accurate in cases where the component is used as both an input and an output.
87
+
88
+
89
+
90
+ ```python
91
+ def predict(
92
+ value: str | datetime.datetime | None
93
+ ) -> str | datetime.datetime | None:
94
+ return value
95
+ ```
96
+ """, elem_classes=["md-custom", "Calendar-user-fn"], header_links=True)
97
+
98
+
99
+
100
+
101
+ demo.load(None, js=r"""function() {
102
+ const refs = {};
103
+ const user_fn_refs = {
104
+ Calendar: [], };
105
+ requestAnimationFrame(() => {
106
+
107
+ Object.entries(user_fn_refs).forEach(([key, refs]) => {
108
+ if (refs.length > 0) {
109
+ const el = document.querySelector(`.${key}-user-fn`);
110
+ if (!el) return;
111
+ refs.forEach(ref => {
112
+ el.innerHTML = el.innerHTML.replace(
113
+ new RegExp("\\b"+ref+"\\b", "g"),
114
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
115
+ );
116
+ })
117
+ }
118
+ })
119
+
120
+ Object.entries(refs).forEach(([key, refs]) => {
121
+ if (refs.length > 0) {
122
+ const el = document.querySelector(`.${key}`);
123
+ if (!el) return;
124
+ refs.forEach(ref => {
125
+ el.innerHTML = el.innerHTML.replace(
126
+ new RegExp("\\b"+ref+"\\b", "g"),
127
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
128
+ );
129
+ })
130
+ }
131
+ })
132
+ })
133
+ }
134
+
135
+ """)
136
 
137
  demo.launch()
css.css ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ html {
2
+ font-family: Inter;
3
+ font-size: 16px;
4
+ font-weight: 400;
5
+ line-height: 1.5;
6
+ -webkit-text-size-adjust: 100%;
7
+ background: #fff;
8
+ color: #323232;
9
+ -webkit-font-smoothing: antialiased;
10
+ -moz-osx-font-smoothing: grayscale;
11
+ text-rendering: optimizeLegibility;
12
+ }
13
+
14
+ :root {
15
+ --space: 1;
16
+ --vspace: calc(var(--space) * 1rem);
17
+ --vspace-0: calc(3 * var(--space) * 1rem);
18
+ --vspace-1: calc(2 * var(--space) * 1rem);
19
+ --vspace-2: calc(1.5 * var(--space) * 1rem);
20
+ --vspace-3: calc(0.5 * var(--space) * 1rem);
21
+ }
22
+
23
+ .app {
24
+ max-width: 748px !important;
25
+ }
26
+
27
+ .prose p {
28
+ margin: var(--vspace) 0;
29
+ line-height: var(--vspace * 2);
30
+ font-size: 1rem;
31
+ }
32
+
33
+ code {
34
+ font-family: "Inconsolata", sans-serif;
35
+ font-size: 16px;
36
+ }
37
+
38
+ h1,
39
+ h1 code {
40
+ font-weight: 400;
41
+ line-height: calc(2.5 / var(--space) * var(--vspace));
42
+ }
43
+
44
+ h1 code {
45
+ background: none;
46
+ border: none;
47
+ letter-spacing: 0.05em;
48
+ padding-bottom: 5px;
49
+ position: relative;
50
+ padding: 0;
51
+ }
52
+
53
+ h2 {
54
+ margin: var(--vspace-1) 0 var(--vspace-2) 0;
55
+ line-height: 1em;
56
+ }
57
+
58
+ h3,
59
+ h3 code {
60
+ margin: var(--vspace-1) 0 var(--vspace-2) 0;
61
+ line-height: 1em;
62
+ }
63
+
64
+ h4,
65
+ h5,
66
+ h6 {
67
+ margin: var(--vspace-3) 0 var(--vspace-3) 0;
68
+ line-height: var(--vspace);
69
+ }
70
+
71
+ .bigtitle,
72
+ h1,
73
+ h1 code {
74
+ font-size: calc(8px * 4.5);
75
+ word-break: break-word;
76
+ }
77
+
78
+ .title,
79
+ h2,
80
+ h2 code {
81
+ font-size: calc(8px * 3.375);
82
+ font-weight: lighter;
83
+ word-break: break-word;
84
+ border: none;
85
+ background: none;
86
+ }
87
+
88
+ .subheading1,
89
+ h3,
90
+ h3 code {
91
+ font-size: calc(8px * 1.8);
92
+ font-weight: 600;
93
+ border: none;
94
+ background: none;
95
+ letter-spacing: 0.1em;
96
+ text-transform: uppercase;
97
+ }
98
+
99
+ h2 code {
100
+ padding: 0;
101
+ position: relative;
102
+ letter-spacing: 0.05em;
103
+ }
104
+
105
+ blockquote {
106
+ font-size: calc(8px * 1.1667);
107
+ font-style: italic;
108
+ line-height: calc(1.1667 * var(--vspace));
109
+ margin: var(--vspace-2) var(--vspace-2);
110
+ }
111
+
112
+ .subheading2,
113
+ h4 {
114
+ font-size: calc(8px * 1.4292);
115
+ text-transform: uppercase;
116
+ font-weight: 600;
117
+ }
118
+
119
+ .subheading3,
120
+ h5 {
121
+ font-size: calc(8px * 1.2917);
122
+ line-height: calc(1.2917 * var(--vspace));
123
+
124
+ font-weight: lighter;
125
+ text-transform: uppercase;
126
+ letter-spacing: 0.15em;
127
+ }
128
+
129
+ h6 {
130
+ font-size: calc(8px * 1.1667);
131
+ font-size: 1.1667em;
132
+ font-weight: normal;
133
+ font-style: italic;
134
+ font-family: "le-monde-livre-classic-byol", serif !important;
135
+ letter-spacing: 0px !important;
136
+ }
137
+
138
+ #start .md > *:first-child {
139
+ margin-top: 0;
140
+ }
141
+
142
+ h2 + h3 {
143
+ margin-top: 0;
144
+ }
145
+
146
+ .md hr {
147
+ border: none;
148
+ border-top: 1px solid var(--block-border-color);
149
+ margin: var(--vspace-2) 0 var(--vspace-2) 0;
150
+ }
151
+ .prose ul {
152
+ margin: var(--vspace-2) 0 var(--vspace-1) 0;
153
+ }
154
+
155
+ .gap {
156
+ gap: 0;
157
+ }
space.py ADDED
@@ -0,0 +1,258 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ from app import demo as app
4
+ import os
5
+
6
+ _docs = {'Calendar': {'description': 'A calendar component that allows users to select a date.\n\ndepending on the value of the type parameter.\n\n\n value: The default date value, formatted as YYYY-MM-DD. Can be either a string or datetime.datetime object.\n type: The type of the value to pass to the python function. Either "string" or "datetime".\n label: The label for the component.\n info: Extra text to render below the component.\n show_label: Whether to show the label for the component.\n container: Whether to show the component in a container.\n scale: The relative size of the component compared to other components in the same row.\n min_width: The minimum width of the component.\n interactive: Whether to allow the user to interact with the component.\n visible: Whether to show the component.\n elem_id: The id of the component. Useful for custom js or css.\n elem_classes: The classes of the component. Useful for custom js or css.\n render: Whether to render the component in the parent Blocks scope.\n load_fn: A function to run when the component is first loaded onto the page to set the intial value.\n every: Whether load_fn should be run on a fixed time interval.', 'members': {'__init__': {'value': {'type': 'str | datetime.datetime', 'default': 'None', 'description': None}, 'type': {'type': 'Literal["string", "datetime"]', 'default': '"datetime"', 'description': None}, 'label': {'type': 'str | None', 'default': 'None', 'description': None}, 'info': {'type': 'str | None', 'default': 'None', 'description': None}, 'show_label': {'type': 'bool | None', 'default': 'None', 'description': None}, 'container': {'type': 'bool', 'default': 'True', 'description': None}, 'scale': {'type': 'int | None', 'default': 'None', 'description': None}, 'min_width': {'type': 'int | None', 'default': 'None', 'description': None}, 'interactive': {'type': 'bool | None', 'default': 'None', 'description': None}, 'visible': {'type': 'bool', 'default': 'True', 'description': None}, 'elem_id': {'type': 'str | None', 'default': 'None', 'description': None}, 'elem_classes': {'type': 'list[str] | str | None', 'default': 'None', 'description': None}, 'render': {'type': 'bool', 'default': 'True', 'description': None}, 'load_fn': {'type': 'Callable[..., Any] | None', 'default': 'None', 'description': None}, 'every': {'type': 'float | None', 'default': 'None', 'description': None}}, 'postprocess': {'value': {'type': 'str | datetime.datetime | None', 'description': None}}, 'preprocess': {'return': {'type': 'str | datetime.datetime | None', 'description': None}, 'value': None}}, 'events': {'change': {'type': None, 'default': None, 'description': ''}, 'input': {'type': None, 'default': None, 'description': ''}, 'submit': {'type': None, 'default': None, 'description': ''}}}, '__meta__': {'additional_interfaces': {}, 'user_fn_refs': {'Calendar': []}}}
7
+
8
+ abs_path = os.path.join(os.path.dirname(__file__), "css.css")
9
+
10
+ with gr.Blocks(
11
+ css=abs_path,
12
+ theme=gr.themes.Default(
13
+ font_mono=[
14
+ gr.themes.GoogleFont("Inconsolata"),
15
+ "monospace",
16
+ ],
17
+ ),
18
+ ) as demo:
19
+ gr.Markdown(
20
+ """
21
+ # `gradio_calendar`
22
+
23
+ <div style="display: flex; gap: 7px;">
24
+ <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/settings/discussions" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/%F0%9F%A4%97%20Discuss-%23097EFF?style=flat&logoColor=black"></a>
25
+ </div>
26
+
27
+ Gradio component for selecting dates with a calendar πŸ“†
28
+ """, elem_classes=["md-custom"], header_links=True)
29
+ app.render()
30
+ gr.Markdown(
31
+ """
32
+ ## Installation
33
+
34
+ ```bash
35
+ pip install gradio_calendar
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ ```python
41
+
42
+ import gradio as gr
43
+ from _app import demo as app
44
+ import os
45
+
46
+ _docs = {'Calendar': {'description': 'A calendar component that allows users to select a date.\n\ndepending on the value of the type parameter.\n\n\n value: The default date value, formatted as YYYY-MM-DD. Can be either a string or datetime.datetime object.\n type: The type of the value to pass to the python function. Either "string" or "datetime".\n label: The label for the component.\n info: Extra text to render below the component.\n show_label: Whether to show the label for the component.\n container: Whether to show the component in a container.\n scale: The relative size of the component compared to other components in the same row.\n min_width: The minimum width of the component.\n interactive: Whether to allow the user to interact with the component.\n visible: Whether to show the component.\n elem_id: The id of the component. Useful for custom js or css.\n elem_classes: The classes of the component. Useful for custom js or css.\n render: Whether to render the component in the parent Blocks scope.\n load_fn: A function to run when the component is first loaded onto the page to set the intial value.\n every: Whether load_fn should be run on a fixed time interval.', 'members': {'__init__': {'value': {'type': 'str | datetime.datetime', 'default': 'None', 'description': None}, 'type': {'type': 'Literal["string", "datetime"]', 'default': '"datetime"', 'description': None}, 'label': {'type': 'str | None', 'default': 'None', 'description': None}, 'info': {'type': 'str | None', 'default': 'None', 'description': None}, 'show_label': {'type': 'bool | None', 'default': 'None', 'description': None}, 'container': {'type': 'bool', 'default': 'True', 'description': None}, 'scale': {'type': 'int | None', 'default': 'None', 'description': None}, 'min_width': {'type': 'int | None', 'default': 'None', 'description': None}, 'interactive': {'type': 'bool | None', 'default': 'None', 'description': None}, 'visible': {'type': 'bool', 'default': 'True', 'description': None}, 'elem_id': {'type': 'str | None', 'default': 'None', 'description': None}, 'elem_classes': {'type': 'list[str] | str | None', 'default': 'None', 'description': None}, 'render': {'type': 'bool', 'default': 'True', 'description': None}, 'load_fn': {'type': 'Callable[..., Any] | None', 'default': 'None', 'description': None}, 'every': {'type': 'float | None', 'default': 'None', 'description': None}}, 'postprocess': {'value': {'type': 'str | datetime.datetime | None', 'description': None}}, 'preprocess': {'return': {'type': 'str | datetime.datetime | None', 'description': None}, 'value': None}}, 'events': {'change': {'type': None, 'default': None, 'description': ''}, 'input': {'type': None, 'default': None, 'description': ''}, 'submit': {'type': None, 'default': None, 'description': ''}}}, '__meta__': {'additional_interfaces': {}, 'user_fn_refs': {'Calendar': []}}}
47
+
48
+ abs_path = os.path.join(os.path.dirname(__file__), "css.css")
49
+
50
+ with gr.Blocks(
51
+ css=abs_path,
52
+ theme=gr.themes.Default(
53
+ font_mono=[
54
+ gr.themes.GoogleFont("Inconsolata"),
55
+ "monospace",
56
+ ],
57
+ ),
58
+ ) as demo:
59
+ gr.Markdown(
60
+ """
61
+ # `gradio_calendar`
62
+
63
+ <div style="display: flex; gap: 7px;">
64
+ <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/settings/discussions" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/%F0%9F%A4%97%20Discuss-%23097EFF?style=flat&logoColor=black"></a>
65
+ </div>
66
+
67
+ Gradio component for selecting dates with a calendar πŸ“†
68
+ """, elem_classes=["md-custom"], header_links=True)
69
+ app.render()
70
+ gr.Markdown(
71
+ """
72
+ ## Installation
73
+
74
+ ```bash
75
+ pip install gradio_calendar
76
+ ```
77
+
78
+ ## Usage
79
+
80
+ ```python
81
+ import gradio as gr
82
+ from gradio_calendar import Calendar
83
+ import datetime
84
+
85
+ def is_weekday(date: datetime.datetime):
86
+ return date.weekday() < 5
87
+
88
+ demo = gr.Interface(is_weekday,
89
+ [Calendar(type="datetime", label="Select a date", info="Click the calendar icon to bring up the calendar.")],
90
+ gr.Label(label="Is it a weekday?"),
91
+ examples=["2023-01-01", "2023-12-11"],
92
+ cache_examples=True,
93
+ title="Is it a weekday?")
94
+
95
+ if __name__ == "__main__":
96
+ demo.launch()
97
+
98
+ ```
99
+ """, elem_classes=["md-custom"], header_links=True)
100
+
101
+
102
+ gr.Markdown("""
103
+ ## `Calendar`
104
+
105
+ ### Initialization
106
+ """, elem_classes=["md-custom"], header_links=True)
107
+
108
+ gr.ParamViewer(value=_docs["Calendar"]["members"]["__init__"], linkify=[])
109
+
110
+
111
+ gr.Markdown("### Events")
112
+ gr.ParamViewer(value=_docs["Calendar"]["events"], linkify=['Event'])
113
+
114
+
115
+
116
+
117
+ gr.Markdown("""
118
+
119
+ ### User function
120
+
121
+ 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).
122
+
123
+ - When used as an Input, the component only impacts the input signature of the user function.
124
+ - When used as an output, the component only impacts the return signature of the user function.
125
+
126
+ The code snippet below is accurate in cases where the component is used as both an input and an output.
127
+
128
+
129
+
130
+ ```python
131
+ def predict(
132
+ value: str | datetime.datetime | None
133
+ ) -> str | datetime.datetime | None:
134
+ return value
135
+ ```
136
+ """, elem_classes=["md-custom", "Calendar-user-fn"], header_links=True)
137
+
138
+
139
+
140
+
141
+ demo.load(None, js=r"""function() {
142
+ const refs = {};
143
+ const user_fn_refs = {
144
+ Calendar: [], };
145
+ requestAnimationFrame(() => {
146
+
147
+ Object.entries(user_fn_refs).forEach(([key, refs]) => {
148
+ if (refs.length > 0) {
149
+ const el = document.querySelector(`.${key}-user-fn`);
150
+ if (!el) return;
151
+ refs.forEach(ref => {
152
+ el.innerHTML = el.innerHTML.replace(
153
+ new RegExp("\\b"+ref+"\\b", "g"),
154
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
155
+ );
156
+ })
157
+ }
158
+ })
159
+
160
+ Object.entries(refs).forEach(([key, refs]) => {
161
+ if (refs.length > 0) {
162
+ const el = document.querySelector(`.${key}`);
163
+ if (!el) return;
164
+ refs.forEach(ref => {
165
+ el.innerHTML = el.innerHTML.replace(
166
+ new RegExp("\\b"+ref+"\\b", "g"),
167
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
168
+ );
169
+ })
170
+ }
171
+ })
172
+ })
173
+ }
174
+
175
+ """)
176
+
177
+ demo.launch()
178
+
179
+ ```
180
+ """, elem_classes=["md-custom"], header_links=True)
181
+
182
+
183
+ gr.Markdown("""
184
+ ## `Calendar`
185
+
186
+ ### Initialization
187
+ """, elem_classes=["md-custom"], header_links=True)
188
+
189
+ gr.ParamViewer(value=_docs["Calendar"]["members"]["__init__"], linkify=[])
190
+
191
+
192
+ gr.Markdown("### Events")
193
+ gr.ParamViewer(value=_docs["Calendar"]["events"], linkify=['Event'])
194
+
195
+
196
+
197
+
198
+ gr.Markdown("""
199
+
200
+ ### User function
201
+
202
+ 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).
203
+
204
+ - When used as an Input, the component only impacts the input signature of the user function.
205
+ - When used as an output, the component only impacts the return signature of the user function.
206
+
207
+ The code snippet below is accurate in cases where the component is used as both an input and an output.
208
+
209
+
210
+
211
+ ```python
212
+ def predict(
213
+ value: str | datetime.datetime | None
214
+ ) -> str | datetime.datetime | None:
215
+ return value
216
+ ```
217
+ """, elem_classes=["md-custom", "Calendar-user-fn"], header_links=True)
218
+
219
+
220
+
221
+
222
+ demo.load(None, js=r"""function() {
223
+ const refs = {};
224
+ const user_fn_refs = {
225
+ Calendar: [], };
226
+ requestAnimationFrame(() => {
227
+
228
+ Object.entries(user_fn_refs).forEach(([key, refs]) => {
229
+ if (refs.length > 0) {
230
+ const el = document.querySelector(`.${key}-user-fn`);
231
+ if (!el) return;
232
+ refs.forEach(ref => {
233
+ el.innerHTML = el.innerHTML.replace(
234
+ new RegExp("\\b"+ref+"\\b", "g"),
235
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
236
+ );
237
+ })
238
+ }
239
+ })
240
+
241
+ Object.entries(refs).forEach(([key, refs]) => {
242
+ if (refs.length > 0) {
243
+ const el = document.querySelector(`.${key}`);
244
+ if (!el) return;
245
+ refs.forEach(ref => {
246
+ el.innerHTML = el.innerHTML.replace(
247
+ new RegExp("\\b"+ref+"\\b", "g"),
248
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
249
+ );
250
+ })
251
+ }
252
+ })
253
+ })
254
+ }
255
+
256
+ """)
257
+
258
+ demo.launch()
src/.gitignore CHANGED
@@ -6,4 +6,6 @@ __pycache__/
6
  *$py.class
7
  __tmp/*
8
  *.pyi
9
- node_modules
 
 
 
6
  *$py.class
7
  __tmp/*
8
  *.pyi
9
+ node_modules
10
+ flagged
11
+ gradio_cached_examples
src/LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Freddy Boulton
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
src/README.md CHANGED
@@ -1,14 +1,56 @@
1
 
2
- # gradio_calendar πŸ“…
3
- A calendar component that lets users pick dates!
4
 
5
- `Preprocessing`: The date passed to the python function will be a string formatted as YYYY-MM-DD or a datetime.datetime object
6
- depending on the value of the type parameter.
7
 
8
- `Postprocessing`: The value returned from the function can be a string or a datetime.datetime object.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
- ## Example usage
 
 
11
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  ```python
14
  import gradio as gr
@@ -19,13 +61,334 @@ def is_weekday(date: datetime.datetime):
19
  return date.weekday() < 5
20
 
21
  demo = gr.Interface(is_weekday,
22
- [Calendar(type="datetime", label="Select a date")],
23
- gr.Label(label="Is it a weekend?"))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  demo.launch()
27
 
28
  ```
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
- ![](https://github.com/freddyaboulton/gradio-datepicker/assets/41651716/be2ffff3-4db5-4f12-9f6d-237acb1d1f96)
 
 
 
 
 
 
 
1
 
2
+ # `gradio_calendar`
3
+ <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/settings/discussions" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/%F0%9F%A4%97%20Discuss-%23097EFF?style=flat&logoColor=black"></a>
4
 
5
+ Gradio component for selecting dates with a calendar πŸ“†
 
6
 
7
+ ## Installation
8
+
9
+ ```bash
10
+ pip install gradio_calendar
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```python
16
+
17
+ import gradio as gr
18
+ from _app import demo as app
19
+ import os
20
+
21
+ _docs = {'Calendar': {'description': 'A calendar component that allows users to select a date.\n\ndepending on the value of the type parameter.\n\n\n value: The default date value, formatted as YYYY-MM-DD. Can be either a string or datetime.datetime object.\n type: The type of the value to pass to the python function. Either "string" or "datetime".\n label: The label for the component.\n info: Extra text to render below the component.\n show_label: Whether to show the label for the component.\n container: Whether to show the component in a container.\n scale: The relative size of the component compared to other components in the same row.\n min_width: The minimum width of the component.\n interactive: Whether to allow the user to interact with the component.\n visible: Whether to show the component.\n elem_id: The id of the component. Useful for custom js or css.\n elem_classes: The classes of the component. Useful for custom js or css.\n render: Whether to render the component in the parent Blocks scope.\n load_fn: A function to run when the component is first loaded onto the page to set the intial value.\n every: Whether load_fn should be run on a fixed time interval.', 'members': {'__init__': {'value': {'type': 'str | datetime.datetime', 'default': 'None', 'description': None}, 'type': {'type': 'Literal["string", "datetime"]', 'default': '"datetime"', 'description': None}, 'label': {'type': 'str | None', 'default': 'None', 'description': None}, 'info': {'type': 'str | None', 'default': 'None', 'description': None}, 'show_label': {'type': 'bool | None', 'default': 'None', 'description': None}, 'container': {'type': 'bool', 'default': 'True', 'description': None}, 'scale': {'type': 'int | None', 'default': 'None', 'description': None}, 'min_width': {'type': 'int | None', 'default': 'None', 'description': None}, 'interactive': {'type': 'bool | None', 'default': 'None', 'description': None}, 'visible': {'type': 'bool', 'default': 'True', 'description': None}, 'elem_id': {'type': 'str | None', 'default': 'None', 'description': None}, 'elem_classes': {'type': 'list[str] | str | None', 'default': 'None', 'description': None}, 'render': {'type': 'bool', 'default': 'True', 'description': None}, 'load_fn': {'type': 'Callable[..., Any] | None', 'default': 'None', 'description': None}, 'every': {'type': 'float | None', 'default': 'None', 'description': None}}, 'postprocess': {'value': {'type': 'str | datetime.datetime | None', 'description': None}}, 'preprocess': {'return': {'type': 'str | datetime.datetime | None', 'description': None}, 'value': None}}, 'events': {'change': {'type': None, 'default': None, 'description': ''}, 'input': {'type': None, 'default': None, 'description': ''}, 'submit': {'type': None, 'default': None, 'description': ''}}}, '__meta__': {'additional_interfaces': {}, 'user_fn_refs': {'Calendar': []}}}
22
+
23
+ abs_path = os.path.join(os.path.dirname(__file__), "css.css")
24
+
25
+ with gr.Blocks(
26
+ css=abs_path,
27
+ theme=gr.themes.Default(
28
+ font_mono=[
29
+ gr.themes.GoogleFont("Inconsolata"),
30
+ "monospace",
31
+ ],
32
+ ),
33
+ ) as demo:
34
+ gr.Markdown(
35
+ """
36
+ # `gradio_calendar`
37
 
38
+ <div style="display: flex; gap: 7px;">
39
+ <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/settings/discussions" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/%F0%9F%A4%97%20Discuss-%23097EFF?style=flat&logoColor=black"></a>
40
+ </div>
41
 
42
+ Gradio component for selecting dates with a calendar πŸ“†
43
+ """, elem_classes=["md-custom"], header_links=True)
44
+ app.render()
45
+ gr.Markdown(
46
+ """
47
+ ## Installation
48
+
49
+ ```bash
50
+ pip install gradio_calendar
51
+ ```
52
+
53
+ ## Usage
54
 
55
  ```python
56
  import gradio as gr
 
61
  return date.weekday() < 5
62
 
63
  demo = gr.Interface(is_weekday,
64
+ [Calendar(type="datetime", label="Select a date", info="Click the calendar icon to bring up the calendar.")],
65
+ gr.Label(label="Is it a weekday?"),
66
+ examples=["2023-01-01", "2023-12-11"],
67
+ cache_examples=True,
68
+ title="Is it a weekday?")
69
+
70
+ if __name__ == "__main__":
71
+ demo.launch()
72
+
73
+ ```
74
+ """, elem_classes=["md-custom"], header_links=True)
75
+
76
+
77
+ gr.Markdown("""
78
+ ## `Calendar`
79
+
80
+ ### Initialization
81
+ """, elem_classes=["md-custom"], header_links=True)
82
+
83
+ gr.ParamViewer(value=_docs["Calendar"]["members"]["__init__"], linkify=[])
84
+
85
+
86
+ gr.Markdown("### Events")
87
+ gr.ParamViewer(value=_docs["Calendar"]["events"], linkify=['Event'])
88
+
89
+
90
+
91
+
92
+ gr.Markdown("""
93
+
94
+ ### User function
95
+
96
+ 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).
97
+
98
+ - When used as an Input, the component only impacts the input signature of the user function.
99
+ - When used as an output, the component only impacts the return signature of the user function.
100
+
101
+ The code snippet below is accurate in cases where the component is used as both an input and an output.
102
+
103
+
104
+
105
+ ```python
106
+ def predict(
107
+ value: str | datetime.datetime | None
108
+ ) -> str | datetime.datetime | None:
109
+ return value
110
+ ```
111
+ """, elem_classes=["md-custom", "Calendar-user-fn"], header_links=True)
112
+
113
+
114
+
115
 
116
+ demo.load(None, js=r"""function() {
117
+ const refs = {};
118
+ const user_fn_refs = {
119
+ Calendar: [], };
120
+ requestAnimationFrame(() => {
121
+
122
+ Object.entries(user_fn_refs).forEach(([key, refs]) => {
123
+ if (refs.length > 0) {
124
+ const el = document.querySelector(`.${key}-user-fn`);
125
+ if (!el) return;
126
+ refs.forEach(ref => {
127
+ el.innerHTML = el.innerHTML.replace(
128
+ new RegExp("\\b"+ref+"\\b", "g"),
129
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
130
+ );
131
+ })
132
+ }
133
+ })
134
+
135
+ Object.entries(refs).forEach(([key, refs]) => {
136
+ if (refs.length > 0) {
137
+ const el = document.querySelector(`.${key}`);
138
+ if (!el) return;
139
+ refs.forEach(ref => {
140
+ el.innerHTML = el.innerHTML.replace(
141
+ new RegExp("\\b"+ref+"\\b", "g"),
142
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
143
+ );
144
+ })
145
+ }
146
+ })
147
+ })
148
+ }
149
+
150
+ """)
151
 
152
  demo.launch()
153
 
154
  ```
155
 
156
+ ## `Calendar`
157
+
158
+ ### Initialization
159
+
160
+ <table>
161
+ <thead>
162
+ <tr>
163
+ <th align="left">name</th>
164
+ <th align="left" style="width: 25%;">type</th>
165
+ <th align="left">default</th>
166
+ <th align="left">description</th>
167
+ </tr>
168
+ </thead>
169
+ <tbody>
170
+ <tr>
171
+ <td align="left"><code>value</code></td>
172
+ <td align="left" style="width: 25%;">
173
+
174
+ ```python
175
+ str | datetime.datetime
176
+ ```
177
+
178
+ </td>
179
+ <td align="left"><code>None</code></td>
180
+ <td align="left">None</td>
181
+ </tr>
182
+
183
+ <tr>
184
+ <td align="left"><code>type</code></td>
185
+ <td align="left" style="width: 25%;">
186
+
187
+ ```python
188
+ Literal["string", "datetime"]
189
+ ```
190
+
191
+ </td>
192
+ <td align="left"><code>"datetime"</code></td>
193
+ <td align="left">None</td>
194
+ </tr>
195
+
196
+ <tr>
197
+ <td align="left"><code>label</code></td>
198
+ <td align="left" style="width: 25%;">
199
+
200
+ ```python
201
+ str | None
202
+ ```
203
+
204
+ </td>
205
+ <td align="left"><code>None</code></td>
206
+ <td align="left">None</td>
207
+ </tr>
208
+
209
+ <tr>
210
+ <td align="left"><code>info</code></td>
211
+ <td align="left" style="width: 25%;">
212
+
213
+ ```python
214
+ str | None
215
+ ```
216
+
217
+ </td>
218
+ <td align="left"><code>None</code></td>
219
+ <td align="left">None</td>
220
+ </tr>
221
+
222
+ <tr>
223
+ <td align="left"><code>show_label</code></td>
224
+ <td align="left" style="width: 25%;">
225
+
226
+ ```python
227
+ bool | None
228
+ ```
229
+
230
+ </td>
231
+ <td align="left"><code>None</code></td>
232
+ <td align="left">None</td>
233
+ </tr>
234
+
235
+ <tr>
236
+ <td align="left"><code>container</code></td>
237
+ <td align="left" style="width: 25%;">
238
+
239
+ ```python
240
+ bool
241
+ ```
242
+
243
+ </td>
244
+ <td align="left"><code>True</code></td>
245
+ <td align="left">None</td>
246
+ </tr>
247
+
248
+ <tr>
249
+ <td align="left"><code>scale</code></td>
250
+ <td align="left" style="width: 25%;">
251
+
252
+ ```python
253
+ int | None
254
+ ```
255
+
256
+ </td>
257
+ <td align="left"><code>None</code></td>
258
+ <td align="left">None</td>
259
+ </tr>
260
+
261
+ <tr>
262
+ <td align="left"><code>min_width</code></td>
263
+ <td align="left" style="width: 25%;">
264
+
265
+ ```python
266
+ int | None
267
+ ```
268
+
269
+ </td>
270
+ <td align="left"><code>None</code></td>
271
+ <td align="left">None</td>
272
+ </tr>
273
+
274
+ <tr>
275
+ <td align="left"><code>interactive</code></td>
276
+ <td align="left" style="width: 25%;">
277
+
278
+ ```python
279
+ bool | None
280
+ ```
281
+
282
+ </td>
283
+ <td align="left"><code>None</code></td>
284
+ <td align="left">None</td>
285
+ </tr>
286
+
287
+ <tr>
288
+ <td align="left"><code>visible</code></td>
289
+ <td align="left" style="width: 25%;">
290
+
291
+ ```python
292
+ bool
293
+ ```
294
+
295
+ </td>
296
+ <td align="left"><code>True</code></td>
297
+ <td align="left">None</td>
298
+ </tr>
299
+
300
+ <tr>
301
+ <td align="left"><code>elem_id</code></td>
302
+ <td align="left" style="width: 25%;">
303
+
304
+ ```python
305
+ str | None
306
+ ```
307
+
308
+ </td>
309
+ <td align="left"><code>None</code></td>
310
+ <td align="left">None</td>
311
+ </tr>
312
+
313
+ <tr>
314
+ <td align="left"><code>elem_classes</code></td>
315
+ <td align="left" style="width: 25%;">
316
+
317
+ ```python
318
+ list[str] | str | None
319
+ ```
320
+
321
+ </td>
322
+ <td align="left"><code>None</code></td>
323
+ <td align="left">None</td>
324
+ </tr>
325
+
326
+ <tr>
327
+ <td align="left"><code>render</code></td>
328
+ <td align="left" style="width: 25%;">
329
+
330
+ ```python
331
+ bool
332
+ ```
333
+
334
+ </td>
335
+ <td align="left"><code>True</code></td>
336
+ <td align="left">None</td>
337
+ </tr>
338
+
339
+ <tr>
340
+ <td align="left"><code>load_fn</code></td>
341
+ <td align="left" style="width: 25%;">
342
+
343
+ ```python
344
+ Callable[..., Any] | None
345
+ ```
346
+
347
+ </td>
348
+ <td align="left"><code>None</code></td>
349
+ <td align="left">None</td>
350
+ </tr>
351
+
352
+ <tr>
353
+ <td align="left"><code>every</code></td>
354
+ <td align="left" style="width: 25%;">
355
+
356
+ ```python
357
+ float | None
358
+ ```
359
+
360
+ </td>
361
+ <td align="left"><code>None</code></td>
362
+ <td align="left">None</td>
363
+ </tr>
364
+ </tbody></table>
365
+
366
+
367
+ ### Events
368
+
369
+ | name | description |
370
+ |:-----|:------------|
371
+ | `change` | |
372
+ | `input` | |
373
+ | `submit` | |
374
+
375
+
376
+
377
+ ### User function
378
+
379
+ 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).
380
+
381
+ - When used as an Input, the component only impacts the input signature of the user function.
382
+ - When used as an output, the component only impacts the return signature of the user function.
383
+
384
+ The code snippet below is accurate in cases where the component is used as both an input and an output.
385
+
386
+
387
 
388
+ ```python
389
+ def predict(
390
+ value: str | datetime.datetime | None
391
+ ) -> str | datetime.datetime | None:
392
+ return value
393
+ ```
394
+
src/backend/gradio_calendar/calendar.pyi CHANGED
@@ -88,7 +88,8 @@ class Calendar(Component):
88
  trigger_mode: Literal["once", "multiple", "always_last"] | None = None,
89
  js: str | None = None,
90
  concurrency_limit: int | None | Literal["default"] = "default",
91
- concurrency_id: str | None = None) -> Dependency:
 
92
  """
93
  Parameters:
94
  fn: the function to call when this event is triggered. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component.
@@ -106,8 +107,9 @@ class Calendar(Component):
106
  every: Run this event 'every' number of seconds while the client connection is open. Interpreted in seconds. Queue must be enabled.
107
  trigger_mode: If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` event) would allow a second submission after the pending event is complete.
108
  js: Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components.
109
- concurrency_limit: If set, this this is the maximum number of this event that can be running simultaneously. Can be set to None to mean no concurrency_limit (any number of this event can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `Blocks.queue()`, which itself is 1 by default).
110
  concurrency_id: If set, this is the id of the concurrency group. Events with the same concurrency_id will be limited by the lowest set concurrency_limit.
 
111
  """
112
  ...
113
 
@@ -128,7 +130,8 @@ class Calendar(Component):
128
  trigger_mode: Literal["once", "multiple", "always_last"] | None = None,
129
  js: str | None = None,
130
  concurrency_limit: int | None | Literal["default"] = "default",
131
- concurrency_id: str | None = None) -> Dependency:
 
132
  """
133
  Parameters:
134
  fn: the function to call when this event is triggered. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component.
@@ -146,8 +149,9 @@ class Calendar(Component):
146
  every: Run this event 'every' number of seconds while the client connection is open. Interpreted in seconds. Queue must be enabled.
147
  trigger_mode: If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` event) would allow a second submission after the pending event is complete.
148
  js: Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components.
149
- concurrency_limit: If set, this this is the maximum number of this event that can be running simultaneously. Can be set to None to mean no concurrency_limit (any number of this event can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `Blocks.queue()`, which itself is 1 by default).
150
  concurrency_id: If set, this is the id of the concurrency group. Events with the same concurrency_id will be limited by the lowest set concurrency_limit.
 
151
  """
152
  ...
153
 
@@ -168,7 +172,8 @@ class Calendar(Component):
168
  trigger_mode: Literal["once", "multiple", "always_last"] | None = None,
169
  js: str | None = None,
170
  concurrency_limit: int | None | Literal["default"] = "default",
171
- concurrency_id: str | None = None) -> Dependency:
 
172
  """
173
  Parameters:
174
  fn: the function to call when this event is triggered. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component.
@@ -186,7 +191,8 @@ class Calendar(Component):
186
  every: Run this event 'every' number of seconds while the client connection is open. Interpreted in seconds. Queue must be enabled.
187
  trigger_mode: If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` event) would allow a second submission after the pending event is complete.
188
  js: Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components.
189
- concurrency_limit: If set, this this is the maximum number of this event that can be running simultaneously. Can be set to None to mean no concurrency_limit (any number of this event can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `Blocks.queue()`, which itself is 1 by default).
190
  concurrency_id: If set, this is the id of the concurrency group. Events with the same concurrency_id will be limited by the lowest set concurrency_limit.
 
191
  """
192
  ...
 
88
  trigger_mode: Literal["once", "multiple", "always_last"] | None = None,
89
  js: str | None = None,
90
  concurrency_limit: int | None | Literal["default"] = "default",
91
+ concurrency_id: str | None = None,
92
+ show_api: bool = True) -> Dependency:
93
  """
94
  Parameters:
95
  fn: the function to call when this event is triggered. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component.
 
107
  every: Run this event 'every' number of seconds while the client connection is open. Interpreted in seconds. Queue must be enabled.
108
  trigger_mode: If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` event) would allow a second submission after the pending event is complete.
109
  js: Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components.
110
+ concurrency_limit: If set, this is the maximum number of this event that can be running simultaneously. Can be set to None to mean no concurrency_limit (any number of this event can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `Blocks.queue()`, which itself is 1 by default).
111
  concurrency_id: If set, this is the id of the concurrency group. Events with the same concurrency_id will be limited by the lowest set concurrency_limit.
112
+ show_api: whether to show this event in the "view API" page of the Gradio app, or in the ".view_api()" method of the Gradio clients. Unlike setting api_name to False, setting show_api to False will still allow downstream apps to use this event. If fn is None, show_api will automatically be set to False.
113
  """
114
  ...
115
 
 
130
  trigger_mode: Literal["once", "multiple", "always_last"] | None = None,
131
  js: str | None = None,
132
  concurrency_limit: int | None | Literal["default"] = "default",
133
+ concurrency_id: str | None = None,
134
+ show_api: bool = True) -> Dependency:
135
  """
136
  Parameters:
137
  fn: the function to call when this event is triggered. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component.
 
149
  every: Run this event 'every' number of seconds while the client connection is open. Interpreted in seconds. Queue must be enabled.
150
  trigger_mode: If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` event) would allow a second submission after the pending event is complete.
151
  js: Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components.
152
+ concurrency_limit: If set, this is the maximum number of this event that can be running simultaneously. Can be set to None to mean no concurrency_limit (any number of this event can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `Blocks.queue()`, which itself is 1 by default).
153
  concurrency_id: If set, this is the id of the concurrency group. Events with the same concurrency_id will be limited by the lowest set concurrency_limit.
154
+ show_api: whether to show this event in the "view API" page of the Gradio app, or in the ".view_api()" method of the Gradio clients. Unlike setting api_name to False, setting show_api to False will still allow downstream apps to use this event. If fn is None, show_api will automatically be set to False.
155
  """
156
  ...
157
 
 
172
  trigger_mode: Literal["once", "multiple", "always_last"] | None = None,
173
  js: str | None = None,
174
  concurrency_limit: int | None | Literal["default"] = "default",
175
+ concurrency_id: str | None = None,
176
+ show_api: bool = True) -> Dependency:
177
  """
178
  Parameters:
179
  fn: the function to call when this event is triggered. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component.
 
191
  every: Run this event 'every' number of seconds while the client connection is open. Interpreted in seconds. Queue must be enabled.
192
  trigger_mode: If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` event) would allow a second submission after the pending event is complete.
193
  js: Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components.
194
+ concurrency_limit: If set, this is the maximum number of this event that can be running simultaneously. Can be set to None to mean no concurrency_limit (any number of this event can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `Blocks.queue()`, which itself is 1 by default).
195
  concurrency_id: If set, this is the id of the concurrency group. Events with the same concurrency_id will be limited by the lowest set concurrency_limit.
196
+ show_api: whether to show this event in the "view API" page of the Gradio app, or in the ".view_api()" method of the Gradio clients. Unlike setting api_name to False, setting show_api to False will still allow downstream apps to use this event. If fn is None, show_api will automatically be set to False.
197
  """
198
  ...
src/demo/_app.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from gradio_calendar import Calendar
3
+ import datetime
4
+
5
+ def is_weekday(date: datetime.datetime):
6
+ return date.weekday() < 5
7
+
8
+ demo = gr.Interface(is_weekday,
9
+ [Calendar(type="datetime", label="Select a date", info="Click the calendar icon to bring up the calendar.")],
10
+ gr.Label(label="Is it a weekday?"),
11
+ examples=["2023-01-01", "2023-12-11"],
12
+ cache_examples=True,
13
+ title="Is it a weekday?")
14
+
15
+ if __name__ == "__main__":
16
+ demo.launch()
src/demo/app.py CHANGED
@@ -1,3 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  from gradio_calendar import Calendar
3
  import datetime
@@ -12,5 +52,86 @@ demo = gr.Interface(is_weekday,
12
  cache_examples=True,
13
  title="Is it a weekday?")
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  demo.launch()
 
1
+
2
+ import gradio as gr
3
+ from _app import demo as app
4
+ import os
5
+
6
+ _docs = {'Calendar': {'description': 'A calendar component that allows users to select a date.\n\ndepending on the value of the type parameter.\n\n\n value: The default date value, formatted as YYYY-MM-DD. Can be either a string or datetime.datetime object.\n type: The type of the value to pass to the python function. Either "string" or "datetime".\n label: The label for the component.\n info: Extra text to render below the component.\n show_label: Whether to show the label for the component.\n container: Whether to show the component in a container.\n scale: The relative size of the component compared to other components in the same row.\n min_width: The minimum width of the component.\n interactive: Whether to allow the user to interact with the component.\n visible: Whether to show the component.\n elem_id: The id of the component. Useful for custom js or css.\n elem_classes: The classes of the component. Useful for custom js or css.\n render: Whether to render the component in the parent Blocks scope.\n load_fn: A function to run when the component is first loaded onto the page to set the intial value.\n every: Whether load_fn should be run on a fixed time interval.', 'members': {'__init__': {'value': {'type': 'str | datetime.datetime', 'default': 'None', 'description': None}, 'type': {'type': 'Literal["string", "datetime"]', 'default': '"datetime"', 'description': None}, 'label': {'type': 'str | None', 'default': 'None', 'description': None}, 'info': {'type': 'str | None', 'default': 'None', 'description': None}, 'show_label': {'type': 'bool | None', 'default': 'None', 'description': None}, 'container': {'type': 'bool', 'default': 'True', 'description': None}, 'scale': {'type': 'int | None', 'default': 'None', 'description': None}, 'min_width': {'type': 'int | None', 'default': 'None', 'description': None}, 'interactive': {'type': 'bool | None', 'default': 'None', 'description': None}, 'visible': {'type': 'bool', 'default': 'True', 'description': None}, 'elem_id': {'type': 'str | None', 'default': 'None', 'description': None}, 'elem_classes': {'type': 'list[str] | str | None', 'default': 'None', 'description': None}, 'render': {'type': 'bool', 'default': 'True', 'description': None}, 'load_fn': {'type': 'Callable[..., Any] | None', 'default': 'None', 'description': None}, 'every': {'type': 'float | None', 'default': 'None', 'description': None}}, 'postprocess': {'value': {'type': 'str | datetime.datetime | None', 'description': None}}, 'preprocess': {'return': {'type': 'str | datetime.datetime | None', 'description': None}, 'value': None}}, 'events': {'change': {'type': None, 'default': None, 'description': ''}, 'input': {'type': None, 'default': None, 'description': ''}, 'submit': {'type': None, 'default': None, 'description': ''}}}, '__meta__': {'additional_interfaces': {}, 'user_fn_refs': {'Calendar': []}}}
7
+
8
+ abs_path = os.path.join(os.path.dirname(__file__), "css.css")
9
+
10
+ with gr.Blocks(
11
+ css=abs_path,
12
+ theme=gr.themes.Default(
13
+ font_mono=[
14
+ gr.themes.GoogleFont("Inconsolata"),
15
+ "monospace",
16
+ ],
17
+ ),
18
+ ) as demo:
19
+ gr.Markdown(
20
+ """
21
+ # `gradio_calendar`
22
+
23
+ <div style="display: flex; gap: 7px;">
24
+ <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/settings/discussions" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/%F0%9F%A4%97%20Discuss-%23097EFF?style=flat&logoColor=black"></a>
25
+ </div>
26
+
27
+ Gradio component for selecting dates with a calendar πŸ“†
28
+ """, elem_classes=["md-custom"], header_links=True)
29
+ app.render()
30
+ gr.Markdown(
31
+ """
32
+ ## Installation
33
+
34
+ ```bash
35
+ pip install gradio_calendar
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ ```python
41
  import gradio as gr
42
  from gradio_calendar import Calendar
43
  import datetime
 
52
  cache_examples=True,
53
  title="Is it a weekday?")
54
 
55
+ if __name__ == "__main__":
56
+ demo.launch()
57
+
58
+ ```
59
+ """, elem_classes=["md-custom"], header_links=True)
60
+
61
+
62
+ gr.Markdown("""
63
+ ## `Calendar`
64
+
65
+ ### Initialization
66
+ """, elem_classes=["md-custom"], header_links=True)
67
+
68
+ gr.ParamViewer(value=_docs["Calendar"]["members"]["__init__"], linkify=[])
69
+
70
+
71
+ gr.Markdown("### Events")
72
+ gr.ParamViewer(value=_docs["Calendar"]["events"], linkify=['Event'])
73
+
74
+
75
+
76
+
77
+ gr.Markdown("""
78
+
79
+ ### User function
80
+
81
+ 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).
82
+
83
+ - When used as an Input, the component only impacts the input signature of the user function.
84
+ - When used as an output, the component only impacts the return signature of the user function.
85
+
86
+ The code snippet below is accurate in cases where the component is used as both an input and an output.
87
+
88
+
89
+
90
+ ```python
91
+ def predict(
92
+ value: str | datetime.datetime | None
93
+ ) -> str | datetime.datetime | None:
94
+ return value
95
+ ```
96
+ """, elem_classes=["md-custom", "Calendar-user-fn"], header_links=True)
97
+
98
+
99
+
100
+
101
+ demo.load(None, js=r"""function() {
102
+ const refs = {};
103
+ const user_fn_refs = {
104
+ Calendar: [], };
105
+ requestAnimationFrame(() => {
106
+
107
+ Object.entries(user_fn_refs).forEach(([key, refs]) => {
108
+ if (refs.length > 0) {
109
+ const el = document.querySelector(`.${key}-user-fn`);
110
+ if (!el) return;
111
+ refs.forEach(ref => {
112
+ el.innerHTML = el.innerHTML.replace(
113
+ new RegExp("\\b"+ref+"\\b", "g"),
114
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
115
+ );
116
+ })
117
+ }
118
+ })
119
+
120
+ Object.entries(refs).forEach(([key, refs]) => {
121
+ if (refs.length > 0) {
122
+ const el = document.querySelector(`.${key}`);
123
+ if (!el) return;
124
+ refs.forEach(ref => {
125
+ el.innerHTML = el.innerHTML.replace(
126
+ new RegExp("\\b"+ref+"\\b", "g"),
127
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
128
+ );
129
+ })
130
+ }
131
+ })
132
+ })
133
+ }
134
+
135
+ """)
136
 
137
  demo.launch()
src/demo/css.css ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ html {
2
+ font-family: Inter;
3
+ font-size: 16px;
4
+ font-weight: 400;
5
+ line-height: 1.5;
6
+ -webkit-text-size-adjust: 100%;
7
+ background: #fff;
8
+ color: #323232;
9
+ -webkit-font-smoothing: antialiased;
10
+ -moz-osx-font-smoothing: grayscale;
11
+ text-rendering: optimizeLegibility;
12
+ }
13
+
14
+ :root {
15
+ --space: 1;
16
+ --vspace: calc(var(--space) * 1rem);
17
+ --vspace-0: calc(3 * var(--space) * 1rem);
18
+ --vspace-1: calc(2 * var(--space) * 1rem);
19
+ --vspace-2: calc(1.5 * var(--space) * 1rem);
20
+ --vspace-3: calc(0.5 * var(--space) * 1rem);
21
+ }
22
+
23
+ .app {
24
+ max-width: 748px !important;
25
+ }
26
+
27
+ .prose p {
28
+ margin: var(--vspace) 0;
29
+ line-height: var(--vspace * 2);
30
+ font-size: 1rem;
31
+ }
32
+
33
+ code {
34
+ font-family: "Inconsolata", sans-serif;
35
+ font-size: 16px;
36
+ }
37
+
38
+ h1,
39
+ h1 code {
40
+ font-weight: 400;
41
+ line-height: calc(2.5 / var(--space) * var(--vspace));
42
+ }
43
+
44
+ h1 code {
45
+ background: none;
46
+ border: none;
47
+ letter-spacing: 0.05em;
48
+ padding-bottom: 5px;
49
+ position: relative;
50
+ padding: 0;
51
+ }
52
+
53
+ h2 {
54
+ margin: var(--vspace-1) 0 var(--vspace-2) 0;
55
+ line-height: 1em;
56
+ }
57
+
58
+ h3,
59
+ h3 code {
60
+ margin: var(--vspace-1) 0 var(--vspace-2) 0;
61
+ line-height: 1em;
62
+ }
63
+
64
+ h4,
65
+ h5,
66
+ h6 {
67
+ margin: var(--vspace-3) 0 var(--vspace-3) 0;
68
+ line-height: var(--vspace);
69
+ }
70
+
71
+ .bigtitle,
72
+ h1,
73
+ h1 code {
74
+ font-size: calc(8px * 4.5);
75
+ word-break: break-word;
76
+ }
77
+
78
+ .title,
79
+ h2,
80
+ h2 code {
81
+ font-size: calc(8px * 3.375);
82
+ font-weight: lighter;
83
+ word-break: break-word;
84
+ border: none;
85
+ background: none;
86
+ }
87
+
88
+ .subheading1,
89
+ h3,
90
+ h3 code {
91
+ font-size: calc(8px * 1.8);
92
+ font-weight: 600;
93
+ border: none;
94
+ background: none;
95
+ letter-spacing: 0.1em;
96
+ text-transform: uppercase;
97
+ }
98
+
99
+ h2 code {
100
+ padding: 0;
101
+ position: relative;
102
+ letter-spacing: 0.05em;
103
+ }
104
+
105
+ blockquote {
106
+ font-size: calc(8px * 1.1667);
107
+ font-style: italic;
108
+ line-height: calc(1.1667 * var(--vspace));
109
+ margin: var(--vspace-2) var(--vspace-2);
110
+ }
111
+
112
+ .subheading2,
113
+ h4 {
114
+ font-size: calc(8px * 1.4292);
115
+ text-transform: uppercase;
116
+ font-weight: 600;
117
+ }
118
+
119
+ .subheading3,
120
+ h5 {
121
+ font-size: calc(8px * 1.2917);
122
+ line-height: calc(1.2917 * var(--vspace));
123
+
124
+ font-weight: lighter;
125
+ text-transform: uppercase;
126
+ letter-spacing: 0.15em;
127
+ }
128
+
129
+ h6 {
130
+ font-size: calc(8px * 1.1667);
131
+ font-size: 1.1667em;
132
+ font-weight: normal;
133
+ font-style: italic;
134
+ font-family: "le-monde-livre-classic-byol", serif !important;
135
+ letter-spacing: 0px !important;
136
+ }
137
+
138
+ #start .md > *:first-child {
139
+ margin-top: 0;
140
+ }
141
+
142
+ h2 + h3 {
143
+ margin-top: 0;
144
+ }
145
+
146
+ .md hr {
147
+ border: none;
148
+ border-top: 1px solid var(--block-border-color);
149
+ margin: var(--vspace-2) 0 var(--vspace-2) 0;
150
+ }
151
+ .prose ul {
152
+ margin: var(--vspace-2) 0 var(--vspace-1) 0;
153
+ }
154
+
155
+ .gap {
156
+ gap: 0;
157
+ }
src/demo/space.py ADDED
@@ -0,0 +1,258 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ from app import demo as app
4
+ import os
5
+
6
+ _docs = {'Calendar': {'description': 'A calendar component that allows users to select a date.\n\ndepending on the value of the type parameter.\n\n\n value: The default date value, formatted as YYYY-MM-DD. Can be either a string or datetime.datetime object.\n type: The type of the value to pass to the python function. Either "string" or "datetime".\n label: The label for the component.\n info: Extra text to render below the component.\n show_label: Whether to show the label for the component.\n container: Whether to show the component in a container.\n scale: The relative size of the component compared to other components in the same row.\n min_width: The minimum width of the component.\n interactive: Whether to allow the user to interact with the component.\n visible: Whether to show the component.\n elem_id: The id of the component. Useful for custom js or css.\n elem_classes: The classes of the component. Useful for custom js or css.\n render: Whether to render the component in the parent Blocks scope.\n load_fn: A function to run when the component is first loaded onto the page to set the intial value.\n every: Whether load_fn should be run on a fixed time interval.', 'members': {'__init__': {'value': {'type': 'str | datetime.datetime', 'default': 'None', 'description': None}, 'type': {'type': 'Literal["string", "datetime"]', 'default': '"datetime"', 'description': None}, 'label': {'type': 'str | None', 'default': 'None', 'description': None}, 'info': {'type': 'str | None', 'default': 'None', 'description': None}, 'show_label': {'type': 'bool | None', 'default': 'None', 'description': None}, 'container': {'type': 'bool', 'default': 'True', 'description': None}, 'scale': {'type': 'int | None', 'default': 'None', 'description': None}, 'min_width': {'type': 'int | None', 'default': 'None', 'description': None}, 'interactive': {'type': 'bool | None', 'default': 'None', 'description': None}, 'visible': {'type': 'bool', 'default': 'True', 'description': None}, 'elem_id': {'type': 'str | None', 'default': 'None', 'description': None}, 'elem_classes': {'type': 'list[str] | str | None', 'default': 'None', 'description': None}, 'render': {'type': 'bool', 'default': 'True', 'description': None}, 'load_fn': {'type': 'Callable[..., Any] | None', 'default': 'None', 'description': None}, 'every': {'type': 'float | None', 'default': 'None', 'description': None}}, 'postprocess': {'value': {'type': 'str | datetime.datetime | None', 'description': None}}, 'preprocess': {'return': {'type': 'str | datetime.datetime | None', 'description': None}, 'value': None}}, 'events': {'change': {'type': None, 'default': None, 'description': ''}, 'input': {'type': None, 'default': None, 'description': ''}, 'submit': {'type': None, 'default': None, 'description': ''}}}, '__meta__': {'additional_interfaces': {}, 'user_fn_refs': {'Calendar': []}}}
7
+
8
+ abs_path = os.path.join(os.path.dirname(__file__), "css.css")
9
+
10
+ with gr.Blocks(
11
+ css=abs_path,
12
+ theme=gr.themes.Default(
13
+ font_mono=[
14
+ gr.themes.GoogleFont("Inconsolata"),
15
+ "monospace",
16
+ ],
17
+ ),
18
+ ) as demo:
19
+ gr.Markdown(
20
+ """
21
+ # `gradio_calendar`
22
+
23
+ <div style="display: flex; gap: 7px;">
24
+ <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/settings/discussions" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/%F0%9F%A4%97%20Discuss-%23097EFF?style=flat&logoColor=black"></a>
25
+ </div>
26
+
27
+ Gradio component for selecting dates with a calendar πŸ“†
28
+ """, elem_classes=["md-custom"], header_links=True)
29
+ app.render()
30
+ gr.Markdown(
31
+ """
32
+ ## Installation
33
+
34
+ ```bash
35
+ pip install gradio_calendar
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ ```python
41
+
42
+ import gradio as gr
43
+ from _app import demo as app
44
+ import os
45
+
46
+ _docs = {'Calendar': {'description': 'A calendar component that allows users to select a date.\n\ndepending on the value of the type parameter.\n\n\n value: The default date value, formatted as YYYY-MM-DD. Can be either a string or datetime.datetime object.\n type: The type of the value to pass to the python function. Either "string" or "datetime".\n label: The label for the component.\n info: Extra text to render below the component.\n show_label: Whether to show the label for the component.\n container: Whether to show the component in a container.\n scale: The relative size of the component compared to other components in the same row.\n min_width: The minimum width of the component.\n interactive: Whether to allow the user to interact with the component.\n visible: Whether to show the component.\n elem_id: The id of the component. Useful for custom js or css.\n elem_classes: The classes of the component. Useful for custom js or css.\n render: Whether to render the component in the parent Blocks scope.\n load_fn: A function to run when the component is first loaded onto the page to set the intial value.\n every: Whether load_fn should be run on a fixed time interval.', 'members': {'__init__': {'value': {'type': 'str | datetime.datetime', 'default': 'None', 'description': None}, 'type': {'type': 'Literal["string", "datetime"]', 'default': '"datetime"', 'description': None}, 'label': {'type': 'str | None', 'default': 'None', 'description': None}, 'info': {'type': 'str | None', 'default': 'None', 'description': None}, 'show_label': {'type': 'bool | None', 'default': 'None', 'description': None}, 'container': {'type': 'bool', 'default': 'True', 'description': None}, 'scale': {'type': 'int | None', 'default': 'None', 'description': None}, 'min_width': {'type': 'int | None', 'default': 'None', 'description': None}, 'interactive': {'type': 'bool | None', 'default': 'None', 'description': None}, 'visible': {'type': 'bool', 'default': 'True', 'description': None}, 'elem_id': {'type': 'str | None', 'default': 'None', 'description': None}, 'elem_classes': {'type': 'list[str] | str | None', 'default': 'None', 'description': None}, 'render': {'type': 'bool', 'default': 'True', 'description': None}, 'load_fn': {'type': 'Callable[..., Any] | None', 'default': 'None', 'description': None}, 'every': {'type': 'float | None', 'default': 'None', 'description': None}}, 'postprocess': {'value': {'type': 'str | datetime.datetime | None', 'description': None}}, 'preprocess': {'return': {'type': 'str | datetime.datetime | None', 'description': None}, 'value': None}}, 'events': {'change': {'type': None, 'default': None, 'description': ''}, 'input': {'type': None, 'default': None, 'description': ''}, 'submit': {'type': None, 'default': None, 'description': ''}}}, '__meta__': {'additional_interfaces': {}, 'user_fn_refs': {'Calendar': []}}}
47
+
48
+ abs_path = os.path.join(os.path.dirname(__file__), "css.css")
49
+
50
+ with gr.Blocks(
51
+ css=abs_path,
52
+ theme=gr.themes.Default(
53
+ font_mono=[
54
+ gr.themes.GoogleFont("Inconsolata"),
55
+ "monospace",
56
+ ],
57
+ ),
58
+ ) as demo:
59
+ gr.Markdown(
60
+ """
61
+ # `gradio_calendar`
62
+
63
+ <div style="display: flex; gap: 7px;">
64
+ <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/settings/discussions" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/%F0%9F%A4%97%20Discuss-%23097EFF?style=flat&logoColor=black"></a>
65
+ </div>
66
+
67
+ Gradio component for selecting dates with a calendar πŸ“†
68
+ """, elem_classes=["md-custom"], header_links=True)
69
+ app.render()
70
+ gr.Markdown(
71
+ """
72
+ ## Installation
73
+
74
+ ```bash
75
+ pip install gradio_calendar
76
+ ```
77
+
78
+ ## Usage
79
+
80
+ ```python
81
+ import gradio as gr
82
+ from gradio_calendar import Calendar
83
+ import datetime
84
+
85
+ def is_weekday(date: datetime.datetime):
86
+ return date.weekday() < 5
87
+
88
+ demo = gr.Interface(is_weekday,
89
+ [Calendar(type="datetime", label="Select a date", info="Click the calendar icon to bring up the calendar.")],
90
+ gr.Label(label="Is it a weekday?"),
91
+ examples=["2023-01-01", "2023-12-11"],
92
+ cache_examples=True,
93
+ title="Is it a weekday?")
94
+
95
+ if __name__ == "__main__":
96
+ demo.launch()
97
+
98
+ ```
99
+ """, elem_classes=["md-custom"], header_links=True)
100
+
101
+
102
+ gr.Markdown("""
103
+ ## `Calendar`
104
+
105
+ ### Initialization
106
+ """, elem_classes=["md-custom"], header_links=True)
107
+
108
+ gr.ParamViewer(value=_docs["Calendar"]["members"]["__init__"], linkify=[])
109
+
110
+
111
+ gr.Markdown("### Events")
112
+ gr.ParamViewer(value=_docs["Calendar"]["events"], linkify=['Event'])
113
+
114
+
115
+
116
+
117
+ gr.Markdown("""
118
+
119
+ ### User function
120
+
121
+ 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).
122
+
123
+ - When used as an Input, the component only impacts the input signature of the user function.
124
+ - When used as an output, the component only impacts the return signature of the user function.
125
+
126
+ The code snippet below is accurate in cases where the component is used as both an input and an output.
127
+
128
+
129
+
130
+ ```python
131
+ def predict(
132
+ value: str | datetime.datetime | None
133
+ ) -> str | datetime.datetime | None:
134
+ return value
135
+ ```
136
+ """, elem_classes=["md-custom", "Calendar-user-fn"], header_links=True)
137
+
138
+
139
+
140
+
141
+ demo.load(None, js=r"""function() {
142
+ const refs = {};
143
+ const user_fn_refs = {
144
+ Calendar: [], };
145
+ requestAnimationFrame(() => {
146
+
147
+ Object.entries(user_fn_refs).forEach(([key, refs]) => {
148
+ if (refs.length > 0) {
149
+ const el = document.querySelector(`.${key}-user-fn`);
150
+ if (!el) return;
151
+ refs.forEach(ref => {
152
+ el.innerHTML = el.innerHTML.replace(
153
+ new RegExp("\\b"+ref+"\\b", "g"),
154
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
155
+ );
156
+ })
157
+ }
158
+ })
159
+
160
+ Object.entries(refs).forEach(([key, refs]) => {
161
+ if (refs.length > 0) {
162
+ const el = document.querySelector(`.${key}`);
163
+ if (!el) return;
164
+ refs.forEach(ref => {
165
+ el.innerHTML = el.innerHTML.replace(
166
+ new RegExp("\\b"+ref+"\\b", "g"),
167
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
168
+ );
169
+ })
170
+ }
171
+ })
172
+ })
173
+ }
174
+
175
+ """)
176
+
177
+ demo.launch()
178
+
179
+ ```
180
+ """, elem_classes=["md-custom"], header_links=True)
181
+
182
+
183
+ gr.Markdown("""
184
+ ## `Calendar`
185
+
186
+ ### Initialization
187
+ """, elem_classes=["md-custom"], header_links=True)
188
+
189
+ gr.ParamViewer(value=_docs["Calendar"]["members"]["__init__"], linkify=[])
190
+
191
+
192
+ gr.Markdown("### Events")
193
+ gr.ParamViewer(value=_docs["Calendar"]["events"], linkify=['Event'])
194
+
195
+
196
+
197
+
198
+ gr.Markdown("""
199
+
200
+ ### User function
201
+
202
+ 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).
203
+
204
+ - When used as an Input, the component only impacts the input signature of the user function.
205
+ - When used as an output, the component only impacts the return signature of the user function.
206
+
207
+ The code snippet below is accurate in cases where the component is used as both an input and an output.
208
+
209
+
210
+
211
+ ```python
212
+ def predict(
213
+ value: str | datetime.datetime | None
214
+ ) -> str | datetime.datetime | None:
215
+ return value
216
+ ```
217
+ """, elem_classes=["md-custom", "Calendar-user-fn"], header_links=True)
218
+
219
+
220
+
221
+
222
+ demo.load(None, js=r"""function() {
223
+ const refs = {};
224
+ const user_fn_refs = {
225
+ Calendar: [], };
226
+ requestAnimationFrame(() => {
227
+
228
+ Object.entries(user_fn_refs).forEach(([key, refs]) => {
229
+ if (refs.length > 0) {
230
+ const el = document.querySelector(`.${key}-user-fn`);
231
+ if (!el) return;
232
+ refs.forEach(ref => {
233
+ el.innerHTML = el.innerHTML.replace(
234
+ new RegExp("\\b"+ref+"\\b", "g"),
235
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
236
+ );
237
+ })
238
+ }
239
+ })
240
+
241
+ Object.entries(refs).forEach(([key, refs]) => {
242
+ if (refs.length > 0) {
243
+ const el = document.querySelector(`.${key}`);
244
+ if (!el) return;
245
+ refs.forEach(ref => {
246
+ el.innerHTML = el.innerHTML.replace(
247
+ new RegExp("\\b"+ref+"\\b", "g"),
248
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
249
+ );
250
+ })
251
+ }
252
+ })
253
+ })
254
+ }
255
+
256
+ """)
257
+
258
+ demo.launch()
src/pyproject.toml CHANGED
@@ -8,7 +8,7 @@ build-backend = "hatchling.build"
8
 
9
  [project]
10
  name = "gradio_calendar"
11
- version = "0.0.2"
12
  description = "Gradio component for selecting dates with a calendar πŸ“†"
13
  readme = "README.md"
14
  license = "MIT"
@@ -35,8 +35,12 @@ classifiers = [
35
  [project.optional-dependencies]
36
  dev = ["build", "twine"]
37
 
 
 
 
 
38
  [tool.hatch.build]
39
- artifacts = ["/backend/gradio_calendar/templates", "*.pyi", "backend/gradio_calendar/templates", "backend/gradio_calendar/templates", "backend/gradio_calendar/templates", "backend/gradio_calendar/templates", "backend/gradio_calendar/templates", "backend/gradio_calendar/templates"]
40
 
41
  [tool.hatch.build.targets.wheel]
42
  packages = ["/backend/gradio_calendar"]
 
8
 
9
  [project]
10
  name = "gradio_calendar"
11
+ version = "0.0.3"
12
  description = "Gradio component for selecting dates with a calendar πŸ“†"
13
  readme = "README.md"
14
  license = "MIT"
 
35
  [project.optional-dependencies]
36
  dev = ["build", "twine"]
37
 
38
+ [project.urls]
39
+ repository = "https://github.com/freddyaboulton/gradio-calendar"
40
+ space = "https://huggingface.co/spaces/freddyaboulton/gradio_calendar/settings"
41
+
42
  [tool.hatch.build]
43
+ artifacts = ["/backend/gradio_calendar/templates", "*.pyi", "backend/gradio_calendar/templates", "backend/gradio_calendar/templates", "backend/gradio_calendar/templates", "backend/gradio_calendar/templates", "backend/gradio_calendar/templates", "backend/gradio_calendar/templates", "backend/gradio_calendar/templates", "backend/gradio_calendar/templates"]
44
 
45
  [tool.hatch.build.targets.wheel]
46
  packages = ["/backend/gradio_calendar"]