Skip to content

Fix deployment: create missing Flask app, save preprocessor, improve KMeans efficiency#2

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/identify-improve-slow-code
Draft

Fix deployment: create missing Flask app, save preprocessor, improve KMeans efficiency#2
Copilot wants to merge 2 commits intomainfrom
copilot/identify-improve-slow-code

Conversation

Copy link
Copy Markdown

Copilot AI commented Feb 28, 2026

The app could not be deployed because app/main.py didn't exist, the app/ directory was tracked as a broken git submodule, the fitted preprocessor was never persisted (making inference impossible), and KMeans lacked an explicit n_init causing sklearn deprecation warnings.

Changes

  • app/main.py (new): Flask app with GET / health-check and POST /predict (CSV upload → segment labels). Model and preprocessor loaded lazily on first request.
  • app/__init__.py / src/__init__.py (new): Package init files so imports resolve correctly.
  • generate_model.py: Capture and persist the fitted preprocessor to models/preprocessor.pkl — was previously discarded (X, _ = ...), making it impossible to transform new data consistently at inference time.
  • src/clustering.py: Add n_init=10 explicitly to KMeans to silence sklearn FutureWarning and lock in consistent behavior.
  • run_app.sh: Replace export FLASK_APP=... && flask run with python app/main.py.
  • Git: Removed broken submodule entry for app/ (no .gitmodules existed); re-added as regular tracked files.
# POST /predict — upload CSV, get back segment labels
# app/main.py
@app.route("/predict", methods=["POST"])
def predict():
    df = pd.read_csv(io.StringIO(file.stream.read().decode("utf-8")))
    _load_artifacts()                          # lazy-loads model + preprocessor
    df = engineer_features(df)
    X = _preprocessor.transform(df)           # uses saved preprocessor
    labels = _model.predict(X)
    return jsonify({"segments": labels.tolist()})

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…mprove KMeans efficiency

Co-authored-by: Sasisundar2211 <139478565+Sasisundar2211@users.noreply.github.com>
Copilot AI changed the title [WIP] Identify and improve slow or inefficient code Fix deployment: create missing Flask app, save preprocessor, improve KMeans efficiency Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants