AF-HuggingFace commited on
Commit
cc77f2c
Β·
verified Β·
1 Parent(s): eb9968a

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -10
app.py CHANGED
@@ -105,6 +105,19 @@ else:
105
  print(" 2. Place this notebook inside the aegis-reason/ directory, OR")
106
  print(" 3. Clone: !git clone <repo-url> aegis-reason")
107
  DDIR = 'aegis_dataset'
 
 
 
 
 
 
 
 
 
 
 
 
 
108
 
109
  # ═══════════════════════════ DESIGN SYSTEM ═══════════════════════════
110
  # (rcParams already set above β€” dark)
@@ -8899,6 +8912,18 @@ def impact_scenario(disaster_name, rescue_boost=0.0):
8899
 
8900
 
8901
  def explore():
 
 
 
 
 
 
 
 
 
 
 
 
8902
  if not os.path.isdir(DDIR): return '❌',None,EMPTY_3D_HTML
8903
  lines_e=[]
8904
  for sub in ['topdown','egocentric','chains']:
@@ -8938,6 +8963,17 @@ def explore():
8938
 
8939
  def view_chain(idx):
8940
  sft=os.path.join(DDIR,'sft_data.jsonl')
 
 
 
 
 
 
 
 
 
 
 
8941
  if not os.path.exists(sft): return 'No data.',None
8942
  recs=[json.loads(l) for l in open(sft)]; idx=max(0,min(int(idx),len(recs)-1)); r=recs[idx]
8943
  ch=r['conversations'][2]['content']
@@ -8965,17 +9001,24 @@ def view_chain(idx):
8965
  return f"ID: {r['id']}\n{len(ch)} chars\n\n{ch}",img
8966
 
8967
  def run_validation():
 
 
 
 
8968
  out=['═══ E2E ═══']
8969
- if os.path.exists('scripts/aegis_e2e_test.py'):
8970
- r=subprocess.run([sys.executable,'scripts/aegis_e2e_test.py'],capture_output=True,text=True,timeout=300); out.append(r.stdout[:2000])
 
8971
  else: out.append('❌ Not found')
8972
  out.append('\n═══ AUDIT ═══'); iss=0
8973
- for pyf in glob.glob('*.py')+glob.glob('scripts/*.py'):
8974
  for i,ln in enumerate(open(pyf).readlines(),1):
8975
- if '/home/claude/' in ln and not ln.strip().startswith('#'): out.append(f' ⚠️ {pyf}:{i}'); iss+=1
 
8976
  if iss==0: out.append(' βœ… Clean')
8977
  for f in ['README.md','configs/aegis_sft.toml','configs/aegis_grpo.toml','LICENSE','requirements.txt']:
8978
- out.append(f' {"βœ…" if os.path.exists(f) else "❌"} {f}')
 
8979
  return '\n'.join(out)
8980
 
8981
  # ─── Interactive weight explorer ───
@@ -12759,15 +12802,15 @@ Physical AI agents must **ground decisions in domain knowledge**. CRAG closes th
12759
  with gr.Tab('πŸ”¬ Ablation'):
12760
  gr.Markdown("**Conditions**: A (Oracle) β†’ B (Partial: spatial+decision only) β†’ C (Degraded: shifted coords) β†’ D (Vague)")
12761
  with gr.Accordion("πŸ”„ Interactive 3D: Ablation Conditions (rotate me!)", open=True):
12762
- gr.HTML(value=fig3d_html(plotly_ablation_3d()), label='3D Ablation')
12763
- ab_b=gr.Button('Generate 3D Ablation',variant='primary'); ab_p=gr.HTML(value=EMPTY_3D_HTML, label='3D Interactive Ablation')
12764
  ab_b.click(fn=_safe(show_ablation, lambda e: EMPTY_3D_HTML),outputs=ab_p)
12765
 
12766
  # ──────────────── TAB 5: CALCULUS ────────────────
12767
  with gr.Tab('πŸ“ Calibration'):
