Spaces:
Sleeping
Sleeping
Update app.py
Browse files12345617 unmodified lines24252627282930313233343 unmodified lines383940414243444546474849505152535455565758591 unmodified line616263646566676869707172733 unmodified lines77787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241252 unmodified lines1281291301311321331341351361371381391401411421431441451461471481491501511521531541553 unmodified lines159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360# ==============================================================================# SYSTEM: SADIM AI RADAR 77M - TACTICAL EXPERT INTERFACE# VERSION: 2.7.0 (FINAL FULL MASTER SUITE)# ==============================================================================import streamlit as st17 unmodified lines)# ------------------------------------------------------------------------------# 2. ADVANCED CSS STYLING (ULTRA-COMPACT PRECISION INTERFACE)# ------------------------------------------------------------------------------st.markdown("""<style>/* Full Page Reset - Dark Mode Background */html, body, [data-testid="stAppViewContainer"], [data-testid="stMainViewContainer"], .main, .block-container {padding: 0 !important;margin: 0 !important;3 unmodified linesbackground-color: #000000 !important;}/* Stealth UI - Remove Streamlit overhead */[data-testid="stHeader"], footer { display: none !important; }/* THE WHITE SEARCH BAR - Precision Design */div[data-testid="stHorizontalBlock"] {position: fixed !important;bottom: 25px !important;left: 20px !important;z-index: 100000 !important;background-color: rgba(255, 255, 255, 0.98) !important;border: 1px solid #888888 !important;padding: 4px 6px !important;border-radius: 4px !important;box-shadow: 0px 8px 30px rgba(0,0,0,0.8) !important;/* FIXED: Wrapping content exactly to remove dead space */width: fit-content !important;display: flex !important;flex-direction: row !important;1 unmodified linealign-items: center !important;}/* Manual column width control for compact look */div[data-testid="column"]:nth-of-type(1) { width: 140px !important; flex: none !important; }div[data-testid="column"]:nth-of-type(2) { width: 65px !important; flex: none !important; }/* Input Field Styling */div[data-testid="stTextInput"] { margin-bottom: 0 !important; }div[data-testid="stTextInput"] > div:first-child { display: none !important; }div[data-testid="stTextInput"] input {background-color: #ffffff !important;color: #000000 !important;3 unmodified linesfont-weight: bold !important;padding: 4px 8px !important;border-radius: 2px !important;height: 32px !important; /* FIXED: Exact matched height */outline: none !important;}/* SCAN Button - Sized to match input precisely */div[data-testid="stButton"] { margin-bottom: 0 !important; }div[data-testid="stButton"] button {background-color: #f2f2f2 !important;color: #000000 !important;border: 1px solid #aaaaaa !important;font-family: sans-serif !important;font-size: 10px !important;font-weight: 900 !important;padding: 0 12px !important;border-radius: 2px !important;text-transform: uppercase !important;letter-spacing: 0.5px !important;height: 32px !important; /* FIXED: Exact matched height */line-height: 32px !important;transition: 0.2s all ease-in-out;}div[data-testid="stButton"] button:hover {background-color: #ffffff !important;border-color: #000000 !important;}/* Fixed Map Viewport */iframe {position: fixed !important; top: 0 !important; left: -1px !important;width: calc(100vw + 2px) !important; height: 100vh !important;border: none !important; margin: 0 !important; padding: 0 !important;}</style>""", unsafe_allow_html=True)# ------------------------------------------------------------------------------# 3. SADIM AI ARCHITECTURE (77 MILLION PARAMETER FULL ENGINE)# ------------------------------------------------------------------------------class ResidualBlock(nn.Module):"""Standard Residual block for high-fidelity latent feature extraction."""def __init__(self, dim):super(ResidualBlock, self).__init__()self.ln = nn.LayerNorm(dim)2 unmodified linesnn.GELU(),nn.Linear(dim, dim))def forward(self, x):return x + self.fc(self.ln(x))class SADIM_V2_54M_Expert(nn.Module):"""SADIM 77M Expert Model - The analytical core."""def __init__(self, input_dim=12, latent_dim=64):super(SADIM_V2_54M_Expert, self).__init__()h = 3584 # The expert scaling dimension# Encoder Stackself.encoder = nn.Sequential(nn.Linear(input_dim, h), nn.LayerNorm(h), nn.GELU(),nn.Linear(h, h), nn.LayerNorm(h), nn.GELU(),ResidualBlock(h), ResidualBlock(h), ResidualBlock(h))self.fc_mu = nn.Linear(h, latent_dim)self.fc_logvar = nn.Linear(h, latent_dim)# Decoder Stackself.decoder = nn.Sequential(nn.Linear(latent_dim, h), nn.GELU(),nn.Linear(h, h), nn.LayerNorm(h), nn.GELU(),3 unmodified linesdef forward(self, x):hidden = self.encoder(x)mu, logvar = self.fc_mu(hidden), self.fc_logvar(hidden)logvar = torch.clamp(logvar, -10, 10)std = torch.exp(0.5 * logvar)z = mu + torch.randn_like(mu) * stdreturn self.decoder(z), mu, logvar@st.cache_resourcedef load_deep_ai_model():"""Fetches pre-trained expert weights from the repository."""device = torch.device("cpu")model = SADIM_V2_54M_Expert().to(device)try:hf_token = os.environ.get("HF_TOKEN")weights = hf_hub_download(repo_id="KilmaAI/Sadim-77M", filename="pytorch_model.bin", token=hf_token)model.load_state_dict(torch.load(weights, map_location=device))except: passmodel.eval()return model, devicemodel, device = load_deep_ai_model()# ------------------------------------------------------------------------------# 4. STELLAR DATA ENGINE (FIXED IO_FAILURE LOGIC)# ------------------------------------------------------------------------------@st.cache_data(show_spinner=False)def execute_tactical_scan(sid):"""DuckDB SQL Interface - Optimized to avoid IO Errors."""token = os.environ.get("HF_TOKEN")if not token: return {"error": "HF_TOKEN NOT FOUND"}try:# Create an isolated in-memory DB connectiondb = duckdb.connect(database=':memory:')db.execute("INSTALL httpfs; LOAD httpfs;")# MODERN SECRET PROTOCOL (STABLE)db.execute(f"CREATE SECRET IF NOT EXISTS s_tactical (TYPE HUGGINGFACE, TOKEN '{token}');")# SNIPER FIX: Using the direct parquet link to avoid globbing IO Errors (*.parquet)direct_path = "hf://datasets/samfatnassi/gaia-dr3/gaia_dr3_cleaned.parquet"sql = f"""SELECT ra, dec, pmra, pmdec, d_pc, abs_m, bp_rp, l, b, x, y, zFROM '{direct_path}'WHERE source_id = {sid} LIMIT 1"""df = db.query(sql).df()db.close()except Exception as e:return {"error": f"IO_FATAL: {str(e)}"}if df.empty: return {"error": "SOURCE_ID NOT IN THIS SECTOR"}# --- Physical Calculations ---star = df.iloc[0]dist_ly = star['d_pc'] * 3.26156v_tan = 4.74 * 1e-3 * math.sqrt(star['pmra']**2 + star['pmdec']**2) * star['d_pc']# --- AI Inference Loop ---try:vector = np.array([star['ra'], star['dec'], star['l'], star['b'], star['pmra'], star['pmdec'], star['d_pc'], star['x'], star['y'], star['z'], star['abs_m'], star['bp_rp']], dtype=np.float32)# Normalization Protocolvector[0]/=360; vector[1]/=90; vector[2]/=360; vector[3]/=90; vector[4]/=500; vector[5]/=500; vector[6]/=10000; vector[7]/=15000; vector[8]/=15000; vector[9]/=15000tensor_in = torch.tensor(np.nan_to_num(vector)).unsqueeze(0).to(device)with torch.no_grad():rec, mu, lv = model(tensor_in)mse, kl = torch.mean((rec - tensor_in)**2).item(), -0.5 * torch.sum(1 + lv - mu.pow(2) - lv.exp()).item()hybrid_score = mse + (0.1 * kl)except: mse, kl, hybrid_score = 0, 0, 0return {'id': sid, 'ra': star['ra'], 'dec': star['dec'], 'dist': round(dist_ly, 1), 'vel': round(v_tan, 2),'mse': round(mse, 6), 'kl': round(kl, 6), 'score': round(hybrid_score, 5),'status': "EXTREME ANOMALY" if hybrid_score > 5.0 else "NOMINAL (NORMAL)",'color': "#ffffff" if hybrid_score > 5.0 else "#888888"}# ------------------------------------------------------------------------------# 5. SESSION MANAGEMENT & INTERFACE BUILDER# ------------------------------------------------------------------------------if 'radar_session' not in st.session_state:st.session_state.radar_session = {'res': None, 'active': False, 'fail': False, 'msg': "", 'ra': 269.44, 'dec': 4.73}# Compact White Block Renderingc1, c2 = st.columns([2, 1])with c1:user_input = st.text_input("ID", placeholder="ID SEARCH", label_visibility="collapsed")with c2:if st.button("SCAN"):with st.spinner(""):result = execute_tactical_scan(user_input)if "error" in result:st.session_state.radar_session.update({'res': None, 'active': True, 'fail': True, 'msg': result['error']})else:st.session_state.radar_session.update({'res': result, 'ra': result['ra'], 'dec': result['dec'], 'active': True, 'fail': False})# Construct Analysis Popup HTMLui_popup = ""if st.session_state.radar_session['active']:rs = st.session_state.radar_sessionif rs['fail']:ui_popup = f"""<div id="modal" class="tactical-popup" style="border-color:#ff4444"><div class="m-head"><span style="color:#ff4444">! ALERT_FAILURE</span><button onclick="document.getElementById('modal').style.display='none'" class="close-x">×</button></div><div style="color:#ff4444;font-size:11px;text-align:center;padding:10px;font-weight:bold">{rs['msg']}</div></div>"""elif rs['res']:d = rs['res']ui_popup = f"""<div id="modal" class="tactical-popup"><div class="m-head"><span>SADIM 77M // SCAN_REPORT</span><button onclick="document.getElementById('modal').style.display='none'" class="close-x">×</button></div><div class="sec"><div class="grid"><span>SOURCE_ID</span><b>{d['id']}</b></div><div class="grid"><span>DISTANCE</span><b>{d['dist']} LY</b></div><div class="grid"><span>VELOCITY</span><b>{d['vel']} KM/S</b></div></div><div class="sec-ai"><div class="grid"><span>MSE_DEV</span><b>{d['mse']}</b></div><div class="grid"><span>KL_SURP</span><b>{d['kl']}</b></div></div><div class="status-box" style="color:{d['color']}">STATUS: [{d['status']}]</div></div>"""# ------------------------------------------------------------------------------# 6. RADAR ENGINE - ALADIN JS + DEEP FLY-TO LOGIC# ------------------------------------------------------------------------------radar_html = f"""<!DOCTYPE html><html><head><link rel="stylesheet" href="https://aladin.u-strasbg.fr/AladinLite/api/v2/latest/aladin.min.css" /><style>body,html{{margin:0;padding:0;height:100vh;width:100vw;background:black;overflow:hidden}}#radar-main{{width:100%;height:100%;position:absolute}}/* TACTICAL POPUP STYLING */.tactical-popup{{position:absolute;top:20px;right:20px;z-index:9999;background:rgba(12,12,12,0.96);border:1px solid #555;padding:12px;font-family:monospace;width:250px;color:white;border-radius:4px;box-shadow:0 10px 40px rgba(0,0,0,0.9);}}.m-head{{display:flex;justify-content:space-between;border-bottom:1px dashed #444;margin-bottom:12px;font-size:10px;font-weight:bold}}.close-x{{background:none;border:none;color:#888;cursor:pointer;font-size:22px;line-height:1}}.grid{{display:flex;justify-content:space-between;font-size:10px;margin-bottom:6px}}.sec{{margin-bottom:12px;border-bottom:1px solid #333;padding-bottom:8px}}.status-box{{text-align:center;font-weight:bold;margin-top:10px;border-top:1px solid #444;padding-top:10px;font-size:11px}}/* THE TINY PRECISION CROSSHAIR (10px) */.radar-cross{{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:10px;height:10px;border:1px solid rgba(255,255,255,0.4);border-radius:50%;z-index:998;pointer-events:none;}}.radar-cross::before, .radar-cross::after {{ content:'';position:absolute;background:rgba(255,255,255,0.8); }}.radar-cross::before {{ top:50%;left:-5px;right:-5px;height:1px; }}.radar-cross::after {{ left:50%;top:-5px;bottom:-5px;width:1px; }}.aladin-logo, .aladin-searchControl, .aladin-layers-control{{display:none!important}}</style></head><body><div id="radar-main"></div><div class="radar-cross"></div>{ui_popup}<script src="https://code.jquery.com/jquery-1.12.1.min.js"></script><script src="https://aladin.u-strasbg.fr/AladinLite/api/v2/latest/aladin.min.js"></script><script>var isNew = {'true' if st.session_state.radar_session['res'] else 'false'};var ra = {st.session_state.radar_session['ra']};var dec = {st.session_state.radar_session['dec']};// Initialize Aladin Litevar aladin = A.aladin('#radar-main', {{survey: "P/DSS2/color",fov: isNew ? 6.0 : 0.2,target: ra + " " + dec,showReticle: false, showZoomControl: true}});if(isNew){{var cat = A.catalog({{name:'Target_Lock', color:'#ffffff', shape:'plus', sourceSize:8}});aladin.addCatalog(cat); cat.addSources([A.source(ra, dec)]);// THE DEEP FLY-TO ANIMATION (Dive into target)setTimeout(function(){{aladin.setFoV(0.03);}}, 500);}}</script></body></html>"""components.html(radar_html, height=1000)# ==============================================================================# END OF CODE (TOTAL LINE COUNT: ~400)# ==============================================================================12345617 unmodified lines24252627282930313233343 unmodified lines3839404142434445464748495051525354555657585960611 unmodified line636465666768697071727374757677787980818283843 unmodified lines8889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421432 unmodified lines1461471481491501511521531541551561571581591601611621631641651663 unmodified lines170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411# ==============================================================================# SYSTEM: SADIM AI RADAR 77M - TACTICAL EXPERT INTERFACE# VERSION: 2.8.0 (STABLE DEPLOYMENT - PATH FIXED)# ==============================================================================import streamlit as st17 unmodified lines)# ------------------------------------------------------------------------------# 2. ADVANCED CSS STYLING (THE WHITE COMPACT INTERFACE)# ------------------------------------------------------------------------------st.markdown("""<style>/* Full Page Reset */html, body, [data-testid="stAppViewContainer"], [data-testid="stMainViewContainer"], .main, .block-container {padding: 0 !important;margin: 0 !important;3 unmodified linesbackground-color: #000000 !important;}/* Hide Streamlit Native UI Elements */[data-testid="stHeader"], footer {display: none !important;}/* THE WHITE SEARCH BAR CONTAINER - Compact Precision */div[data-testid="stHorizontalBlock"] {position: fixed !important;bottom: 30px !important;left: 30px !important;z-index: 100000 !important;background-color: rgba(255, 255, 255, 0.98) !important;border: 1px solid #888888 !important;padding: 5px 8px !important;border-radius: 4px !important;box-shadow: 0px 10px 30px rgba(0,0,0,0.8) !important;/* Forces the container to wrap the content exactly */width: fit-content !important;display: flex !important;flex-direction: row !important;1 unmodified linealign-items: center !important;}/* Controlling the Columns inside the white block */div[data-testid="column"] {width: auto !important;flex: none !important;min-width: 0 !important;padding: 0 !important;}/* Input Field Customization */div[data-testid="stTextInput"] {margin-bottom: 0 !important;width: 140px !important;}div[data-testid="stTextInput"] > div:first-child {display: none !important;}div[data-testid="stTextInput"] input {background-color: #ffffff !important;color: #000000 !important;3 unmodified linesfont-weight: bold !important;padding: 4px 8px !important;border-radius: 2px !important;height: 32px !important;outline: none !important;box-shadow: none !important;}/* SCAN Button - Academic Engineering Look */div[data-testid="stButton"] {margin-bottom: 0 !important;width: 70px !important;}div[data-testid="stButton"] button {background-color: #f2f2f2 !important;color: #000000 !important;border: 1px solid #999999 !important;font-family: 'Arial', sans-serif !important;font-size: 11px !important;font-weight: 900 !important;padding: 0 !important;border-radius: 2px !important;text-transform: uppercase !important;height: 32px !important;line-height: 32px !important;width: 100% !important;transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);display: block !important;}div[data-testid="stButton"] button:hover {background-color: #ffffff !important;border-color: #000000 !important;}/* Full-Screen Map Viewport Positioning */iframe {position: fixed !important;top: 0 !important;left: -1px !important;width: calc(100vw + 2px) !important;height: 100vh !important;border: none !important;margin: 0 !important;padding: 0 !important;}</style>""", unsafe_allow_html=True)# ------------------------------------------------------------------------------# 3. SADIM AI ARCHITECTURE (77 MILLION PARAMETER EXPERT ENGINE)# ------------------------------------------------------------------------------class ResidualBlock(nn.Module):def __init__(self, dim):super(ResidualBlock, self).__init__()self.ln = nn.LayerNorm(dim)2 unmodified linesnn.GELU(),nn.Linear(dim, dim))def forward(self, x):return x + self.fc(self.ln(x))class SADIM_V2_54M_Expert(nn.Module):def __init__(self, input_dim=12, latent_dim=64):super(SADIM_V2_54M_Expert, self).__init__()h = 3584self.encoder = nn.Sequential(nn.Linear(input_dim, h), nn.LayerNorm(h), nn.GELU(),nn.Linear(h, h), nn.LayerNorm(h), nn.GELU(),ResidualBlock(h), ResidualBlock(h), ResidualBlock(h))self.fc_mu = nn.Linear(h, latent_dim)self.fc_logvar = nn.Linear(h, latent_dim)self.decoder = nn.Sequential(nn.Linear(latent_dim, h), nn.GELU(),nn.Linear(h, h), nn.LayerNorm(h), nn.GELU(),3 unmodified linesdef forward(self, x):hidden = self.encoder(x)mu = self.fc_mu(hidden)logvar = torch.clamp(self.fc_logvar(hidden), -10, 10)std = torch.exp(0.5 * logvar)z = mu + torch.randn_like(std) * stdreturn self.decoder(z), mu, logvar@st.cache_resourcedef initialize_deep_ai():device = torch.device("cpu")model = SADIM_V2_54M_Expert().to(device)try:hf_token = os.environ.get("HF_TOKEN")model_path = hf_hub_download(repo_id="KilmaAI/Sadim-77M", filename="pytorch_model.bin", token=hf_token)model.load_state_dict(torch.load(model_path, map_location=device))except Exception:passmodel.eval()return model, devicemodel, device = initialize_deep_ai()# ------------------------------------------------------------------------------# 4. STELLAR DATA ENGINE (FIXED HUGGING FACE PATH)# ------------------------------------------------------------------------------@st.cache_data(show_spinner=False)def execute_stellar_scan(source_id):token = os.environ.get("HF_TOKEN")if not token:return {"error": "SYSTEM_FATAL: HF_TOKEN NOT FOUND IN SECRETS"}try:db = duckdb.connect(database=':memory:')db.execute("INSTALL httpfs; LOAD httpfs;")db.execute(f"CREATE SECRET IF NOT EXISTS tac_sec (TYPE HUGGINGFACE, TOKEN '{token}');")# السطر السحري: إضافة ** للبحث في كل المجلدات الداخلية دون أخطاءparquet_path = "hf://datasets/samfatnassi/gaia-dr3/**/*.parquet"sql_query = f"""SELECT ra, dec, pmra, pmdec, d_pc, abs_m, bp_rp, l, b, x, y, zFROM '{parquet_path}'WHERE source_id = {source_id}LIMIT 1"""dataframe = db.query(sql_query).df()db.close()except Exception as e:return {"error": f"IO_FAILURE: {str(e)}"}if dataframe.empty:return {"error": "TARGET_ID NOT FOUND IN GAIA-DR3 CATALOG"}# --- PHYSICAL DATA EXTRACTION ---row = dataframe.iloc[0]dist_pc = row['d_pc']dist_ly = dist_pc * 3.26156pm_total = math.sqrt(row['pmra']**2 + row['pmdec']**2)v_tangential = 4.74 * 1e-3 * pm_total * dist_pc# --- AI INFERENCE PIPELINE ---try:raw_vector = np.array([row['ra'], row['dec'], row['l'], row['b'],row['pmra'], row['pmdec'], row['d_pc'],row['x'], row['y'], row['z'],row['abs_m'], row['bp_rp']], dtype=np.float32)norm_v = raw_vector.copy()norm_v[0] /= 360.0; norm_v[1] /= 90.0; norm_v[2] /= 360.0; norm_v[3] /= 90.0norm_v[4] /= 500.0; norm_v[5] /= 500.0; norm_v[6] /= 10000.0norm_v[7] /= 15000.0; norm_v[8] /= 15000.0; norm_v[9] /= 15000.0input_tensor = torch.tensor(np.nan_to_num(norm_v)).unsqueeze(0).to(device)with torch.no_grad():reconstructed, mu, logvar = model(input_tensor)mse_val = torch.mean((reconstructed - input_tensor)**2).item()kl_val = -0.5 * torch.sum(1 + logvar - mu.pow(2) - logvar.exp()).item()hybrid_total = mse_val + (0.1 * kl_val)except Exception:mse_val, kl_val, hybrid_total = 0.0, 0.0, 0.0return {'id': source_id, 'ra': row['ra'], 'dec': row['dec'],'dist': round(dist_ly, 1), 'vel': round(v_tangential, 2),'mse': round(mse_val, 6), 'kl': round(kl_val, 6),'score': round(hybrid_total, 5),'status': "EXTREME ANOMALY" if hybrid_total > 5.0 else "NOMINAL (NORMAL)",'color': "#ffffff" if hybrid_total > 5.0 else "#888888"}# ------------------------------------------------------------------------------# 5. SESSION MANAGEMENT & INTERFACE BUILDER# ------------------------------------------------------------------------------if 'session' not in st.session_state:st.session_state.session = {'data': None, 'is_active': False, 'has_error': False,'error_text': "", 'ra': 269.4485, 'dec': 4.7394}search_col_1, search_col_2 = st.columns([2, 1])with search_col_1:target_sid = st.text_input("ID_SEARCH", placeholder="ENTER SOURCE_ID", label_visibility="collapsed")with search_col_2:if st.button("SCAN"):if target_sid and target_sid.isdigit():with st.spinner(""):scan_res = execute_stellar_scan(target_sid)if "error" in scan_res:st.session_state.session.update({'data': None, 'is_active': True, 'has_error': True, 'error_text': scan_res['error']})else:st.session_state.session.update({'data': scan_res, 'ra': scan_res['ra'], 'dec': scan_res['dec'], 'is_active': True, 'has_error': False})popup_html_component = ""if st.session_state.session['is_active']:state = st.session_state.sessionif state['has_error']:popup_html_component = f"""<div id="pop-win" class="tactical-popup" style="border-color:#ff3333"><div class="pop-header"><span style="color:#ff3333">! ALERT_FAILURE</span><button onclick="document.getElementById('pop-win').style.display='none'" class="pop-close">×</button></div><div style="color:#ff3333;font-size:11px;text-align:center;padding:10px;font-weight:bold">{state['error_text']}</div></div>"""elif state['data']:sd = state['data']popup_html_component = f"""<div id="pop-win" class="tactical-popup"><div class="pop-header"><span>SADIM 77M // SCAN_REPORT</span><button onclick="document.getElementById('pop-win').style.display='none'" class="pop-close">×</button></div><div class="pop-section"><div class="pop-row"><span>SOURCE_ID</span><b>{sd['id']}</b></div><div class="pop-row"><span>DIST_LY</span><b>{sd['dist']}</b></div><div class="pop-row"><span>VEL_KMS</span><b>{sd['vel']}</b></div></div><div class="pop-section-ai"><div class="pop-row"><span>MSE_DEV</span><b>{sd['mse']}</b></div><div class="pop-row"><span>KL_SURP</span><b>{sd['kl']}</b></div></div><div class="pop-status" style="color:{sd['color']}">STATUS: [{sd['status']}]</div></div>"""# ------------------------------------------------------------------------------# 6. RADAR VISUALIZER ENGINE (ALADIN LITE + FLY-TO)# ------------------------------------------------------------------------------radar_logic_html = f"""<!DOCTYPE html><html><head><link rel="stylesheet" href="https://aladin.u-strasbg.fr/AladinLite/api/v2/latest/aladin.min.css" /><style>body, html {{ margin:0; padding:0; height:100vh; width:100vw; background: black; overflow:hidden; }}#radar-canvas {{ width:100%; height:100%; position:absolute; top:0; left:0; }}.tactical-popup {{position: absolute; top: 25px; right: 25px; z-index: 9999;background: rgba(10, 10, 10, 0.97); border: 1px solid #444;padding: 15px; font-family: 'Courier New', Courier, monospace; width: 260px;color: white; border-radius: 4px; box-shadow: 0 10px 50px rgba(0,0,0,1);}}.pop-header {{display: flex; justify-content: space-between; align-items: center;border-bottom: 1px dashed #555; margin-bottom: 12px;font-size: 10px; font-weight: bold; letter-spacing: 1px; color: #aaa;}}.pop-close {{background: none; border: none; color: #777; cursor: pointer;font-size: 24px; line-height: 1; padding: 0;}}.pop-close:hover {{ color: white; }}.pop-row {{ display: flex; justify-content: space-between; font-size: 10px; margin-bottom: 6px; }}.pop-row span {{ color: #777; }}.pop-section {{ margin-bottom: 12px; border-bottom: 1px solid #333; padding-bottom: 8px; }}.pop-section-ai {{ margin-bottom: 12px; }}.pop-status {{text-align: center; font-weight: bold; margin-top: 10px;border-top: 1px solid #444; padding-top: 12px; font-size: 11px; letter-spacing: 2px;}}/* PRECISION CROSSHAIR - Ultra Tiny (10px) */.radar-crosshair {{position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);width: 10px; height: 10px; border: 1px solid rgba(255,255,255,0.4); border-radius: 50%;z-index: 9998; pointer-events: none;}}.radar-crosshair::before, .radar-crosshair::after {{content: ''; position: absolute; background: rgba(255,255,255,0.9);}}.radar-crosshair::before {{ top: 50%; left: -4px; right: -4px; height: 1px; }}.radar-crosshair::after {{ left: 50%; top: -4px; bottom: -4px; width: 1px; }}.aladin-logo, .aladin-searchControl, .aladin-layers-control {{ display: none !important; }}</style></head><body><div id="radar-canvas"></div><div class="radar-crosshair"></div>{popup_html_component}<script src="https://code.jquery.com/jquery-1.12.1.min.js"></script><script src="https://aladin.u-strasbg.fr/AladinLite/api/v2/latest/aladin.min.js"></script><script>var scanActive = {'true' if st.session_state.session['data'] else 'false'};var t_ra = {st.session_state.session['ra']};var t_dec = {st.session_state.session['dec']};var tactical_radar = A.aladin('#radar-canvas', {{survey: "P/DSS2/color",fov: scanActive ? 8.0 : 0.2,target: t_ra + " " + t_dec,showReticle: false,showLayersControl: true,showZoomControl: true}});if(scanActive){{var targetLayer = A.catalog({{name:'LOCK_ON', color:'#ffffff', shape:'plus', sourceSize:10}});tactical_radar.addCatalog(targetLayer);targetLayer.addSources([A.source(t_ra, t_dec)]);// THE FLY-TO ANIMATIONsetTimeout(function(){{tactical_radar.setFoV(0.04);}}, 600);}}</script></body></html>"""components.html(radar_logic_html, height=1000)# ==============================================================================# END OF CODE# ==============================================================================
app.py+241-190