-
Notifications
You must be signed in to change notification settings - Fork 2
update documentation ( #29 ) #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
abdass
wants to merge
52
commits into
syedabdullahbukhari77:codebase-v2
Choose a base branch
from
abdass:abdass-patch-1
base: codebase-v2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
f1c346d
[training/train.py] [refactor] : standardize tensor conversion with t…
syedabdullahbukhari77 6808e7b
[training/train.py] [refactor] : standardize tensor conversion with t…
syedabdullahbukhari77 ac5779a
[training/train.py] [refactor] : standardize tensor conversion with t…
syedabdullahbukhari77 f236ca4
[training/train.py] [refactor] : wrap script in main() entrypoint for…
syedabdullahbukhari77 1186262
[training/train.py] [refactor] : wrap script in main() entrypoint for…
syedabdullahbukhari77 bd3000f
[training/train.py] [refactor] : finalize script by reverting to orig…
syedabdullahbukhari77 bf79172
Merge pull request #7 from syedabdullahbukhari77/training/dataset.py
syedabdullahbukhari77 7eb6726
[training/train.py] [refactor] : finalize script by reverting to orig…
syedabdullahbukhari77 fbacb5c
Merge pull request #8 from syedabdullahbukhari77/training/dataset.py
syedabdullahbukhari77 f48f61e
[notebook/revenue_forecasting_project_cloud_basedy]
syedabdullahbukhari77 f562412
Merge pull request #9 from syedabdullahbukhari77/main
syedabdullahbukhari77 0027ae6
Merge pull request #10 from syedabdullahbukhari77/prototype-notebook-1
syedabdullahbukhari77 b1d62a9
Merge pull request #11 from syedabdullahbukhari77/main
syedabdullahbukhari77 dd79620
Merge pull request #12 from syedabdullahbukhari77/training/preprocesi…
syedabdullahbukhari77 6b8e818
[training/validate.py] : wrap all validation code single file , furth…
syedabdullahbukhari77 7447339
[training/validate.py] : wrap all validation code single file , furth…
syedabdullahbukhari77 2f32931
Merge pull request #13 from syedabdullahbukhari77/training/validate.py
syedabdullahbukhari77 eaf0b2e
[notebook/revenue_forecasting_project_cloud_basedy]
syedabdullahbukhari77 3d45705
Merge branch 'prototype-notebook-2' of https://github.com/syedabdulla…
syedabdullahbukhari77 f2126c7
Merge pull request #14 from syedabdullahbukhari77/prototype-notebook-2
syedabdullahbukhari77 a3dc7d6
[ inference / predict.py ] (refactor) : [ add docstrings and improve …
syedabdullahbukhari77 88c1a32
[ inference / predict.py ] (refactor) : [ add docstrings and improve …
syedabdullahbukhari77 fe740a5
[ inference / predict.py ] (refactor) : [ add docstrings and improve …
syedabdullahbukhari77 ce829bf
Merge pull request #15 from syedabdullahbukhari77/inference/predict.py
syedabdullahbukhari77 7468a22
[ inference / predict.py ] (refactor) : [ add docstrings and improve …
syedabdullahbukhari77 f1127bf
Merge pull request #16 from syedabdullahbukhari77/inference/predict.py
syedabdullahbukhari77 7b5eb16
[ inference / predict.py ] (refactor) : [ add docstrings and improve …
syedabdullahbukhari77 25cc9f9
feat(app): add Streamlit UI for business forecasting with file upload…
syedabdullahbukhari77 92cd4ae
feat(app): add Streamlit UI for business forecasting with file upload…
syedabdullahbukhari77 b63582c
feat(app): add Streamlit UI for business forecasting with file upload…
syedabdullahbukhari77 7bb6378
feat(app): add Streamlit UI for business forecasting with file upload…
syedabdullahbukhari77 7a35b6c
refactor(app): reorganize artifact loading and model inference into h…
syedabdullahbukhari77 5d84be2
feat(app): add missing column checks and encoder validation for robus…
syedabdullahbukhari77 bef3bda
[ server / app.py ] : enhance output with forecast line chart and chu…
syedabdullahbukhari77 47e0495
[ server / app.py ] : enhance output with forecast line chart and chu…
syedabdullahbukhari77 d4d0bcb
[ server / app.py ] : enhance output with forecast line chart and chu…
syedabdullahbukhari77 f8592e2
[ server / app.py ] : finalize Streamlit app with consistent structur…
syedabdullahbukhari77 0807324
Merge pull request #17 from syedabdullahbukhari77/server/app.py
syedabdullahbukhari77 a27ea53
Merge pull request #18 from syedabdullahbukhari77/main
syedabdullahbukhari77 c28c277
Merge pull request #19 from syedabdullahbukhari77/prototype-notebook-1
syedabdullahbukhari77 1c4a4cb
[training / dataset.py] implement FinanceDataset class for Pytorch tr…
syedabdullahbukhari77 a4f00f7
[training/dataset.py] implement FinanceDataset class for training pip…
syedabdullahbukhari77 85a0f99
(server/app.py) add Streamlit UI for business forecasting(#22) syedab…
syedabdullahbukhari77 b78e2b8
add Streamlit UI for business forecasting ( #23 ) from syedabdullahbu…
syedabdullahbukhari77 e360a92
(README.md) add streamlit deployment documentation
syedabdullahbukhari77 e33446e
(README.md) add streamlit deployment documentation ( #24 )
syedabdullahbukhari77 06c4505
(README.md) add streamlit deployment documentation
syedabdullahbukhari77 d3ca8a5
(README.md) add streamlit deployment documentation
syedabdullahbukhari77 0d9eedc
(README.md) add streamlit deployment documentation ( #26 )
syedabdullahbukhari77 2b9af45
wrap script in main() entrypoint for cleaner execution ( #27 )
syedabdullahbukhari77 dc6870b
wrap script in main() entrypoint for cleaner execution ( #28 )
syedabdullahbukhari77 58cb67e
update documentation ( #29 )
abdass File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import torch | ||
import numpy as np | ||
from models.finance_model import finance_model | ||
|
||
def load_model(path="models/finance_model.pth", input_dim=9, device="cpu"): | ||
model = finance_model(input_dim) | ||
model.load_state_dict(torch.load(path, map_location=device)) | ||
model.eval() | ||
return model | ||
|
||
def predict(model, features: list, device="cpu"): | ||
features = np.array(features).reshape(1, -1) | ||
features_tensor = torch.tensor(features, dtype=torch.float32).to(device) | ||
|
||
with torch.no_grad(): | ||
revenue, risk, churn = model(features_tensor) | ||
|
||
return { | ||
"revenue": revenue.item(), | ||
"risk": risk.item(), | ||
"churn_probability": torch.sigmoid(churn).item() | ||
} |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import streamlit as st | ||
import pandas as pd | ||
import torch | ||
import os, sys | ||
import joblib | ||
|
||
# make sure we can import from parent folder | ||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) | ||
|
||
from models.finance_model import finance_model | ||
|
||
# Fixed feature set (must match training!) | ||
FEATURES = [ | ||
'customer_tenure', 'industry', 'some_other_features', | ||
'company_size', 'region', 'operating_margin', | ||
'debt_ratio', 'log_revenue', 'gross_profit' | ||
] | ||
|
||
@st.cache_resource | ||
def load_artifacts(model_path="models/finance_model.pth", input_dim=9): | ||
model = finance_model(input_dim=input_dim) | ||
model.load_state_dict(torch.load(model_path, map_location="cpu")) | ||
model.eval() | ||
|
||
scaler = joblib.load("models/scaler.pkl") | ||
encoders = joblib.load("models/encoders.pkl") | ||
return model, scaler, encoders | ||
|
||
st.title("📊 Business Forecasting App") | ||
st.write("Predict **Revenue**, **Risk**, and **Churn** from business financial data using PyTorch.") | ||
|
||
# File upload | ||
uploaded_file = st.file_uploader("Upload a CSV file with business features", type=["csv"]) | ||
|
||
if uploaded_file: | ||
df = pd.read_csv(uploaded_file) | ||
st.write("### Uploaded Data (raw)") | ||
st.dataframe(df.head()) | ||
|
||
# --- Column check --- | ||
missing = [col for col in FEATURES if col not in df.columns] | ||
if missing: | ||
st.error(f"❌ Missing required columns: {missing}") | ||
else: | ||
# Drop extra columns automatically | ||
df = df[FEATURES] | ||
|
||
# --- Apply encoders --- | ||
scaler = joblib.load("models/scaler.pkl") | ||
encoders = joblib.load("models/encoders.pkl") | ||
for col in df.select_dtypes(include=['object']).columns: | ||
if col in encoders: | ||
df[col] = encoders[col].transform(df[col]) | ||
else: | ||
st.error(f"No encoder found for column {col}") | ||
st.stop() | ||
|
||
# --- Scale numeric features --- | ||
X = scaler.transform(df) | ||
X_tensor = torch.tensor(X, dtype=torch.float32) | ||
|
||
# --- Load model --- | ||
model, _, _ = load_artifacts(input_dim=len(FEATURES)) | ||
|
||
# --- Run predictions --- | ||
with torch.no_grad(): | ||
revenue, risk, churn = model(X_tensor) | ||
|
||
results = pd.DataFrame({ | ||
"Revenue_Pred": revenue.numpy(), | ||
"Risk_Score": risk.numpy(), | ||
"Churn_Prob": torch.sigmoid(churn).numpy() | ||
}) | ||
|
||
st.write("### Predictions") | ||
st.dataframe(results.head()) | ||
|
||
# Visualization | ||
st.write("### 📈 Forecast Visualization") | ||
st.line_chart(results[["Revenue_Pred"]]) | ||
st.bar_chart(results[["Churn_Prob"]]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# training/train.py | ||
import torch | ||
import torch.nn as nn | ||
import torch.optim as optim | ||
from models.finance_model import finance_model | ||
from training.preprocessing import load_and_preprocess | ||
import joblib | ||
import os | ||
|
||
# 1. Load and preprocess data | ||
X_train, X_val, y_train, y_val, scaler, encoders = load_and_preprocess("synthetic_financial_data_bukharii.csv") | ||
|
||
# 2. Convert to tensors | ||
X_train = torch.tensor(X_train, dtype=torch.float32) | ||
y_train = torch.tensor(y_train, dtype=torch.float32) | ||
X_val = torch.tensor(X_val, dtype=torch.float32) | ||
y_val = torch.tensor(y_val, dtype=torch.float32) | ||
|
||
# 3. Model | ||
model = finance_model(input_dim=X_train.shape[1]) | ||
criterion = nn.MSELoss() # basic loss, you can customize for multitask | ||
optimizer = optim.Adam(model.parameters(), lr=0.001) | ||
|
||
# 4. Train loop (very simple for demo) | ||
for epoch in range(20): # increase epochs as needed | ||
model.train() | ||
optimizer.zero_grad() | ||
revenue, risk, churn = model(X_train) | ||
loss = criterion(revenue, y_train[:,0]) + criterion(risk, y_train[:,1]) + criterion(churn, y_train[:,2]) | ||
loss.backward() | ||
optimizer.step() | ||
|
||
if epoch % 5 == 0: | ||
print(f"Epoch {epoch} - Loss: {loss.item():.4f}") | ||
|
||
# 5. Save artifacts | ||
os.makedirs("models", exist_ok=True) | ||
torch.save(model.state_dict(), "models/finance_model.pth") | ||
joblib.dump(scaler, "models/scaler.pkl") | ||
joblib.dump(encoders, "models/encoders.pkl") | ||
|
||
print("Training complete. Model & preprocessing saved in /models/") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import torch | ||
|
||
def validate(model, loss_fn1, loss_fn2, device, val_loader): | ||
model.eval() | ||
val_loss = 0.0 | ||
|
||
with torch.no_grad(): | ||
for X_batch, y_batch in val_loader: | ||
X_batch, y_batch = X_batch.to(device), y_batch.to(device) | ||
y_rev, y_risk, y_churn = y_batch[:,0], y_batch[:,1], y_batch[:,2] | ||
|
||
pred_rev, pred_risk, pred_churn = model(X_batch) | ||
|
||
loss_rev = loss_fn1(pred_rev, y_rev) | ||
loss_risk = loss_fn1(pred_risk, y_risk) | ||
loss_churn = loss_fn2(pred_churn, y_churn) | ||
|
||
loss = loss_rev + loss_risk + loss_churn | ||
val_loss += loss.item() | ||
|
||
return val_loss / len(val_loader) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems that all content in dataset/synthetic_financial_data_bukharii.csv was accidentally removed in this commit. Could you please restore the file before we merge PR (#29)? Otherwise, it will break the project. @abdass