Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -79,14 +79,24 @@ if (should_train_model=='1'): #train model
|
|
| 79 |
|
| 80 |
|
| 81 |
# Check if the result is a non-empty DataFrame
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
file_train_df = pd.read_csv(file_path_train)
|
| 89 |
file_test_df = pd.read_csv(file_path_test)
|
|
|
|
|
|
|
| 90 |
|
| 91 |
#file_train_df = fetch_and_update_training_data(file_path_train)
|
| 92 |
#file_test_df = pd.read_csv(file_path_test)
|
|
|
|
| 79 |
|
| 80 |
|
| 81 |
# Check if the result is a non-empty DataFrame
|
| 82 |
+
try:
|
| 83 |
+
# Try fetching from the API
|
| 84 |
+
file_train_df_temp = fetch_and_update_training_data(file_path_train)
|
| 85 |
+
|
| 86 |
+
if file_train_df_temp is not None and not file_train_df_temp.empty:
|
| 87 |
+
file_train_df = file_train_df_temp
|
| 88 |
+
file_test_df = pd.read_csv(file_path_test)
|
| 89 |
+
print("API fetch data.")
|
| 90 |
+
else:
|
| 91 |
+
raise ValueError("Empty or None DataFrame received from API.")
|
| 92 |
+
|
| 93 |
+
except Exception as e:
|
| 94 |
+
# On any error, fallback to local CSV
|
| 95 |
+
print(f"API fetch failed ({e}) — using local CSV.")
|
| 96 |
file_train_df = pd.read_csv(file_path_train)
|
| 97 |
file_test_df = pd.read_csv(file_path_test)
|
| 98 |
+
|
| 99 |
+
|
| 100 |
|
| 101 |
#file_train_df = fetch_and_update_training_data(file_path_train)
|
| 102 |
#file_test_df = pd.read_csv(file_path_test)
|