yuanjie commited on
Commit
34d7a98
β€’
1 Parent(s): 83a476f
__init__.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2018-2022 Streamlit Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2018-2022 Streamlit Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import streamlit as st
16
+ from streamlit.logger import get_logger
17
+
18
+ LOGGER = get_logger(__name__)
19
+
20
+
21
+ def run():
22
+ st.set_page_config(
23
+ page_title="Hello",
24
+ page_icon="πŸ‘‹",
25
+ )
26
+
27
+ st.write("# Welcome to Streamlit! πŸ‘‹")
28
+
29
+ st.sidebar.success("Select a demo above.")
30
+
31
+ st.markdown(
32
+ """
33
+ Streamlit is an open-source app framework built specifically for
34
+ Machine Learning and Data Science projects.
35
+ **πŸ‘ˆ Select a demo from the sidebar** to see some examples
36
+ of what Streamlit can do!
37
+ ### Want to learn more?
38
+ - Check out [streamlit.io](https://streamlit.io)
39
+ - Jump into our [documentation](https://docs.streamlit.io)
40
+ - Ask a question in our [community
41
+ forums](https://discuss.streamlit.io)
42
+ ### See more complex demos
43
+ - Use a neural net to [analyze the Udacity Self-driving Car Image
44
+ Dataset](https://github.com/streamlit/demo-self-driving)
45
+ - Explore a [New York City rideshare dataset](https://github.com/streamlit/demo-uber-nyc-pickups)
46
+ """
47
+ )
48
+
49
+
50
+ if __name__ == "__main__":
51
+ run()
packages.txt ADDED
File without changes
pages/0__ο£ΏDemo.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from streamlit.hello.utils import show_code
3
+ import inspect
4
+ import textwrap
5
+
6
+
7
+ class Page(object):
8
+
9
+ def __init__(self, app_title="# App Title",
10
+ app_info="> App Info",
11
+ sidebar_title="## Sidebar Title",
12
+ page_title="Page Title",
13
+ page_icon='πŸ”₯',
14
+ menu_items=None,
15
+ show_code=False
16
+ ):
17
+ st.set_page_config(
18
+ page_title=page_title,
19
+ page_icon=page_icon,
20
+ initial_sidebar_state='auto',
21
+ menu_items=menu_items
22
+ )
23
+
24
+ if app_title: st.markdown(app_title)
25
+ if app_info: st.markdown(app_info)
26
+ if sidebar_title: st.sidebar.markdown(sidebar_title)
27
+
28
+ if sidebar_title and show_code: self.show_code(self.main)
29
+
30
+ def main(self):
31
+ raise NotImplementedError('Method not implemented!')
32
+
33
+ def show_code(self, demo):
34
+ """Showing the code of the demo."""
35
+ _ = st.sidebar.checkbox("Show code", False)
36
+ if _:
37
+ # Showing the code of the demo.
38
+ st.markdown("---")
39
+ st.markdown("## Main Code")
40
+ sourcelines, _ = inspect.getsourcelines(demo)
41
+ st.code(textwrap.dedent("".join(sourcelines[1:])))
42
+ st.markdown("---")
43
+
44
+
45
+
46
+ class SPage(Page):
47
+
48
+ def main(self):
49
+ st.markdown("θΏ™ζ˜―δΈͺ`main`函数")
50
+
51
+
52
+ SPage(sidebar_title='').main()
pages/0_πŸ“Ή_Animation_Demo.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2018-2022 Streamlit Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import streamlit as st
16
+ import inspect
17
+ import textwrap
18
+ import numpy as np
19
+ from typing import Any
20
+ from streamlit.hello.utils import show_code
21
+
22
+
23
+ def animation_demo():
24
+
25
+ # Interactive Streamlit elements, like these sliders, return their value.
26
+ # This gives you an extremely simple interaction model.
27
+ iterations = st.sidebar.slider("Level of detail", 2, 20, 10, 1)
28
+ separation = st.sidebar.slider("Separation", 0.7, 2.0, 0.7885)
29
+
30
+ # Non-interactive elements return a placeholder to their location
31
+ # in the app. Here we're storing progress_bar to update it later.
32
+ progress_bar = st.sidebar.progress(0)
33
+
34
+ # These two elements will be filled in later, so we create a placeholder
35
+ # for them using st.empty()
36
+ frame_text = st.sidebar.empty()
37
+ image = st.empty()
38
+
39
+ m, n, s = 960, 640, 400
40
+ x = np.linspace(-m / s, m / s, num=m).reshape((1, m))
41
+ y = np.linspace(-n / s, n / s, num=n).reshape((n, 1))
42
+
43
+ for frame_num, a in enumerate(np.linspace(0.0, 4 * np.pi, 100)):
44
+ # Here were setting value for these two elements.
45
+ progress_bar.progress(frame_num)
46
+ frame_text.text("Frame %i/100" % (frame_num + 1))
47
+
48
+ # Performing some fractal wizardry.
49
+ c = separation * np.exp(1j * a)
50
+ Z = np.tile(x, (n, 1)) + 1j * np.tile(y, (1, m))
51
+ C = np.full((n, m), c)
52
+ M: Any = np.full((n, m), True, dtype=bool)
53
+ N = np.zeros((n, m))
54
+
55
+ for i in range(iterations):
56
+ Z[M] = Z[M] * Z[M] + C[M]
57
+ M[np.abs(Z) > 2] = False
58
+ N[M] = i
59
+
60
+ # Update the image placeholder by calling the image() function on it.
61
+ image.image(1.0 - (N / N.max()), use_column_width=True)
62
+
63
+ # We clear elements by calling empty on them.
64
+ progress_bar.empty()
65
+ frame_text.empty()
66
+
67
+ # Streamlit widgets automatically run the script from top to bottom. Since
68
+ # this button is not connected to any other logic, it just causes a plain
69
+ # rerun.
70
+ st.button("Re-run")
71
+
72
+
73
+ st.set_page_config(page_title="Animation Demo", page_icon="πŸ“Ή")
74
+ st.markdown("# Animation Demo")
75
+ st.sidebar.header("Animation Demo")
76
+ st.write(
77
+ """This app shows how you can use Streamlit to build cool animations.
78
+ It displays an animated fractal based on the the Julia Set. Use the slider
79
+ to tune different parameters."""
80
+ )
81
+
82
+ animation_demo()
83
+
84
+ show_code(animation_demo)
pages/1_πŸ“ˆ_Plotting_Demo.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2018-2022 Streamlit Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import streamlit as st
16
+ import inspect
17
+ import textwrap
18
+ import time
19
+ import numpy as np
20
+ from streamlit.hello.utils import show_code
21
+
22
+
23
+ def plotting_demo():
24
+ progress_bar = st.sidebar.progress(0)
25
+ status_text = st.sidebar.empty()
26
+ last_rows = np.random.randn(1, 1)
27
+ chart = st.line_chart(last_rows)
28
+
29
+ for i in range(1, 101):
30
+ new_rows = last_rows[-1, :] + np.random.randn(5, 1).cumsum(axis=0)
31
+ status_text.text("%i%% Complete" % i)
32
+ chart.add_rows(new_rows)
33
+ progress_bar.progress(i)
34
+ last_rows = new_rows
35
+ time.sleep(0.05)
36
+
37
+ progress_bar.empty()
38
+
39
+ # Streamlit widgets automatically run the script from top to bottom. Since
40
+ # this button is not connected to any other logic, it just causes a plain
41
+ # rerun.
42
+ st.button("Re-run")
43
+
44
+
45
+ st.set_page_config(page_title="Plotting Demo", page_icon="πŸ“ˆ")
46
+ st.markdown("# Plotting Demo")
47
+ st.sidebar.header("Plotting Demo")
48
+ st.write(
49
+ """This demo illustrates a combination of plotting and animation with
50
+ Streamlit. We're generating a bunch of random numbers in a loop for around
51
+ 5 seconds. Enjoy!"""
52
+ )
53
+
54
+ plotting_demo()
55
+
56
+ show_code(plotting_demo)
pages/2_🌍_Mapping_Demo.py ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2018-2022 Streamlit Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import streamlit as st
16
+ import inspect
17
+ import textwrap
18
+ import pandas as pd
19
+ import pydeck as pdk
20
+ from streamlit.hello.utils import show_code
21
+
22
+
23
+ from urllib.error import URLError
24
+
25
+
26
+ def mapping_demo():
27
+ @st.cache
28
+ def from_data_file(filename):
29
+ url = (
30
+ "http://raw.githubusercontent.com/streamlit/"
31
+ "example-data/master/hello/v1/%s" % filename
32
+ )
33
+ return pd.read_json(url)
34
+
35
+ try:
36
+ ALL_LAYERS = {
37
+ "Bike Rentals": pdk.Layer(
38
+ "HexagonLayer",
39
+ data=from_data_file("bike_rental_stats.json"),
40
+ get_position=["lon", "lat"],
41
+ radius=200,
42
+ elevation_scale=4,
43
+ elevation_range=[0, 1000],
44
+ extruded=True,
45
+ ),
46
+ "Bart Stop Exits": pdk.Layer(
47
+ "ScatterplotLayer",
48
+ data=from_data_file("bart_stop_stats.json"),
49
+ get_position=["lon", "lat"],
50
+ get_color=[200, 30, 0, 160],
51
+ get_radius="[exits]",
52
+ radius_scale=0.05,
53
+ ),
54
+ "Bart Stop Names": pdk.Layer(
55
+ "TextLayer",
56
+ data=from_data_file("bart_stop_stats.json"),
57
+ get_position=["lon", "lat"],
58
+ get_text="name",
59
+ get_color=[0, 0, 0, 200],
60
+ get_size=15,
61
+ get_alignment_baseline="'bottom'",
62
+ ),
63
+ "Outbound Flow": pdk.Layer(
64
+ "ArcLayer",
65
+ data=from_data_file("bart_path_stats.json"),
66
+ get_source_position=["lon", "lat"],
67
+ get_target_position=["lon2", "lat2"],
68
+ get_source_color=[200, 30, 0, 160],
69
+ get_target_color=[200, 30, 0, 160],
70
+ auto_highlight=True,
71
+ width_scale=0.0001,
72
+ get_width="outbound",
73
+ width_min_pixels=3,
74
+ width_max_pixels=30,
75
+ ),
76
+ }
77
+ st.sidebar.markdown("### Map Layers")
78
+ selected_layers = [
79
+ layer
80
+ for layer_name, layer in ALL_LAYERS.items()
81
+ if st.sidebar.checkbox(layer_name, True)
82
+ ]
83
+ if selected_layers:
84
+ st.pydeck_chart(
85
+ pdk.Deck(
86
+ map_style="mapbox://styles/mapbox/light-v9",
87
+ initial_view_state={
88
+ "latitude": 37.76,
89
+ "longitude": -122.4,
90
+ "zoom": 11,
91
+ "pitch": 50,
92
+ },
93
+ layers=selected_layers,
94
+ )
95
+ )
96
+ else:
97
+ st.error("Please choose at least one layer above.")
98
+ except URLError as e:
99
+ st.error(
100
+ """
101
+ **This demo requires internet access.**
102
+ Connection error: %s
103
+ """
104
+ % e.reason
105
+ )
106
+
107
+
108
+ st.set_page_config(page_title="Mapping Demo", page_icon="🌍")
109
+ st.markdown("# Mapping Demo")
110
+ st.sidebar.header("Mapping Demo")
111
+ st.write(
112
+ """This demo shows how to use
113
+ [`st.pydeck_chart`](https://docs.streamlit.io/library/api-reference/charts/st.pydeck_chart)
114
+ to display geospatial data."""
115
+ )
116
+
117
+ mapping_demo()
118
+
119
+ show_code(mapping_demo)
pages/3_πŸ“Š_DataFrame_Demo.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2018-2022 Streamlit Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import streamlit as st
16
+ import inspect
17
+ import textwrap
18
+ import pandas as pd
19
+ import altair as alt
20
+ from streamlit.hello.utils import show_code
21
+
22
+ from urllib.error import URLError
23
+
24
+
25
+ def data_frame_demo():
26
+ @st.cache
27
+ def get_UN_data():
28
+ AWS_BUCKET_URL = "http://streamlit-demo-data.s3-us-west-2.amazonaws.com"
29
+ df = pd.read_csv(AWS_BUCKET_URL + "/agri.csv.gz")
30
+ return df.set_index("Region")
31
+
32
+ try:
33
+ df = get_UN_data()
34
+ countries = st.multiselect(
35
+ "Choose countries", list(df.index), ["China", "United States of America"]
36
+ )
37
+ if not countries:
38
+ st.error("Please select at least one country.")
39
+ else:
40
+ data = df.loc[countries]
41
+ data /= 1000000.0
42
+ st.write("### Gross Agricultural Production ($B)", data.sort_index())
43
+
44
+ data = data.T.reset_index()
45
+ data = pd.melt(data, id_vars=["index"]).rename(
46
+ columns={"index": "year", "value": "Gross Agricultural Product ($B)"}
47
+ )
48
+ chart = (
49
+ alt.Chart(data)
50
+ .mark_area(opacity=0.3)
51
+ .encode(
52
+ x="year:T",
53
+ y=alt.Y("Gross Agricultural Product ($B):Q", stack=None),
54
+ color="Region:N",
55
+ )
56
+ )
57
+ st.altair_chart(chart, use_container_width=True)
58
+ except URLError as e:
59
+ st.error(
60
+ """
61
+ **This demo requires internet access.**
62
+ Connection error: %s
63
+ """
64
+ % e.reason
65
+ )
66
+
67
+
68
+ st.set_page_config(page_title="DataFrame Demo", page_icon="πŸ“Š")
69
+ st.markdown("# DataFrame Demo")
70
+ st.sidebar.header("DataFrame Demo")
71
+ st.write(
72
+ """This demo shows how to use `st.write` to visualize Pandas DataFrames.
73
+ (Data courtesy of the [UN Data Explorer](http://data.un.org/Explorer.aspx).)"""
74
+ )
75
+
76
+ data_frame_demo()
77
+
78
+ show_code(data_frame_demo)
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ meutils
run.sh ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # @Project : nesc
3
+ # @Time : 2022/9/21 δΈ‹εˆ5:20
4
+ # @Author : yuanjie
5
+ # @Email : 313303303@qq.com
6
+ # @Software : PyCharm
7
+ # @Description : ${DESCRIPTION}
8
+
9
+ #streamlit run mapps.py
10
+ #streamlit-launchpad ./examples
11
+ streamlit run app.py
12
+