Skip to content

[Bug]: Express server startup crash, premature return in Flask ML prediction route, and invalid Streamlit model paths #977

Description

@Akshatshukla-25

Bug Description

Three critical runtime issues were identified across the system components:

  1. Express Backend Startup Crash: backend/server.js attempts to mount routes onto app (app.use(...)) before const app = express(); is initialized, resulting in an immediate ReferenceError: app is not defined on launch.
  2. Flask API Pipeline Bypassed: backend/api.py contains a premature return jsonify(...) statement at line 655 inside the predict() function. This renders ~140 lines of downstream logic (language translation, URL scanning, XAI explanation generation, spam severity scoring, and label decoding) unreachable dead code.
  3. Streamlit App Launch Failure: Streamlit/app.py attempts to load model .pkl files from a non-existent models/ subdirectory, causing a FileNotFoundError when launched.

Steps to Reproduce

  1. Server Startup Issue: Run node backend/server.js and observe the immediate unhandled ReferenceError.
  2. Flask Prediction Issue: Run python backend/api.py and send a POST request to /predict with {"text": "Win free lottery tickets now", "type": "message"}. Observe that language translation, URL checking, XAI explanations, and label decoding are completely skipped, returning a raw unencoded integer index instead of a full JSON analysis.
  3. Streamlit Issue: Run streamlit run Streamlit/app.py and observe the app crash with FileNotFoundError.

Expected Behavior

  1. backend/server.js should declare app = express() prior to mounting routes and start listening successfully.
  2. backend/api.py /predict route should execute the entire inference pipeline, returning human-readable labels ("ham", "spam", "smishing"), confidence metrics, and XAI explanation data.
  3. Streamlit/app.py should resolve model paths relative to the repository root and launch the UI without error.

Actual Behavior

  1. backend/server.js throws ReferenceError: app is not defined and terminates the process immediately.
  2. backend/api.py /predict returns premature raw predictions ({"prediction": 1}), bypassing 140+ lines of detection and explainability features.
  3. Streamlit/app.py crashes on launch with FileNotFoundError: [Errno 2] No such file or directory: 'models/linear_svm_model.pkl'.

Screenshots

N/A

Additional Information

  • Environment: macOS / Linux / Docker
  • Runtime: Node.js (v18+), Python (3.9+)
  • Affected Files:
    • backend/server.js
    • backend/api.py
    • Streamlit/app.py

Metadata

Metadata

Labels

SSoC26bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions