Skip to content

Fix hardcoded file paths causing "Features data file not found" errors - #4

Open
SupravoCoder with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-eaa0e052-3564-4029-bd83-374522cc7398
Open

Fix hardcoded file paths causing "Features data file not found" errors#4
SupravoCoder with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-eaa0e052-3564-4029-bd83-374522cc7398

Conversation

Copilot AI commented Jul 12, 2025

Copy link
Copy Markdown
Contributor

Problem

The Bhukamp earthquake prediction applications were failing with "Features data file not found" errors due to hardcoded Windows-specific file paths that don't work on other systems or deployment environments.

Issues Fixed:

  1. Hardcoded Windows paths in both Predictor_Earthquake.py and Susceptibility Predictor.py
  2. Incorrect path structure - MODELS_DIR was pointing to a CSV file instead of a directory
  3. Missing directory structure - Required model files were not in the expected location

Changes Made

1. Fixed Predictor_Earthquake.py

Before:

MODELS_DIR = r"C:\Users\Supravo Biswas\Desktop\Coding\Python Coding\StreamlitPython\Susceptability_pred_ML\Susceptability_pred_ML\models\EarthquakeFeatures.csv"

After:

MODELS_DIR = os.path.join(os.path.dirname(__file__), "..", "models")
LABELED_DATA_PATH = os.path.join(MODELS_DIR, "earthquakes_labeled.csv")
FEATURES_DATA_PATH = os.path.join(MODELS_DIR, "EarthquakeFeatures.csv")

2. Fixed Susceptibility Predictor.py

Before:

model_path = os.path.join(MODELS_DIR, "C:\\Users\\Supravo Biswas\\Desktop\\...")

After:

model_path = os.path.join(MODELS_DIR, "EarthquakePredictor.pkl")

3. Created Proper Directory Structure

myproject/
├── models/
│   ├── EarthquakeFeatures.csv
│   ├── EarthquakePredictor.pkl
│   ├── fault_density_scaler.pkl
│   ├── hubdist_scaler.pkl
│   ├── mag_scaler.pkl
│   ├── earthquakes_labeled.csv
│   └── README.md
├── pages/
│   ├── Predictor_Earthquake.py
│   └── Susceptibility Predictor.py

4. Enhanced Error Handling

  • Added comprehensive file existence checks
  • Improved error messages with clear file location information
  • Added instructions for users when files are missing

Testing

✅ Both applications now start without path errors
✅ Model loading and prediction functionality verified
✅ Cross-platform compatibility confirmed
✅ All required files properly located and accessible

Benefits

  • Cross-platform compatibility: Works on Windows, macOS, and Linux
  • Portable deployment: No environment-specific paths
  • Better user experience: Clear error messages when files are missing
  • Maintainable: Proper directory structure with documentation

This fixes the core issue preventing the earthquake prediction applications from running in different environments.

This pull request was created as a result of the following prompt from Copilot chat.

Fix file path issues in Predictor_Earthquake.py and Susceptibility Predictor.py pages that are causing "Features data file not found" errors.

Issues to Fix:

1. Hardcoded Local Paths

Both files contain hardcoded Windows-specific paths that won't work on other systems:

  • MODELS_DIR = r"C:\Users\Supravo Biswas\Desktop\Coding\Python Coding\StreamlitPython\Susceptability_pred_ML\Susceptability_pred_ML\models\EarthquakeFeatures.csv"
  • Multiple absolute paths in the load_resources() function

2. Incorrect Path Structure

The MODELS_DIR path incorrectly ends with EarthquakeFeatures.csv instead of being a directory path.

3. Missing Directory Structure

The repository needs a proper models directory structure for the data files.

Expected Fixes:

1. Fix Predictor_Earthquake.py

  • Change hardcoded paths to relative paths using os.path.join()
  • Fix the MODELS_DIR to point to a directory, not a file
  • Use os.path.dirname(__file__) to get the current file's directory
  • Create fallback mechanisms for missing files

2. Fix Susceptibility Predictor.py

  • Replace all hardcoded absolute paths with relative paths
  • Update the load_resources() function to use proper relative paths
  • Add better error handling for missing files

3. Create Directory Structure

  • Create myproject/models/ directory
  • Add placeholder files or documentation for required data files

4. Expected Directory Structure:

myproject/
├── models/
│   ├── EarthquakeFeatures.csv (data file)
│   ├── EarthquakePredictor.pkl (model file)
│   ├── fault_density_scaler.pkl (scaler file)
│   ├── hubdist_scaler.pkl (scaler file)
│   └── mag_scaler.pkl (scaler file)
├── pages/
│   ├── Predictor_Earthquake.py
│   └── Susceptibility Predictor.py

5. Path Fixes Example:

# Current problematic code:
MODELS_DIR = r"C:\Users\Supravo Biswas\Desktop\..."

# Should be:
MODELS_DIR = os.path.join(os.path.dirname(__file__), "..", "models")
FEATURES_DATA_PATH = os.path.join(MODELS_DIR, "EarthquakeFeatures.csv")

6. Error Handling

  • Add proper file existence checks
  • Provide clear error messages when files are missing
  • Add instructions for users on how to add missing data files

Files to Fix:

  • myproject/pages/Predictor_Earthquake.py - Fix hardcoded paths and directory structure
  • myproject/pages/Susceptibility Predictor.py - Fix hardcoded paths in load_resources() function
  • Create myproject/models/ directory with appropriate README or placeholder files

This will make the application portable and fix the "Features data file not found" errors.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.

Repository owner deleted a comment from netlify Bot Jul 12, 2025
Copilot AI and others added 2 commits July 12, 2025 18:49
Co-authored-by: SupravoCoder <147735025+SupravoCoder@users.noreply.github.com>
Co-authored-by: SupravoCoder <147735025+SupravoCoder@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix hardcoded file paths in Predictor_Earthquake and Susceptibility Predictor pages Fix hardcoded file paths causing "Features data file not found" errors Jul 12, 2025
Copilot AI requested a review from SupravoCoder July 12, 2025 18:50
@SupravoCoder
SupravoCoder marked this pull request as ready for review July 13, 2025 09:02
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.

3 participants