mastefan commited on
Commit
87fd244
·
verified ·
1 Parent(s): 000cde8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -13
app.py CHANGED
@@ -188,25 +188,29 @@ def extract_feature_timeseries(video_path:str, frame_skip:int=FRAME_SKIP, debug:
188
  # Predictor & event logic
189
  # =====================================================
190
  def predict_scores(df):
191
- feats=["red_ratio","green_ratio","red_diff","green_diff","z_red","z_green"]
192
- X=df[feats].copy()
193
- ag=ag_predictor()
194
- available_models = ag.get_model_names()
 
 
195
  safe_models = [m for m in available_models if "fastai" not in m.lower()]
196
- print(f"[INFO] Using models: {safe_models}")
 
197
  try:
198
- proba=ag.predict_proba(X, models=safe_models)
199
- if isinstance(proba,pd.DataFrame) and (1 in proba.columns):
200
  return proba[1]
201
  except Exception as e:
202
- print("[WARN] AutoGluon fastai model failed, falling back to safe models only:", e)
203
- proba=ag.predict_proba(X, models=safe_models)
204
- if isinstance(proba,pd.DataFrame) and (1 in proba.columns):
205
  return proba[1]
206
- s=pd.Series(ag.predict(X, models=safe_models)).astype(float)
207
- rng=(s.quantile(0.95)-s.quantile(0.05)) or 1.0
208
- return ((s-s.quantile(0.05))/rng).clip(0,1)
209
 
 
 
 
 
210
 
211
  def pick_events(df,score,fps):
212
  z=rolling_z(score,45); strong=(z>4.0); keep=strong.rolling(3,min_periods=1).sum()>=2
 
188
  # Predictor & event logic
189
  # =====================================================
190
  def predict_scores(df):
191
+ feats = ["red_ratio", "green_ratio", "red_diff", "green_diff", "z_red", "z_green"]
192
+ X = df[feats].copy()
193
+ ag = ag_predictor()
194
+
195
+ # List available models and remove any FastAI learners that might break
196
+ available_models = ag.model_names
197
  safe_models = [m for m in available_models if "fastai" not in m.lower()]
198
+ print(f"[INFO] Using safe models: {safe_models}")
199
+
200
  try:
201
+ proba = ag.predict_proba(X, models=safe_models)
202
+ if isinstance(proba, pd.DataFrame) and (1 in proba.columns):
203
  return proba[1]
204
  except Exception as e:
205
+ print("[WARN] AutoGluon fastai model failed; retrying with safe models only:", e)
206
+ proba = ag.predict_proba(X, models=safe_models)
207
+ if isinstance(proba, pd.DataFrame) and (1 in proba.columns):
208
  return proba[1]
 
 
 
209
 
210
+ # Fallback in case probability data isn't available
211
+ s = pd.Series(ag.predict(X, models=safe_models)).astype(float)
212
+ rng = (s.quantile(0.95) - s.quantile(0.05)) or 1.0
213
+ return ((s - s.quantile(0.05)) / rng).clip(0, 1)
214
 
215
  def pick_events(df,score,fps):
216
  z=rolling_z(score,45); strong=(z>4.0); keep=strong.rolling(3,min_periods=1).sum()>=2