saba000farahani commited on
Commit
dbd03d2
·
verified ·
1 Parent(s): 12672a0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -30
app.py CHANGED
@@ -3,37 +3,13 @@ import numpy as np
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:
 
3
  import joblib
4
  from tensorflow.keras.models import load_model
5
  import os
 
6
 
7
+ # Directory paths for the saved models
8
+ script_dir = os.path.dirname(os.path.abspath(__file__))
9
+ scaler_path = os.path.join(script_dir, 'toolkit', 'scaler_X.pkl')
10
+ rf_model_path = os.path.join(script_dir, 'toolkit', 'rf_model.pkl')
11
+ mlp_model_path = os.path.join(script_dir, 'toolkit', 'mlp_model.h5')
12
+ meta_model_path = os.path.join(script_dir, 'toolkit', 'meta_model.pkl')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  # Load the scaler and models
15
  try: