File size: 1,423 Bytes
ed65aea
 
 
 
 
 
 
 
 
 
1f530b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ed65aea
 
 
 
2d07682
ed65aea
 
 
 
fa1b47f
ed65aea
 
fa1b47f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
DR MURPHY — ODE Reformulation Dashboard (HuggingFace Spaces)

Engines:
  - njit_10var: @njit Euler loop, H2 only, ~1s per cycle
  - ode_v2: scipy ODE + Numba/CoolProp, H2+N2, ~25s per cycle
  - fast: production hand-rolled engine, ~3s per cycle
"""
import os
import sys
import threading

# Defer Numba JIT to background thread so Gradio starts immediately
# (HF Spaces has a startup timeout — Numba compilation can take 2-3 min on free tier)
def _warmup_numba():
    try:
        from break_coolprop import h2_props
        ps_lut = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'h2_ps_lut.npz')
        if os.path.exists(ps_lut):
            h2_props.init(ps_lut)
            print("  Numba H2 EOS ready.")
        else:
            print(f"  Warning: h2_ps_lut.npz not found.")
    except Exception as e:
        print(f"  Numba warmup failed: {e}")

print("Starting Numba JIT warmup in background...")
_warmup_thread = threading.Thread(target=_warmup_numba, daemon=True)
_warmup_thread.start()

from scenario_gui import build_app

# Module-level demo object (required by HF Spaces)
demo = build_app()

if __name__ == "__main__":
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('--port', type=int, default=7860)
    args = parser.parse_args()
    print(f"\nLaunching on port {args.port}...")
    demo.launch(server_name="0.0.0.0", server_port=args.port, share=False)