pradelf commited on
Commit
d9ff01d
·
1 Parent(s): f178cd1

fix: update user in Dockerfile and add initial Streamlit app

Browse files
Files changed (2) hide show
  1. Dockerfile +4 -5
  2. src/app.py +116 -0
Dockerfile CHANGED
@@ -2,9 +2,9 @@ FROM python:3.9-slim
2
 
3
 
4
  USER root
5
- RUN useradd -ms /bin/bash jedha
6
  RUN mkdir /app
7
- RUN chown -R jedha /app
8
 
9
  WORKDIR /app
10
 
@@ -18,16 +18,15 @@ RUN apt-get update && apt-get install -y \
18
  COPY requirements.txt ./
19
  RUN pip3 install -r requirements.txt
20
 
21
- USER jedha
22
 
23
  WORKDIR /app
24
 
25
  COPY . .
26
 
27
- RUN git clone https://github.com/pradelf/getaround.git ./app
28
 
29
  EXPOSE 8501
30
 
31
  HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
32
 
33
- ENTRYPOINT ["streamlit", "run", "/app/app/app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
2
 
3
 
4
  USER root
5
+ RUN useradd -ms /bin/bash user
6
  RUN mkdir /app
7
+ RUN chown -R user /app
8
 
9
  WORKDIR /app
10
 
 
18
  COPY requirements.txt ./
19
  RUN pip3 install -r requirements.txt
20
 
21
+ USER user
22
 
23
  WORKDIR /app
24
 
25
  COPY . .
26
 
 
27
 
28
  EXPOSE 8501
29
 
30
  HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
31
 
32
+ ENTRYPOINT ["streamlit", "run", "/app/src/app.py", "--server.port=8501", "--server.address=0.0.0.0"]
src/app.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ### TITLE AND TEXT
15
+ st.title("Build dashboards with Streamlit 🎨")
16
+
17
+ st.markdown("""
18
+ Welcome to this awesome `streamlit` dashboard. This library is great to build very fast and
19
+ intuitive charts and application running on the web. Here is a showcase of what you can do with
20
+ it. Our data comes from an e-commerce website that simply displays samples of customer sales. Let's check it out.
21
+ Also, if you want to have a real quick overview of what streamlit is all about, feel free to watch the below video 👇
22
+ """)
23
+
24
+ ### LOAD DATA
25
+ DATA_PRICING = ('../Data/get_around_pricing_project.csv')
26
+
27
+ DATA_ANALYSIS = ('../Data/get_around_delay_analysis.csv')
28
+
29
+ # this lets the cache activated : usage d'un décorateur python pour ajouter des fonctionnalité
30
+ # : st.cache_data et st.cache_resource qui remplace st.cache qui va devenir obsolète.
31
+ # https://docs.streamlit.io/develop/api-reference/caching-and-state/st.cache_data
32
+ # https://docs.streamlit.io/develop/api-reference/caching-and-state/st.cache_resource
33
+ @st.cache_data
34
+ def load_data(file, nrows, delimiter=","):
35
+ data = pd.read_csv(file, nrows=nrows,delimiter=delimiter)
36
+ #data["Date"] = data["Date"].apply(lambda x: pd.to_datetime(",".join(x.split(",")[-2:])))
37
+ #data["currency"] = data["currency"].apply(lambda x: pd.to_numeric(x[1:]))
38
+ return data
39
+
40
+ data_load_state = st.text('Loading data...')
41
+ data_pricing = load_data(DATA_PRICING,1000)
42
+ data_analysis = load_data(DATA_ANALYSIS,1000)
43
+ data_load_state.text("") # change text from "Loading data..." to "" once the the load_data function has run
44
+
45
+ ## Run the below code if the check is checked ✅
46
+ if st.checkbox('Show raw data'):
47
+ st.subheader('Raw data')
48
+ st.write(data_pricing)
49
+ ### SHOW GRAPH STREAMLIT
50
+
51
+ price_per_model = data_pricing["price"]
52
+ st.bar_chart(price_per_model)
53
+
54
+ ### SHOW GRAPH PLOTLY + STREAMLIT
55
+
56
+ st.subheader("Simple bar chart built with Plotly")
57
+ st.markdown("""
58
+ Now, the best thing about `streamlit` is its compatibility with other libraries. For example, you
59
+ don't need to actually use built-in charts to create your dashboard, you can use :
60
+
61
+ * [`plotly`](https://docs.streamlit.io/library/api-reference/charts/st.plotly_chart)
62
+ * [`matplotlib`](https://docs.streamlit.io/library/api-reference/charts/st.pyplot)
63
+ * [`bokeh`](https://docs.streamlit.io/library/api-reference/charts/st.bokeh_chart)
64
+ * ...
65
+ This way, you have all the flexibility you need to build awesome dashboards. 🥰
66
+ """)
67
+ fig = px.histogram(data.sort_values("country"), x="country", y="currency", barmode="group")
68
+ st.plotly_chart(fig, use_container_width=True)
69
+
70
+
71
+ ### SIDEBAR
72
+ st.sidebar.header("Build dashboards with Streamlit")
73
+ st.sidebar.markdown("""
74
+ * [Load and showcase data](#load-and-showcase-data)
75
+ * [Charts directly built with Streamlit](#simple-bar-chart-built-directly-with-streamlit)
76
+ * [Charts built with Plotly](#simple-bar-chart-built-with-plotly)
77
+ * [Input Data](#input-data)
78
+ """)
79
+ e = st.sidebar.empty()
80
+ e.write("")
81
+ st.sidebar.write("GetAround Project")
82
+
83
+ ### EXPANDER
84
+
85
+ with st.expander("⏯️ Watch this 15min tutorial"):
86
+ st.video("https://youtu.be/B2iAodr0fOo")
87
+
88
+ st.markdown("---")
89
+
90
+ #### CREATE TWO COLUMNS
91
+ col1, col2 = st.columns(2)
92
+
93
+ with col1:
94
+ # visu des widgets
95
+ st.markdown("First column")
96
+ car_id= st.selectbox("Select a country you want to see all time sales", data_analysis["car_id"].sort_values().unique())
97
+ # intelligence et contrôle du widget
98
+ rental_canceled = data_analysis[data_analysis["state"]=="canceled"]
99
+ fig = px.histogram(rental_canceled, x="time_delta_with_previous_rental_in_minutes", y="delay_at_checkout_in_minutes")
100
+ fig.update_layout(bargap=0.2)
101
+ st.plotly_chart(fig, use_container_width=True)
102
+
103
+ with col2:
104
+ st.markdown("Second column")
105
+ with st.form("average_sales_per_country"):
106
+ model = st.selectbox("Select a model you want to see", data_pricing["model_key"].sort_values().unique())
107
+ power = st.selectbox("Select a start date you want to see your metric",data_pricing["engine_power"].sort_values().unique())
108
+ submit = st.form_submit_button("submit")
109
+ if submit:
110
+ model_select = data_pricing[data_pricing["model_key"]==model]
111
+ power_select = data_pricing[data_pricing["power"]==power]
112
+ avg_rental_price = data_pricing[model_select & power_select ]["rental_price_per_day"].mean()
113
+ st.metric("Average rental price (in $)", np.round(avg_rental_price, 2))
114
+
115
+
116
+