MHamzaShahid commited on
Commit
56e5176
·
verified ·
1 Parent(s): 0443708

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -5
app.py CHANGED
@@ -4,12 +4,25 @@ import joblib
4
  import numpy as np
5
 
6
  # Load the trained model
7
- try:
8
- model = joblib.load("district_yield_pipeline.pkl")
9
- model_loaded = True
10
- except:
 
 
 
 
 
 
 
 
 
 
 
 
11
  model_loaded = False
12
- print("Warning: Model file not found. Please ensure 'district_yield_pipeline.pkl' is in the same directory.")
 
13
 
14
  # Define the lists for dropdowns (based on your dataset)
15
  CROPS = [
 
4
  import numpy as np
5
 
6
  # Load the trained model
7
+ import os
8
+ import joblib
9
+
10
+ script_dir = os.path.dirname(os.path.abspath(__file__))
11
+ model_path = os.path.join(script_dir, "district_yield_pipeline.pkl")
12
+
13
+ # Check if file exists before trying to load
14
+ if os.path.exists(model_path):
15
+ try:
16
+ model = joblib.load(model_path)
17
+ model_loaded = True
18
+ print("Model loaded successfully!")
19
+ except Exception as e:
20
+ model_loaded = False
21
+ print(f"Error loading model file: {e}")
22
+ else:
23
  model_loaded = False
24
+ print(f"Model file not found at: {model_path}")
25
+ print(f"Available files: {os.listdir(script_dir)}")
26
 
27
  # Define the lists for dropdowns (based on your dataset)
28
  CROPS = [