Spaces:
Sleeping
Sleeping
Update
Browse files- app.py +49 -2
- requirements.txt +3 -0
- style.css +16 -0
app.py
CHANGED
@@ -1,9 +1,56 @@
|
|
1 |
#!/usr/bin/env python
|
2 |
|
|
|
|
|
3 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
-
with gr.Blocks() as demo:
|
6 |
-
pass
|
7 |
|
8 |
if __name__ == "__main__":
|
9 |
demo.queue().launch()
|
|
|
1 |
#!/usr/bin/env python
|
2 |
|
3 |
+
import datetime
|
4 |
+
|
5 |
import gradio as gr
|
6 |
+
import numpy as np
|
7 |
+
import pandas as pd
|
8 |
+
import plotly.express as px
|
9 |
+
import plotly.graph_objs as go
|
10 |
+
|
11 |
+
from gradio_calendar import Calendar
|
12 |
+
|
13 |
+
DESCRIPTION = """
|
14 |
+
- [GitHub](https://github.com/freddyaboulton/gradio-calendar)
|
15 |
+
- [PyPI](https://pypi.org/project/gradio-calendar/)
|
16 |
+
"""
|
17 |
+
|
18 |
+
np.random.seed(1)
|
19 |
+
data = np.random.normal(size=(500, 5)).cumsum(axis=0)
|
20 |
+
df = pd.DataFrame(data, columns=["A", "B", "C", "D", "E"])
|
21 |
+
df.index = pd.to_datetime(pd.date_range("2024-01-01", periods=500))
|
22 |
+
|
23 |
+
|
24 |
+
def update(start_date: datetime.datetime, end_date: datetime.datetime) -> go.Figure:
|
25 |
+
fig = px.line(df)
|
26 |
+
fig.update_layout(xaxis_range=[start_date, end_date], xaxis_rangeslider_visible=True)
|
27 |
+
return fig
|
28 |
+
|
29 |
+
|
30 |
+
with gr.Blocks(css="style.css") as demo:
|
31 |
+
with gr.Row():
|
32 |
+
start_date = Calendar(
|
33 |
+
label="Start date",
|
34 |
+
type="datetime",
|
35 |
+
value=datetime.datetime(2024, 1, 1),
|
36 |
+
)
|
37 |
+
end_date = Calendar(
|
38 |
+
label="End date",
|
39 |
+
type="datetime",
|
40 |
+
value=datetime.datetime(2024, 3, 31),
|
41 |
+
)
|
42 |
+
plot = gr.Plot()
|
43 |
+
|
44 |
+
gr.on(
|
45 |
+
triggers=[start_date.change, end_date.change],
|
46 |
+
fn=update,
|
47 |
+
inputs=[start_date, end_date],
|
48 |
+
outputs=plot,
|
49 |
+
)
|
50 |
+
demo.load(fn=update, inputs=[start_date, end_date], outputs=plot)
|
51 |
+
|
52 |
+
gr.Markdown(DESCRIPTION)
|
53 |
|
|
|
|
|
54 |
|
55 |
if __name__ == "__main__":
|
56 |
demo.queue().launch()
|
requirements.txt
CHANGED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio==4.13.0
|
2 |
+
gradio_calendar==0.0.2
|
3 |
+
plotly==5.18.0
|
style.css
CHANGED
@@ -9,3 +9,19 @@ h1 {
|
|
9 |
background: #1565c0;
|
10 |
border-radius: 100vh;
|
11 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
background: #1565c0;
|
10 |
border-radius: 100vh;
|
11 |
}
|
12 |
+
|
13 |
+
.js-plotly-plot .plotly {
|
14 |
+
padding-top: 30px !important;
|
15 |
+
background-color: white;
|
16 |
+
}
|
17 |
+
|
18 |
+
.js-plotly-plot .plotly .modebar {
|
19 |
+
top: -30px !important;
|
20 |
+
right: 10px !important;
|
21 |
+
}
|
22 |
+
|
23 |
+
.modebar-group {
|
24 |
+
display: flex;
|
25 |
+
flex-direction: row;
|
26 |
+
align-items: center;
|
27 |
+
}
|