Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -173,36 +173,13 @@ def create_brand_categories():
|
|
| 173 |
}
|
| 174 |
}
|
| 175 |
|
| 176 |
-
@st.cache_resource
|
| 177 |
-
def download_file_from_google_drive(file_id):
|
| 178 |
-
"""Downloads a file from Google Drive using gdown."""
|
| 179 |
-
url = f"https://drive.google.com/uc?id={file_id}"
|
| 180 |
-
try:
|
| 181 |
-
with st.spinner('Downloading from Google Drive...'):
|
| 182 |
-
output = f"temp_{file_id}.pkl"
|
| 183 |
-
gdown.download(url, output, quiet=False)
|
| 184 |
-
|
| 185 |
-
with open(output, 'rb') as f:
|
| 186 |
-
content = f.read()
|
| 187 |
-
|
| 188 |
-
# Clean up the temporary file
|
| 189 |
-
os.remove(output)
|
| 190 |
-
return content
|
| 191 |
-
|
| 192 |
-
except Exception as e:
|
| 193 |
-
st.error(f"Error downloading from Google Drive: {str(e)}")
|
| 194 |
-
raise e
|
| 195 |
-
|
| 196 |
@st.cache_data
|
| 197 |
def load_datasets():
|
| 198 |
-
"""Load the dataset from Google Drive."""
|
| 199 |
-
dataset_file_id = "1emG-BQ3-x4xsMAGMEznkh1ACdlAj5Dn1"
|
| 200 |
-
|
| 201 |
try:
|
| 202 |
with st.spinner('Loading dataset...'):
|
| 203 |
-
content = download_file_from_google_drive(dataset_file_id)
|
| 204 |
# Use BytesIO to read the CSV content
|
| 205 |
-
original_data = pd.read_csv(BytesIO(
|
|
|
|
| 206 |
|
| 207 |
# Ensure column names match the model's expectations
|
| 208 |
original_data.columns = original_data.columns.str.strip().str.capitalize()
|
|
@@ -213,18 +190,11 @@ def load_datasets():
|
|
| 213 |
|
| 214 |
@st.cache_resource
|
| 215 |
def load_model_and_encodings():
|
| 216 |
-
"""Load model from Google Drive and create encodings."""
|
| 217 |
-
model_file_id = "1wKixkdW2pVKEpJW-N1QIyKUr2nYirU7I"
|
| 218 |
-
|
| 219 |
try:
|
| 220 |
# Show loading message
|
| 221 |
with st.spinner('Loading model...'):
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
model = joblib.load(BytesIO(model_content))
|
| 225 |
-
except:
|
| 226 |
-
model_content = download_file_from_google_drive(model_file_id)
|
| 227 |
-
model = joblib.load(BytesIO(model_content))
|
| 228 |
|
| 229 |
# Load data for encodings
|
| 230 |
original_data = load_datasets()
|
|
|
|
| 173 |
}
|
| 174 |
}
|
| 175 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
@st.cache_data
|
| 177 |
def load_datasets():
|
|
|
|
|
|
|
|
|
|
| 178 |
try:
|
| 179 |
with st.spinner('Loading dataset...'):
|
|
|
|
| 180 |
# Use BytesIO to read the CSV content
|
| 181 |
+
original_data = pd.read_csv(BytesIO(CTP_Model1.csv), low_memory=False)
|
| 182 |
+
|
| 183 |
|
| 184 |
# Ensure column names match the model's expectations
|
| 185 |
original_data.columns = original_data.columns.str.strip().str.capitalize()
|
|
|
|
| 190 |
|
| 191 |
@st.cache_resource
|
| 192 |
def load_model_and_encodings():
|
|
|
|
|
|
|
|
|
|
| 193 |
try:
|
| 194 |
# Show loading message
|
| 195 |
with st.spinner('Loading model...'):
|
| 196 |
+
model_content = hf_hub_download(repo_id="EdBoy2202/car_prediction_model", filename="car_price_modelv3.pkl")
|
| 197 |
+
model = joblib.load(BytesIO(model_content))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
|
| 199 |
# Load data for encodings
|
| 200 |
original_data = load_datasets()
|