Spaces:
Build error
Build error
Update app.py
Browse files
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 |
-
#
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
#
|
| 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 |
-
#
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
| 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)
|