catninja123 commited on
Commit
a90e56a
·
verified ·
1 Parent(s): 8558968

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +27 -40
app.py CHANGED
@@ -1,6 +1,6 @@
1
  """
2
- V38.2 Admission Model - Training Space (Residualized Version)
3
- Runs train_v38_2_resid.py on HF Space hardware and displays results via Gradio.
4
  """
5
  import gradio as gr
6
  import subprocess
@@ -11,16 +11,14 @@ import time
11
 
12
  OUTPUT_DIR = './output'
13
  os.makedirs(OUTPUT_DIR, exist_ok=True)
14
-
15
- TRAIN_SCRIPT = 'train_v38_2_resid.py'
16
 
17
  def run_training():
18
- """Execute the V38.2 residualized model training"""
19
  log_lines = []
20
  log_lines.append("=" * 70)
21
- log_lines.append(f"Starting V38.2 Residualized Model Training...")
22
  log_lines.append(f"Script: {TRAIN_SCRIPT}")
23
- log_lines.append(f"Working directory: {os.getcwd()}")
24
  log_lines.append("=" * 70)
25
  yield "\n".join(log_lines)
26
 
@@ -41,43 +39,32 @@ def run_training():
41
  process.wait()
42
  log_lines.append(f"\nProcess exited with code: {process.returncode}")
43
 
44
- results_path = os.path.join(OUTPUT_DIR, 'v38_2_resid_results.json')
45
- if os.path.exists(results_path):
46
- with open(results_path) as f:
47
- results = json.load(f)
48
- log_lines.append("\n" + "=" * 70)
49
- log_lines.append("RESULTS SUMMARY")
50
- log_lines.append("=" * 70)
51
- log_lines.append(json.dumps(results, indent=2))
 
 
52
 
53
  yield "\n".join(log_lines[-300:])
54
 
55
  def check_status():
56
- results_path = os.path.join(OUTPUT_DIR, 'v38_2_resid_results.json')
57
- if os.path.exists(results_path):
58
- with open(results_path) as f:
59
- results = json.load(f)
60
- summary = f"""V38.2 Residualized Model Results:
61
- Version: {results.get('version', 'N/A')}
62
- Timestamp: {results.get('timestamp', 'N/A')}
63
- Elapsed: {results.get('elapsed_minutes', 0):.1f} minutes
64
- Features: {results.get('n_features', 'N/A')}
65
-
66
- GroupKFold AUC: {results['final_metrics']['auc']:.4f} (V37.3: 0.8697, V38.2-bare: 0.8687)
67
- Temporal AUC: {results['temporal_validation']['avg_blend']:.4f} (V37.3: 0.8410, V38.2-bare: 0.8417)
68
-
69
- Top 10 Features:
70
- """
71
- for i, (fname, imp) in enumerate(results.get('feature_importance', [])[:10]):
72
- summary += f" {i+1}. {fname}: {imp:.2f}\n"
73
- return summary
74
- else:
75
- return "No results yet. Click 'Run Training' to start."
76
 
77
  def auto_run():
78
- results_path = os.path.join(OUTPUT_DIR, 'v38_2_resid_results.json')
79
  if not os.path.exists(results_path):
80
- print("Auto-starting residualized model training...")
81
  process = subprocess.Popen(
82
  [sys.executable, TRAIN_SCRIPT],
83
  stdout=subprocess.PIPE,
@@ -90,9 +77,9 @@ def auto_run():
90
  process.wait()
91
  print(f"Training complete. Exit code: {process.returncode}")
92
 
93
- with gr.Blocks(title="V38.2 Residualized Model") as demo:
94
- gr.Markdown("# V38.2 Residualized Model - Simpson's Paradox Fix")
95
- gr.Markdown("Adds school_base_rate, residualized features, explicit interactions, and school percentiles")
96
 
97
  with gr.Row():
98
  run_btn = gr.Button("Run Training", variant="primary")
 
1
  """
2
+ V38.2-PRO Admission Model - Training Space
3
+ Runs train_v38_2_pro.py with feature selection + optimized residualization.
4
  """
5
  import gradio as gr
6
  import subprocess
 
11
 
12
  OUTPUT_DIR = './output'
13
  os.makedirs(OUTPUT_DIR, exist_ok=True)
14
+ TRAIN_SCRIPT = 'train_v38_2_pro.py'
 
15
 
16
  def run_training():
17
+ """Execute the V38.2-PRO model training"""
18
  log_lines = []
19
  log_lines.append("=" * 70)
20
+ log_lines.append(f"Starting V38.2-PRO Model Training...")
21
  log_lines.append(f"Script: {TRAIN_SCRIPT}")
 
22
  log_lines.append("=" * 70)
23
  yield "\n".join(log_lines)
24
 
 
39
  process.wait()
40
  log_lines.append(f"\nProcess exited with code: {process.returncode}")
41
 
42
+ for results_name in ['v38_2_pro_results.json', 'v38_2_resid_results.json']:
43
+ results_path = os.path.join(OUTPUT_DIR, results_name)
44
+ if os.path.exists(results_path):
45
+ with open(results_path) as f:
46
+ results = json.load(f)
47
+ log_lines.append("\n" + "=" * 70)
48
+ log_lines.append(f"RESULTS: {results_name}")
49
+ log_lines.append("=" * 70)
50
+ log_lines.append(json.dumps(results, indent=2))
51
+ break
52
 
53
  yield "\n".join(log_lines[-300:])
54
 
55
  def check_status():
56
+ for results_name in ['v38_2_pro_results.json', 'v38_2_resid_results.json']:
57
+ results_path = os.path.join(OUTPUT_DIR, results_name)
58
+ if os.path.exists(results_path):
59
+ with open(results_path) as f:
60
+ results = json.load(f)
61
+ return json.dumps(results, indent=2)
62
+ return "No results yet. Click Run Training to start."
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
  def auto_run():
65
+ results_path = os.path.join(OUTPUT_DIR, 'v38_2_pro_results.json')
66
  if not os.path.exists(results_path):
67
+ print("Auto-starting V38.2-PRO model training...")
68
  process = subprocess.Popen(
69
  [sys.executable, TRAIN_SCRIPT],
70
  stdout=subprocess.PIPE,
 
77
  process.wait()
78
  print(f"Training complete. Exit code: {process.returncode}")
79
 
80
+ with gr.Blocks(title="V38.2-PRO Model") as demo:
81
+ gr.Markdown("# V38.2-PRO Model - Feature Selection + Optimized Residualization")
82
+ gr.Markdown("Stage 1: Feature importance Stage 2: Selected features + stronger regularization")
83
 
84
  with gr.Row():
85
  run_btn = gr.Button("Run Training", variant="primary")