Spaces:
Runtime error
Runtime error
Upload Preprocessing.py
Browse files- Preprocessing.py +9 -7
Preprocessing.py
CHANGED
|
@@ -18,21 +18,23 @@ def download_and_load_pkl(url, filename):
|
|
| 18 |
print(f"Attempting to download {filename} from {url}")
|
| 19 |
try:
|
| 20 |
response = requests.get(url, stream=True)
|
| 21 |
-
response.raise_for_status()
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
| 24 |
for chunk in response.iter_content(chunk_size=8192):
|
| 25 |
f.write(chunk)
|
| 26 |
|
| 27 |
-
obj = joblib.load(
|
| 28 |
print(f"Successfully downloaded and loaded {filename}")
|
| 29 |
-
os.remove(
|
| 30 |
return obj
|
| 31 |
except requests.exceptions.RequestException as e:
|
| 32 |
-
print(f"Error downloading {
|
| 33 |
return None
|
| 34 |
except Exception as e:
|
| 35 |
-
print(f"Error loading {
|
| 36 |
return None
|
| 37 |
|
| 38 |
numerical_imputer = download_and_load_pkl(NUM_IMPUTER_URL, "numerical_imputer.pkl")
|
|
|
|
| 18 |
print(f"Attempting to download {filename} from {url}")
|
| 19 |
try:
|
| 20 |
response = requests.get(url, stream=True)
|
| 21 |
+
response.raise_for_status()
|
| 22 |
+
|
| 23 |
+
temp_filepath = os.path.join('/tmp', filename)
|
| 24 |
+
|
| 25 |
+
with open(temp_filepath, 'wb') as f:
|
| 26 |
for chunk in response.iter_content(chunk_size=8192):
|
| 27 |
f.write(chunk)
|
| 28 |
|
| 29 |
+
obj = joblib.load(temp_filepath)
|
| 30 |
print(f"Successfully downloaded and loaded {filename}")
|
| 31 |
+
os.remove(temp_filepath)
|
| 32 |
return obj
|
| 33 |
except requests.exceptions.RequestException as e:
|
| 34 |
+
print(f"Error downloading {temp_filepath} from {url}: {e}")
|
| 35 |
return None
|
| 36 |
except Exception as e:
|
| 37 |
+
print(f"Error loading {temp_filepath} after download: {e}")
|
| 38 |
return None
|
| 39 |
|
| 40 |
numerical_imputer = download_and_load_pkl(NUM_IMPUTER_URL, "numerical_imputer.pkl")
|