saba000farahani commited on
Commit
4aae833
·
verified ·
1 Parent(s): 94b1181

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -11
app.py CHANGED
@@ -3,26 +3,40 @@ import numpy as np
3
  import joblib
4
  from tensorflow.keras.models import load_model
5
  import os
 
6
 
7
- # Check the current working directory and list its contents
8
- print("Current working directory:", os.getcwd())
9
- print("Contents of the directory:", os.listdir())
 
 
10
 
11
- # Paths to your saved models and scaler
12
  scaler_path = 'scaler_X.pkl'
13
  rf_model_path = 'rf_model.pkl'
14
  mlp_model_path = 'mlp_model.h5'
15
  meta_model_path = 'meta_model.pkl'
16
 
17
- # Check if files exist
18
- print("Checking if model files exist...")
19
- print(f"Scaler path exists: {os.path.isfile(scaler_path)}")
20
- print(f"Random Forest model path exists: {os.path.isfile(rf_model_path)}")
21
- print(f"MLP model path exists: {os.path.isfile(mlp_model_path)}")
22
- print(f"Meta model path exists: {os.path.isfile(meta_model_path)}")
 
 
23
 
 
 
 
 
 
 
 
 
 
 
24
  try:
25
- # Load the scaler and models
26
  scaler_X = joblib.load(scaler_path)
27
  print("Scaler loaded successfully.")
28
  loaded_rf_model = joblib.load(rf_model_path)
 
3
  import joblib
4
  from tensorflow.keras.models import load_model
5
  import os
6
+ import requests
7
 
8
+ # URLs of the files in your Hugging Face repository
9
+ scaler_url = 'https://huggingface.co/spaces/saba000farahani/Env_ContaminationLevel/raw/main/scaler_X.pkl'
10
+ rf_model_url = 'https://huggingface.co/spaces/saba000farahani/Env_ContaminationLevel/raw/main/rf_model.pkl'
11
+ mlp_model_url = 'https://huggingface.co/spaces/saba000farahani/Env_ContaminationLevel/raw/main/mlp_model.h5'
12
+ meta_model_url = 'https://huggingface.co/spaces/saba000farahani/Env_ContaminationLevel/raw/main/meta_model.pkl'
13
 
14
+ # Local paths to save the downloaded files
15
  scaler_path = 'scaler_X.pkl'
16
  rf_model_path = 'rf_model.pkl'
17
  mlp_model_path = 'mlp_model.h5'
18
  meta_model_path = 'meta_model.pkl'
19
 
20
+ # Function to download a file from a URL
21
+ def download_file(url, local_path):
22
+ with requests.get(url, stream=True) as r:
23
+ r.raise_for_status()
24
+ with open(local_path, 'wb') as f:
25
+ for chunk in r.iter_content(chunk_size=8192):
26
+ f.write(chunk)
27
+ print(f"Downloaded {local_path}")
28
 
29
+ # Download the files
30
+ try:
31
+ download_file(scaler_url, scaler_path)
32
+ download_file(rf_model_url, rf_model_path)
33
+ download_file(mlp_model_url, mlp_model_path)
34
+ download_file(meta_model_url, meta_model_path)
35
+ except Exception as e:
36
+ print(f"Error downloading files: {e}")
37
+
38
+ # Load the scaler and models
39
  try:
 
40
  scaler_X = joblib.load(scaler_path)
41
  print("Scaler loaded successfully.")
42
  loaded_rf_model = joblib.load(rf_model_path)