Aiomer1 commited on
Commit
e5ffccc
·
verified ·
1 Parent(s): 2c8e92f

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. .amlignore +6 -0
  2. Dockerfile +46 -0
  3. app.py +68 -0
  4. requirements.txt +6 -0
.amlignore ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ ## This file was auto generated by the Azure Machine Learning Studio. Please do not remove.
2
+ ## Read more about the .amlignore file here: https://docs.microsoft.com/azure/machine-learning/how-to-save-write-experiment-files#storage-limits-of-experiment-snapshots
3
+
4
+ .ipynb_aml_checkpoints/
5
+ *.amltmp
6
+ *.amltemp
Dockerfile ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ FROM python:3.9-slim
3
+
4
+ # Set the working directory inside the container.
5
+ # This is where your application will live.
6
+ # Streamlit apps should not run from the root directory.
7
+ WORKDIR /app
8
+
9
+ # The following section installs necessary system packages
10
+ # and uses `apt-get` with the `rm` command to clean up
11
+ # the cache in a single layer, which reduces the final
12
+ # image size.
13
+ RUN apt-get update \
14
+ && apt-get install -y \
15
+ build-essential \
16
+ curl \
17
+ software-properties-common \
18
+ git \
19
+ && rm -rf /var/lib/apt/lists/*
20
+
21
+ # The following two instructions are key for cache efficiency.
22
+ # 1. Copy `requirements.txt` into the container.
23
+ # 2. Install the dependencies.
24
+ # This creates a layer that is only rebuilt when `requirements.txt` changes,
25
+ # which is less frequent than code changes.
26
+ COPY requirements.txt ./
27
+ RUN pip3 install --no-cache-dir -r requirements.txt
28
+
29
+ # Copy all the application files (including app.py) into the container.
30
+ # This layer will be rebuilt every time you change your code.
31
+ COPY . .
32
+
33
+ # Create a non-root user for security. Running a container as a non-root
34
+ # user is a security best practice to prevent potential attacks.
35
+ RUN useradd -m -u 1000 user
36
+ USER user
37
+
38
+ # Expose the port on which the Streamlit app will run.
39
+ EXPOSE 8501
40
+
41
+ # Define a health check for the container.
42
+ HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
43
+
44
+ # Use ENTRYPOINT to set the command that runs when the container starts.
45
+ # We're using the exec form to ensure signals are passed correctly.
46
+ ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import seaborn as sns
3
+ import matplotlib.pyplot as plt
4
+ import pandas as pd
5
+
6
+ # Load data
7
+ def load_data():
8
+ df = pd.read_csv("processed_data.csv") # replace with your dataset
9
+ return df
10
+
11
+ # Create Streamlit app
12
+ def app():
13
+ # Title for the app
14
+ st.title("Pizza Sales Data Analysis Dashboard")
15
+ df = load_data()
16
+
17
+ df = pd.DataFrame(df)
18
+
19
+ # Calculate key metrics
20
+ total_orders = df['order_id'].nunique()
21
+ total_revenue = df['total_price'].sum()
22
+ most_popular_size = df['pizza_size'].value_counts().idxmax()
23
+ most_frequent_category = df['pizza_category'].value_counts().idxmax()
24
+ total_pizzas_sold = df['quantity'].sum()
25
+ repeat_customers = df.groupby('order_id').size().value_counts().get(2, 0)
26
+
27
+ # Sidebar with key metrics
28
+ st.sidebar.header("Key Metrics")
29
+ st.sidebar.metric("Total Orders", total_orders)
30
+ st.sidebar.metric("Total Revenue", f"${total_revenue:,.2f}")
31
+ st.sidebar.metric("Most Popular Size", most_popular_size)
32
+ st.sidebar.metric("Most Popular Category", most_frequent_category)
33
+ st.sidebar.metric("Total Pizzas Sold", total_pizzas_sold)
34
+
35
+ plots = [
36
+ {"title": "Top Selling Pizzas (by Quantity)", "x": "pizza_name", "y": "quantity", "top": 5},
37
+ {"title": "Quantity of Pizzas Sold by Category and Time of the Day", "x": "time_of_day", "hue": "pizza_category"},
38
+ {"title": "Quantity of Pizzas Sold by Size and Time of the Day", "x": "time_of_day", "hue": "pizza_size"},
39
+ {"title": "Monthly Revenue Trends by Pizza Category", "x": "order_month", "y": "total_price", "hue": "pizza_category", "estimator": "sum", "marker": "o"},
40
+ ]
41
+
42
+ for plot in plots:
43
+ st.header(plot["title"])
44
+
45
+ fig, ax = plt.subplots()
46
+
47
+ if "Top Selling Pizzas" in plot["title"]:
48
+ data_aux = df.groupby(plot["x"])[plot["y"]].sum().reset_index().sort_values(by=plot["y"], ascending=False).head(plot["top"])
49
+ ax.bar(data_aux[plot["x"]].values.tolist(), data_aux[plot["y"]].values.tolist())
50
+
51
+ if "Quantity of Pizzas" in plot["title"]:
52
+ sns.countplot(data=df, x=plot["x"], hue=plot["hue"], ax=ax)
53
+
54
+ if "Monthly Revenue" in plot["title"]:
55
+ sns.lineplot(data=df, x=plot["x"], y=plot["y"], hue=plot["hue"], estimator=plot["estimator"], errorbar=None, marker=plot["marker"], ax=ax)
56
+
57
+ ax.set_xlabel(" ".join(plot["x"].split("_")).capitalize())
58
+ if "y" in plot.keys():
59
+ ax.set_ylabel(" ".join(plot["y"].split("_")).capitalize())
60
+ else:
61
+ ax.set_ylabel("Quantity")
62
+ ax.legend(bbox_to_anchor=(1,1))
63
+
64
+ st.pyplot(fig)
65
+
66
+
67
+ if __name__ == "__main__":
68
+ app()
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ pandas==1.5.2
2
+ matplotlib==3.6.2
3
+ seaborn==0.12.1
4
+ scipy==1.10.0
5
+ numpy==1.23.5
6
+ streamlit==1.46.0