404Brain-Not-Found-yeah
commited on
Commit
•
81ce00b
1
Parent(s):
9aa6163
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ import tempfile
|
|
7 |
from huggingface_hub import hf_hub_download, list_repo_files
|
8 |
import logging
|
9 |
import traceback
|
|
|
10 |
|
11 |
# Set up logging
|
12 |
logging.basicConfig(
|
@@ -26,12 +27,16 @@ st.set_page_config(
|
|
26 |
def load_model():
|
27 |
"""Load model from Hugging Face Hub"""
|
28 |
try:
|
|
|
|
|
|
|
|
|
29 |
# 首先列出仓库中的所有文件
|
30 |
logger.info("Listing repository files...")
|
31 |
try:
|
32 |
files = list_repo_files("404Brain-Not-Found-yeah/healing-music-classifier")
|
33 |
logger.info(f"Repository files: {files}")
|
34 |
-
st.write("Available files in repository:", files)
|
35 |
except Exception as e:
|
36 |
logger.error(f"Error listing repository files: {str(e)}\n{traceback.format_exc()}")
|
37 |
st.error(f"Error listing repository files: {str(e)}")
|
@@ -50,7 +55,7 @@ def load_model():
|
|
50 |
local_dir="temp_models"
|
51 |
)
|
52 |
logger.info(f"Model downloaded to: {model_path}")
|
53 |
-
st.write(f"Model downloaded to: {model_path}")
|
54 |
except Exception as e:
|
55 |
logger.error(f"Error downloading model: {str(e)}\n{traceback.format_exc()}")
|
56 |
st.error(f"Error downloading model: {str(e)}")
|
@@ -64,7 +69,7 @@ def load_model():
|
|
64 |
local_dir="temp_models"
|
65 |
)
|
66 |
logger.info(f"Scaler downloaded to: {scaler_path}")
|
67 |
-
st.write(f"Scaler downloaded to: {scaler_path}")
|
68 |
except Exception as e:
|
69 |
logger.error(f"Error downloading scaler: {str(e)}\n{traceback.format_exc()}")
|
70 |
st.error(f"Error downloading scaler: {str(e)}")
|
@@ -91,10 +96,21 @@ def load_model():
|
|
91 |
st.write(f"Model file size: {model_size} bytes")
|
92 |
st.write(f"Scaler file size: {scaler_size} bytes")
|
93 |
|
94 |
-
|
95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
logger.info("Model and scaler loaded successfully")
|
97 |
-
st.success("Model and scaler loaded successfully!")
|
98 |
return model, scaler
|
99 |
except Exception as e:
|
100 |
logger.error(f"Error loading model/scaler files: {str(e)}\n{traceback.format_exc()}")
|
|
|
7 |
from huggingface_hub import hf_hub_download, list_repo_files
|
8 |
import logging
|
9 |
import traceback
|
10 |
+
import sklearn
|
11 |
|
12 |
# Set up logging
|
13 |
logging.basicConfig(
|
|
|
27 |
def load_model():
|
28 |
"""Load model from Hugging Face Hub"""
|
29 |
try:
|
30 |
+
# 检查scikit-learn版本
|
31 |
+
logger.info(f"Using scikit-learn version: {sklearn.__version__}")
|
32 |
+
st.write(f"Using scikit-learn version: {sklearn.__version__}")
|
33 |
+
|
34 |
# 首先列出仓库中的所有文件
|
35 |
logger.info("Listing repository files...")
|
36 |
try:
|
37 |
files = list_repo_files("404Brain-Not-Found-yeah/healing-music-classifier")
|
38 |
logger.info(f"Repository files: {files}")
|
39 |
+
st.write("Available files in repository:", files)
|
40 |
except Exception as e:
|
41 |
logger.error(f"Error listing repository files: {str(e)}\n{traceback.format_exc()}")
|
42 |
st.error(f"Error listing repository files: {str(e)}")
|
|
|
55 |
local_dir="temp_models"
|
56 |
)
|
57 |
logger.info(f"Model downloaded to: {model_path}")
|
58 |
+
st.write(f"Model downloaded to: {model_path}")
|
59 |
except Exception as e:
|
60 |
logger.error(f"Error downloading model: {str(e)}\n{traceback.format_exc()}")
|
61 |
st.error(f"Error downloading model: {str(e)}")
|
|
|
69 |
local_dir="temp_models"
|
70 |
)
|
71 |
logger.info(f"Scaler downloaded to: {scaler_path}")
|
72 |
+
st.write(f"Scaler downloaded to: {scaler_path}")
|
73 |
except Exception as e:
|
74 |
logger.error(f"Error downloading scaler: {str(e)}\n{traceback.format_exc()}")
|
75 |
st.error(f"Error downloading scaler: {str(e)}")
|
|
|
96 |
st.write(f"Model file size: {model_size} bytes")
|
97 |
st.write(f"Scaler file size: {scaler_size} bytes")
|
98 |
|
99 |
+
# 尝试使用不同的pickle协议加载
|
100 |
+
try:
|
101 |
+
model = joblib.load(model_path)
|
102 |
+
scaler = joblib.load(scaler_path)
|
103 |
+
except Exception as load_error:
|
104 |
+
logger.warning(f"Standard loading failed: {str(load_error)}")
|
105 |
+
# 尝试使用兼容模式加载
|
106 |
+
import pickle
|
107 |
+
with open(model_path, 'rb') as f:
|
108 |
+
model = pickle.load(f, encoding='latin1')
|
109 |
+
with open(scaler_path, 'rb') as f:
|
110 |
+
scaler = pickle.load(f, encoding='latin1')
|
111 |
+
|
112 |
logger.info("Model and scaler loaded successfully")
|
113 |
+
st.success("Model and scaler loaded successfully!")
|
114 |
return model, scaler
|
115 |
except Exception as e:
|
116 |
logger.error(f"Error loading model/scaler files: {str(e)}\n{traceback.format_exc()}")
|