Atomik31 commited on
Commit
d338053
·
1 Parent(s): 676a7e6

Initial commit

Browse files
Files changed (4) hide show
  1. .streamlit/config.toml +6 -0
  2. Dockerfile +37 -0
  3. app.py +163 -0
  4. requirements.txt +50 -0
.streamlit/config.toml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ [browser]
2
+ serverAddress = '0.0.0.0'
3
+
4
+ [theme]
5
+ base="dark"
6
+ primaryColor="#4be8e0"
Dockerfile ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Start with a lightweight Linux Anaconda image
2
+ FROM continuumio/miniconda3:25.3.1-1
3
+
4
+ # Update all packages and install nano unzip and curl
5
+ RUN apt-get update
6
+ RUN apt-get install nano unzip curl -y
7
+
8
+ # THIS IS SPECIFIC TO HUGGINFACE
9
+ # We create a new user named "user" with ID of 1000
10
+ RUN useradd -m -u 1000 user
11
+ # We switch from "root" (default user when creating an image) to "user"
12
+ USER user
13
+ # We set two environmnet variables
14
+ # so that we can give ownership to all files in there afterwards
15
+ # we also add /home/user/.local/bin in the $PATH environment variable
16
+ # PATH environment variable sets paths to look for installed binaries
17
+ # We update it so that Linux knows where to look for binaries if we were to install them with "user".
18
+ ENV HOME=/home/user \
19
+ PATH=/home/user/.local/bin:$PATH
20
+
21
+ # We set working directory to $HOME/app (<=> /home/user/app)
22
+ WORKDIR $HOME/app
23
+
24
+ # Leverage layer caching: copy only reqs first
25
+ COPY requirements.txt requirements.txt
26
+ RUN pip install -r requirements.txt
27
+
28
+ # Copy all local files to /home/user/app with "user" as owner of these files
29
+ # Always use --chown=user when using HUGGINGFACE to avoid permission errors
30
+ COPY --chown=user . $HOME/app
31
+
32
+ # THIS IS SPECIFIC TO HUGGINGFACE AS WELL
33
+ # expose port 7860 which is the port used by HuggingFace for Web Application
34
+ EXPOSE 7860
35
+
36
+ # Run streamlit server
37
+ CMD ["streamlit", "run", "app.py", "--server.port=7860"]
app.py ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import plotly.express as px
4
+ import plotly.graph_objects as go
5
+ import numpy as np
6
+
7
+ ### Config
8
+ st.set_page_config(
9
+ page_title="E-commerce",
10
+ page_icon="💸 ",
11
+ layout="wide"
12
+ )
13
+
14
+ DATA_URL = ('https://full-stack-assets.s3.eu-west-3.amazonaws.com/Deployment/e-commerce_data.csv')
15
+
16
+ ### App
17
+ st.title("Build dashboards with Streamlit 🎨")
18
+
19
+ st.markdown("""
20
+ Welcome to this awesome `streamlit` dashboard. This library is great to build very fast and
21
+ intuitive charts and application running on the web. Here is a showcase of what you can do with
22
+ it. Our data comes from an e-commerce website that simply displays samples of customer sales. Let's check it out.
23
+
24
+ You can download the whole code here 👉 [Source code](https://github.com/JedhaBootcamp/streamlit-demo-app)
25
+
26
+ Also, if you want to have a real quick overview of what streamlit is all about, feel free to watch the below video 👇
27
+ """)
28
+
29
+ with st.expander("⏯️ Watch this 15min tutorial"):
30
+ st.video("https://youtu.be/B2iAodr0fOo")
31
+
32
+ st.markdown("---")
33
+
34
+
35
+ # Use `st.cache` when loading data is extremly useful
36
+ # because it will cache your data so that your app
37
+ # won't have to reload it each time you refresh your app
38
+ @st.cache_data
39
+ def load_data(nrows):
40
+ data = pd.read_csv(DATA_URL, nrows=nrows)
41
+ data["Date"] = data["Date"].apply(lambda x: pd.to_datetime(",".join(x.split(",")[-2:])))
42
+ data["currency"] = data["currency"].apply(lambda x: pd.to_numeric(x[1:]))
43
+ return data
44
+
45
+ st.subheader("Load and showcase data")
46
+ st.markdown("""
47
+
48
+ You can use the usual Data Science libraries like `pandas` or `numpy` to load data.
49
+ Then simply use [`st.write()`](https://docs.streamlit.io/library/api-reference/write-magic/st.write) to showcase it on your web app.
50
+
51
+ """)
52
+
53
+ data_load_state = st.text('Loading data...')
54
+ data = load_data(1000)
55
+ data_load_state.text("") # change text from "Loading data..." to "" once the the load_data function has run
56
+
57
+ ## Run the below code if the check is checked ✅
58
+ if st.checkbox('Show raw data'):
59
+ st.subheader('Raw data')
60
+ st.write(data)
61
+
62
+ ## Simple bar chart
63
+ st.subheader("Simple bar chart built directly with Streamlit")
64
+ st.markdown("""
65
+ You can build simple chart directly with streamlit using:
66
+
67
+ * [`st.bar_chart`](https://docs.streamlit.io/library/api-reference/charts/st.bar_chart)
68
+ * [`st.line_chart`](https://docs.streamlit.io/library/api-reference/charts/st.line_chart)
69
+ * [`st.area_chart`](https://docs.streamlit.io/library/api-reference/charts/st.area_chart)
70
+
71
+ Eventhough it doesn't offer great flexibility, it is still a very simple way to create graphs quickly since
72
+ streamlit since these methods accepts a pandas DataFrame or Numpy array as input.
73
+
74
+ """)
75
+ currency_per_country = data.set_index("country")["currency"]
76
+ st.bar_chart(currency_per_country)
77
+
78
+ ## Bar chart built with plotly
79
+ st.subheader("Simple bar chart built with Plotly")
80
+ st.markdown("""
81
+ Now, the best thing about `streamlit` is its compatibility with other libraries. For example, you
82
+ don't need to actually use built-in charts to create your dashboard, you can use :
83
+
84
+ * [`plotly`](https://docs.streamlit.io/library/api-reference/charts/st.plotly_chart)
85
+ * [`matplotlib`](https://docs.streamlit.io/library/api-reference/charts/st.pyplot)
86
+ * [`bokeh`](https://docs.streamlit.io/library/api-reference/charts/st.bokeh_chart)
87
+ * ...
88
+
89
+ This way, you have all the flexibility you need to build awesome dashboards. 🥰
90
+
91
+ """)
92
+ fig = px.histogram(data.sort_values("country"), x="country", y="currency", barmode="group")
93
+ st.plotly_chart(fig, use_container_width=True)
94
+
95
+
96
+ ### Input data
97
+ st.subheader("Input data")
98
+ st.markdown("""
99
+ As a final note, you can use data that a user will insert when he/she interacts with your app.
100
+ This is called *input data*. To collect these, you can do two things:
101
+ * [Use any of the input widget](https://docs.streamlit.io/library/api-reference/widgets)
102
+ * [Build a form](https://docs.streamlit.io/library/api-reference/control-flow/st.form)
103
+
104
+ Depending on what you need to do, you will prefer one or the other. With a `form`, you actually group
105
+ input widgets together and send the data right away, which can be useful when you need to filter
106
+ by several variables.
107
+
108
+ """)
109
+
110
+ #### Create two columns
111
+ col1, col2 = st.columns(2)
112
+
113
+ with col1:
114
+ st.markdown("**1️⃣ Example of input widget**")
115
+ country = st.selectbox("Select a country you want to see all time sales", data["country"].sort_values().unique())
116
+
117
+ country_sales = data[data["country"]==country]
118
+ fig = px.histogram(country_sales, x="Date", y="currency")
119
+ fig.update_layout(bargap=0.2)
120
+ st.plotly_chart(fig, use_container_width=True)
121
+
122
+ with col2:
123
+ st.markdown("**2️⃣ Example of input form**")
124
+
125
+ with st.form("average_sales_per_country"):
126
+ country = st.selectbox("Select a country you want to see sales", data["country"].sort_values().unique())
127
+ start_period = st.date_input("Select a start date you want to see your metric")
128
+ end_period = st.date_input("Select an end date you want to see your metric")
129
+ submit = st.form_submit_button("submit")
130
+
131
+ if submit:
132
+ avg_period_country_sales = data[(data["country"]==country)]
133
+ start_period, end_period = pd.to_datetime(start_period), pd.to_datetime(end_period)
134
+ mask = (avg_period_country_sales["Date"] > start_period) & (avg_period_country_sales["Date"] < end_period)
135
+ avg_period_country_sales = avg_period_country_sales[mask].mean()
136
+ st.metric("Average sales during selected period (in $)", np.round(avg_period_country_sales, 2))
137
+
138
+
139
+ ### Side bar
140
+ st.sidebar.header("Build dashboards with Streamlit")
141
+ st.sidebar.markdown("""
142
+ * [Load and showcase data](#load-and-showcase-data)
143
+ * [Charts directly built with Streamlit](#simple-bar-chart-built-directly-with-streamlit)
144
+ * [Charts built with Plotly](#simple-bar-chart-built-with-plotly)
145
+ * [Input Data](#input-data)
146
+ """)
147
+ e = st.sidebar.empty()
148
+ e.write("")
149
+ st.sidebar.write("Made with 💖 by [Jedha](https://jedha.co)")
150
+
151
+
152
+
153
+ ### Footer
154
+ empty_space, footer = st.columns([1, 2])
155
+
156
+ with empty_space:
157
+ st.write("")
158
+
159
+ with footer:
160
+ st.markdown("""
161
+ 🍇
162
+ If you want to learn more, check out [streamlit's documentation](https://docs.streamlit.io/) 📖
163
+ """)
requirements.txt ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ altair==5.5.0
2
+ attrs==25.4.0
3
+ blinker==1.9.0
4
+ boto3==1.40.62
5
+ botocore==1.40.62
6
+ cachetools==6.2.1
7
+ click==8.3.0
8
+ contourpy==1.3.3
9
+ cycler==0.12.1
10
+ fonttools==4.60.1
11
+ gitdb==4.0.12
12
+ GitPython==3.1.45
13
+ gunicorn==23.0.0
14
+ Jinja2==3.1.6
15
+ jmespath==1.0.1
16
+ joblib==1.5.2
17
+ jsonpointer==2.1
18
+ jsonschema==4.25.1
19
+ jsonschema-specifications==2025.9.1
20
+ kiwisolver==1.4.9
21
+ MarkupSafe==3.0.3
22
+ matplotlib==3.10.7
23
+ narwhals==2.10.0
24
+ numpy==2.3.4
25
+ pandas==2.3.3
26
+ pillow==12.0.0
27
+ plotly==6.3.1
28
+ protobuf==6.33.0
29
+ pyarrow==21.0.0
30
+ pydeck==0.9.1
31
+ pyparsing==3.2.5
32
+ python-dateutil==2.9.0.post0
33
+ pytz==2025.2
34
+ referencing==0.37.0
35
+ rpds-py==0.28.0
36
+ s3transfer==0.14.0
37
+ scikit-learn==1.7.2
38
+ scipy==1.16.3
39
+ seaborn==0.13.2
40
+ setuptools==78.1.1
41
+ six==1.17.0
42
+ smmap==5.0.2
43
+ streamlit==1.51.0
44
+ tenacity==9.1.2
45
+ threadpoolctl==3.6.0
46
+ toml==0.10.2
47
+ tornado==6.5.2
48
+ tzdata==2025.2
49
+ watchdog==6.0.0
50
+ wheel==0.45.1