muddasser commited on
Commit
4583e07
·
verified ·
1 Parent(s): 5fac083

Upload 4 files

Browse files
Files changed (4) hide show
  1. Dockerfile +24 -0
  2. main.py +56 -0
  3. prophet_model.pkl +3 -0
  4. requirements.txt +4 -0
Dockerfile ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ WORKDIR /app
4
+
5
+ # Install system dependencies
6
+ RUN apt-get update && apt-get install -y --no-install-recommends \
7
+ build-essential \
8
+ python3-dev \
9
+ libatlas-base-dev \
10
+ && rm -rf /var/lib/apt/lists/*
11
+
12
+ # Copy files
13
+ COPY requirements.txt .
14
+ COPY main.py .
15
+ COPY prophet_model.pkl .
16
+
17
+ # Install Python dependencies
18
+ RUN pip install --no-cache-dir -r requirements.txt
19
+
20
+ # Expose Streamlit port
21
+ EXPOSE 7860
22
+
23
+ # Run Streamlit app
24
+ CMD ["streamlit", "run", "main.py", "--server.port=7860", "--server.address=0.0.0.0"]
main.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import pickle
4
+ import matplotlib.pyplot as plt
5
+
6
+ # --------------------
7
+ # LOAD TRAINED MODEL
8
+ # --------------------
9
+ MODEL_PATH = "prophet_model.pkl" # updated to match your file
10
+
11
+ try:
12
+ with open(MODEL_PATH, "rb") as f:
13
+ model = pickle.load(f)
14
+ st.success("✅ Loaded saved Prophet model.")
15
+ except FileNotFoundError:
16
+ model = None
17
+ st.warning("⚠ No saved model found. You can still upload CSV for chart display.")
18
+
19
+ # --------------------
20
+ # UPLOAD CSV FILE
21
+ # --------------------
22
+ st.title("📊 Prophet Forecast Viewer")
23
+ uploaded_file = st.file_uploader("Upload your CSV file", type=["csv"])
24
+
25
+ if uploaded_file is not None:
26
+ df = pd.read_csv(uploaded_file)
27
+
28
+ st.subheader("Data Preview")
29
+ st.write(df.head())
30
+
31
+ # Prepare data for Prophet if model exists
32
+ if model is not None:
33
+ try:
34
+ # Ensure Prophet format
35
+ df = df.rename(columns={df.columns[0]: 'ds'})
36
+ df['ds'] = pd.to_datetime(df['ds'])
37
+
38
+ predictions = model.predict(df)
39
+ st.subheader("Predictions")
40
+ st.write(predictions[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].head())
41
+
42
+ # Plot
43
+ fig, ax = plt.subplots(figsize=(10, 5))
44
+ ax.plot(df['ds'], predictions['yhat'], label="Forecast", color="blue")
45
+ ax.fill_between(df['ds'], predictions['yhat_lower'], predictions['yhat_upper'], alpha=0.2)
46
+ ax.set_title("Forecast Chart")
47
+ ax.set_xlabel("Date")
48
+ ax.set_ylabel("Value")
49
+ ax.legend()
50
+ st.pyplot(fig)
51
+
52
+ except Exception as e:
53
+ st.error(f"Prediction failed: {e}")
54
+
55
+ else:
56
+ st.info("📂 Please upload a CSV file to begin.")
prophet_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a788c260920ff23dd0bdd6210821347459e758e4d99b51dc59b1f663951e01a2
3
+ size 100954
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ matplotlib
4
+ prophet