basaktamer commited on
Commit
bebaa00
·
verified ·
1 Parent(s): 361958c

Upload 3 files

Browse files
Files changed (4) hide show
  1. .gitattributes +1 -0
  2. app.py +74 -0
  3. forecasting-sticker-sales.ipynb +0 -0
  4. model.ubj +3 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ model.ubj filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import xgboost as xgb
4
+ import os
5
+ import pickle
6
+
7
+ # Set page configuration
8
+ st.set_page_config(page_title="Podcast Prediction", layout="centered")
9
+
10
+ # --- 1. LOAD ASSETS ---
11
+ @st.cache_resource
12
+ def load_assets():
13
+ current_dir = os.path.dirname(os.path.abspath(__file__))
14
+ model_path = os.path.join(current_dir, 'model.ubj')
15
+ columns_path = os.path.join(current_dir, 'model_columns.pkl')
16
+
17
+ # Load XGBoost model
18
+ model = xgb.XGBRegressor()
19
+ model.load_model(model_path)
20
+
21
+ # Load the column names list
22
+ with open(columns_path, 'rb') as f:
23
+ model_columns = pickle.load(f)
24
+
25
+ return model, model_columns
26
+
27
+ try:
28
+ model, model_columns = load_assets()
29
+ st.success("Model and Column definitions loaded!")
30
+ except Exception as e:
31
+ st.error(f"Error loading assets: {e}")
32
+ st.stop()
33
+
34
+ # --- 2. UI INPUTS ---
35
+ st.title("🎙️ Podcast Listening Time Predictor")
36
+
37
+ with st.form("input_form"):
38
+ col1, col2 = st.columns(2)
39
+ with col1:
40
+ category = st.selectbox("Category", ["Technology", "True Crime", "Comedy", "Health", "Business"])
41
+ episode_length = st.number_input("Length (Mins)", value=30)
42
+ with col2:
43
+ day_of_week = st.selectbox("Day", ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"])
44
+ user_history = st.number_input("User History (Mins)", value=100)
45
+
46
+ submit = st.form_submit_button("Predict")
47
+
48
+ # --- 3. PREDICTION & ALIGNMENT ---
49
+ if submit:
50
+ # 1. Create initial DataFrame
51
+ input_df = pd.DataFrame({
52
+ 'episode_length': [episode_length],
53
+ 'user_history': [user_history],
54
+ 'category': [category],
55
+ 'day_of_week': [day_of_week]
56
+ })
57
+
58
+ # 2. Dummy Encoding (Match the logic used in training)
59
+ input_df = pd.get_dummies(input_df)
60
+
61
+ # 3. ALIGNMENT: The "Magic" step to prevent errors or stuck predictions
62
+ # Add missing columns (that exist in model_columns but not in current input)
63
+ for col in model_columns:
64
+ if col not in input_df.columns:
65
+ input_df[col] = 0
66
+
67
+ # Reorder columns to match the training order exactly
68
+ input_df = input_df[model_columns]
69
+
70
+ # 4. Final Prediction
71
+ prediction = model.predict(input_df)
72
+
73
+ st.divider()
74
+ st.subheader(f"Prediction: {prediction[0]:.2f} Minutes")
forecasting-sticker-sales.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
model.ubj ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:71de975ce86fba817157eada679132026bb6eb6bdd0ada6e86b7371f472a2c94
3
+ size 4967249