12768
  with gr.Accordion("πŸ”„ Interactive 3D: Calibration (rotate me!)", open=True):
12769
- gr.HTML(value=fig3d_html(plotly_calibration_3d()), label='3D Calibration')
12770
- cr_b=gr.Button('Regenerate 3D Calibration',variant='primary'); cr_p=gr.HTML(value=EMPTY_3D_HTML, label='3D Interactive')
12771
  cr_b.click(fn=_safe(show_calibration, lambda e: EMPTY_3D_HTML),outputs=cr_p)
12772
 
12773
  # ──────────────── TAB 10: DATASET ────────────────
@@ -12891,7 +12934,7 @@ Benchmarks: Baseten 48% P95↓, Moonshot AI 10x, DeepSeek-R1 30x on GB200
12891
  label='⚑ Inference Backend'
12892
  )
12893
  with gr.Row():
12894
- accel_scenario = gr.Dropdown(
12895
  choices=[v['domain'] for v in CR2_HEALTHCARE_SCENARIOS.values()],
12896
  value=list(CR2_HEALTHCARE_SCENARIOS.values())[0]['domain'],
12897
  label='πŸ₯ Healthcare Scenario'
 
105
  print(" 2. Place this notebook inside the aegis-reason/ directory, OR")
106
  print(" 3. Clone: !git clone <repo-url> aegis-reason")
107
  DDIR = 'aegis_dataset'
108
+ # Robust search for aegis_dataset directory (handles HF Spaces path variations)
109
+ if not os.path.isdir(DDIR):
110
+ _script_dir = os.path.dirname(os.path.abspath(__file__)) if '__file__' in dir() else os.getcwd()
111
+ _ddir_candidates = [
112
+ os.path.join(_script_dir, 'aegis_dataset'),
113
+ os.path.join(os.getcwd(), 'aegis_dataset'),
114
+ '/home/user/app/aegis_dataset',
115
+ os.path.join(REPO, 'aegis_dataset') if REPO else None,
116
+ ]
117
+ for _dc in _ddir_candidates:
118
+ if _dc and os.path.isdir(_dc):
119
+ DDIR = _dc
120
+ break
121
 
122
  # ═══════════════════════════ DESIGN SYSTEM ═══════════════════════════
123
  # (rcParams already set above β€” dark)
 
8912
 
8913
 
8914
  def explore():
8915
+ global DDIR
8916
+ # Fallback search if DDIR doesn't resolve at runtime
8917
+ if not os.path.isdir(DDIR):
8918
+ _script_dir = os.path.dirname(os.path.abspath(__file__)) if '__file__' in dir() else os.getcwd()
8919
+ for _candidate in [
8920
+ os.path.join(_script_dir, 'aegis_dataset'),
8921
+ os.path.join(os.getcwd(), 'aegis_dataset'),
8922
+ '/home/user/app/aegis_dataset',
8923
+ ]:
8924
+ if os.path.isdir(_candidate):
8925
+ DDIR = _candidate
8926
+ break
8927
  if not os.path.isdir(DDIR): return '❌',None,EMPTY_3D_HTML
8928
  lines_e=[]
8929
  for sub in ['topdown','egocentric','chains']:
 
8963
 
8964
  def view_chain(idx):
8965
  sft=os.path.join(DDIR,'sft_data.jsonl')
8966
+ # Fallback search if primary DDIR doesn't contain sft_data.jsonl
8967
+ if not os.path.exists(sft):
8968
+ _script_dir = os.path.dirname(os.path.abspath(__file__)) if '__file__' in dir() else os.getcwd()
8969
+ for _candidate in [
8970
+ os.path.join(_script_dir, 'aegis_dataset', 'sft_data.jsonl'),
8971
+ os.path.join(os.getcwd(), 'aegis_dataset', 'sft_data.jsonl'),
8972
+ '/home/user/app/aegis_dataset/sft_data.jsonl',
8973
+ ]:
8974
+ if os.path.exists(_candidate):
8975
+ sft = _candidate
8976
+ break
8977
  if not os.path.exists(sft): return 'No data.',None
8978
  recs=[json.loads(l) for l in open(sft)]; idx=max(0,min(int(idx),len(recs)-1)); r=recs[idx]
8979
  ch=r['conversations'][2]['content']
 
9001
  return f"ID: {r['id']}\n{len(ch)} chars\n\n{ch}",img
9002
 
9003
  def run_validation():
9004
+ # Resolve the repo root for all relative path lookups
9005
+ _root = REPO or os.path.dirname(os.path.abspath(__file__)) if '__file__' in dir() else os.getcwd()
9006
+ if not _root or not os.path.isdir(_root):
9007
+ _root = os.getcwd()
9008
  out=['═══ E2E ═══']
9009
+ e2e_path = os.path.join(_root, 'scripts', 'aegis_e2e_test.py')
9010
+ if os.path.exists(e2e_path):
9011
+ r=subprocess.run([sys.executable, e2e_path],capture_output=True,text=True,timeout=300, cwd=_root); out.append(r.stdout[:2000])
9012
  else: out.append('❌ Not found')
9013
  out.append('\n═══ AUDIT ═══'); iss=0
9014
+ for pyf in glob.glob(os.path.join(_root, '*.py'))+glob.glob(os.path.join(_root, 'scripts', '*.py')):
9015
  for i,ln in enumerate(open(pyf).readlines(),1):
9016
+ if '/home/claude/' in ln and not ln.strip().startswith('#'):
9017
+ out.append(f' ⚠️ {os.path.relpath(pyf, _root)}:{i}'); iss+=1
9018
  if iss==0: out.append(' βœ… Clean')
9019
  for f in ['README.md','configs/aegis_sft.toml','configs/aegis_grpo.toml','LICENSE','requirements.txt']:
9020
+ fp = os.path.join(_root, f)
9021
+ out.append(f' {"βœ…" if os.path.exists(fp) else "❌"} {f}')
9022
  return '\n'.join(out)
9023
 
9024
  # ─── Interactive weight explorer ───
 
12802
  with gr.Tab('πŸ”¬ Ablation'):
12803
  gr.Markdown("**Conditions**: A (Oracle) β†’ B (Partial: spatial+decision only) β†’ C (Degraded: shifted coords) β†’ D (Vague)")
12804
  with gr.Accordion("πŸ”„ Interactive 3D: Ablation Conditions (rotate me!)", open=True):
12805
+ ab_p=gr.HTML(value=EMPTY_3D_HTML, label='3D Interactive Ablation')
12806
+ ab_b=gr.Button('Generate 3D Ablation',variant='primary')
12807
  ab_b.click(fn=_safe(show_ablation, lambda e: EMPTY_3D_HTML),outputs=ab_p)
12808
 
12809
  # ──────────────── TAB 5: CALCULUS ────────────────
12810
  with gr.Tab('πŸ“ Calibration'):
12811
  with gr.Accordion("πŸ”„ Interactive 3D: Calibration (rotate me!)", open=True):
12812
+ cr_p=gr.HTML(value=EMPTY_3D_HTML, label='3D Interactive')
12813
+ cr_b=gr.Button('Generate 3D Calibration',variant='primary')
12814
  cr_b.click(fn=_safe(show_calibration, lambda e: EMPTY_3D_HTML),outputs=cr_p)
12815
 
12816
  # ──────────────── TAB 10: DATASET ────────────────
 
12934
  label='⚑ Inference Backend'
12935
  )
12936
  with gr.Row():
12937
+ accel_scenario = gr.Radio(
12938
  choices=[v['domain'] for v in CR2_HEALTHCARE_SCENARIOS.values()],
12939
  value=list(CR2_HEALTHCARE_SCENARIOS.values())[0]['domain'],
12940
  label='πŸ₯ Healthcare Scenario'