Satyam-100 commited on
Commit
eb2894e
·
verified ·
1 Parent(s): b072911

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +11 -11
  2. app.py +68 -0
  3. requirements.txt +5 -3
Dockerfile CHANGED
@@ -1,21 +1,21 @@
 
1
  FROM python:3.9-slim
2
 
 
3
  WORKDIR /app
4
 
5
- RUN apt-get update && apt-get install -y \
6
- build-essential \
7
- curl \
8
- software-properties-common \
9
- git \
10
- && rm -rf /var/lib/apt/lists/*
11
 
12
- COPY requirements.txt ./
13
- COPY src/ ./src/
14
 
 
15
  RUN pip3 install -r requirements.txt
16
 
17
- EXPOSE 8501
18
 
19
- HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
20
 
21
- ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
 
 
 
 
 
1
+ # Use a minimal base image with Python 3.9 installed ##v11
2
  FROM python:3.9-slim
3
 
4
+ # Set the working directory inside the container to /app
5
  WORKDIR /app
6
 
 
 
 
 
 
 
7
 
8
+ # Copy all files from the current directory on the host to the container's /app directory
9
+ COPY . .
10
 
11
+ # Install Python dependencies listed in requirements.txt
12
  RUN pip3 install -r requirements.txt
13
 
 
14
 
 
15
 
16
+ # Define the command to run the Streamlit app on port 8501 and make it accessible externally
17
+ CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
18
+
19
+
20
+
21
+ # NOTE: Disable XSRF protection for easier external access in order to make batch predictions
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 CHANGED
@@ -1,3 +1,5 @@
1
- altair
2
- pandas
3
- streamlit
 
 
 
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