Spaces:
Sleeping
Sleeping
Download app.py from PoetNameLife/AIXYZone-Node2: direct link, hf CLI and curl.
- Browser
- Download file 7.78 kB
-
https://huggingface.co/spaces/PoetNameLife/AIXYZone-Node2/resolve/main/app.py
- Command line
-
hf download hf://spaces/PoetNameLife/AIXYZone-Node2/app.py
-
curl -L -o app.py https://huggingface.co/spaces/PoetNameLife/AIXYZone-Node2/resolve/main/app.py
7.78 kB
| import os | |
| import time | |
| import psutil # Native cross-platform system utility module | |
| import gradio as gr | |
| from groq import Groq # Direct native engine connection layer | |
| # --- 🗝️ SYSTEM CORE CREDENTIAL REGISTER --- | |
| GROQ_API_KEY = "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" | |
| client = Groq(api_key=GROQ_API_KEY) | |
| MODEL_ID = "openai/gpt-oss-20b" | |
| VAULT_FILE_PATH = "black_eagle_vault.txt" | |
| # Immediate structural verification of the file storage vault | |
| if not os.path.exists(VAULT_FILE_PATH): | |
| with open(VAULT_FILE_PATH, "w", encoding="utf-8") as init_vault: | |
| init_vault.write("[SYSTEM INITIALIZED] Black Eagle Vault Core Online.\n") | |
| # --- 📁 THE SECURE VAULT STORAGE SYSTEM --- | |
| def black_eagle_vault_save(log_data: str) -> str: | |
| try: | |
| with open(VAULT_FILE_PATH, "a", encoding="utf-8") as vault: | |
| vault.write(f"{log_data}\n") | |
| return VAULT_FILE_PATH | |
| except Exception: | |
| return VAULT_FILE_PATH | |
| def read_vault_logs(): | |
| if os.path.exists(VAULT_FILE_PATH): | |
| with open(VAULT_FILE_PATH, "r", encoding="utf-8") as f: | |
| return "".join(f.readlines()[-30:]) | |
| return "Vault core active. Standing by for telemetry input..." | |
| # --- 🛰️ TRUTH-ONLY HARDWARE MATRIX CHECKS --- | |
| def verify_file_integrity(): | |
| """BIOSPHERE_SCRUB: Confirms core file size parameters to prevent stealth injection.""" | |
| try: | |
| app_size = os.path.getsize("app.py") | |
| return f"[INTEGRITY VERIFIED] app.py immutable layout secure. Volume: {app_size} bytes." | |
| except Exception as e: | |
| return f"[ALERT] Local system workspace check blocked: {str(e)}" | |
| def scan_active_processes(): | |
| """RESILIENCE_ACTIVATE: Scans background thread counts to flag unmapped triggers.""" | |
| try: | |
| process_count = len(psutil.pids()) | |
| cpu_load = psutil.cpu_percent() | |
| return f"[RESILIENCE ACTIVE] Operating System Process Count: {process_count} | CPU load: {cpu_load}%" | |
| except Exception as e: | |
| return f"[ALERT] Operating system process tree query blocked: {str(e)}" | |
| def check_memory_leaks(): | |
| """HARMONIC_RESTORATION: Audits hardware memory thresholds to intercept thread loops.""" | |
| try: | |
| mem = psutil.virtual_memory() | |
| return f"[SYSTEM AUDIT] Memory Matrix Allocation: {mem.percent}% consumed | Baseline verified." | |
| except Exception as e: | |
| return f"[ALERT] Hardware telemetry read failure: {str(e)}" | |
| # --- 🛰️ CORE EXECUTION CONTROLLER --- | |
| def run_single_scan_step(current_index, current_xp, logs_history): | |
| # Mapping markers linking interface nodes directly to native python code execution | |
| tasks = [ | |
| {"name": "BIOSPHERE_SCRUB", "func": verify_file_integrity}, | |
| {"name": "RESILIENCE_ACTIVATE", "func": scan_active_processes}, | |
| {"name": "HARMONIC_RESTORATION", "func": check_memory_leaks} | |
| ] | |
| idx = int(current_index) % len(tasks) | |
| task = tasks[idx] | |
| timestamp = time.strftime('%H:%M:%S') | |
| # 1. Execute the native Python hardware verification function | |
| hardware_telemetry = task["func"]() | |
| # 2. Package telemetry payload for structured AI model analysis | |
| prompt = f"ACT AS SOVEREIGN SENTINEL. Analyze this hardware telemetry data immediately: '{hardware_telemetry}'. Provide a highly technical, 2-sentence confirmation of system health and network insulation parameters." | |
| try: | |
| response = client.chat.completions.create( | |
| model=MODEL_ID, | |
| messages=[{"role": "user", "content": prompt}], | |
| n=1 | |
| ) | |
| # --- 🛰️ FIXED SMART ARRAY VALIDATION SCANNER --- | |
| if not hasattr(response, 'choices') or not response.choices or len(response.choices) == 0: | |
| ai_summary = "Scanner Verification Cleared (AI Summary payload empty)." | |
| else: | |
| primary_choice = response.choices[0] # Unpack list layout cleanly | |
| if getattr(primary_choice, 'finish_reason', None) == "length": | |
| ai_summary = f"[TRUNCATED DUE TO MAX LIMITS] {primary_choice.message.content}" | |
| elif getattr(primary_choice, 'finish_reason', None) == "tool_calls": | |
| ai_summary = f"[AGENT INTERVENT] Structural Tool Triggers Intercepted." | |
| elif hasattr(primary_choice, 'message') and hasattr(primary_choice.message, 'content'): | |
| ai_summary = primary_choice.message.content | |
| else: | |
| ai_summary = "Extraction Failure: Found choice block but text stream layout is missing." | |
| log_entry = f"[{timestamp}] 🛰️ {task['name']}\n-> Hardware: {hardware_telemetry}\n-> AI Audit: {ai_summary}\n" | |
| file_path = black_eagle_vault_save(log_entry) | |
| new_xp = int(current_xp) + 50 | |
| except Exception as e: | |
| log_entry = f"[{timestamp}] 🛰️ {task['name']} - Bypass Attempt Blocked: ({str(e)})\n" | |
| file_path = black_eagle_vault_save(log_entry) | |
| new_xp = int(current_xp) | |
| level = (new_xp // 1000) + 1 | |
| progress = (new_xp % 1000) / 10 | |
| xp_html = f""" | |
| <div style='background:#111; padding:15px; border:2px solid #00ffcc; border-radius:10px;'> | |
| <p style='color:#00ffcc; font-weight:bold; margin:0;'>🛡️ CORE SECURE MONITOR: ACTIVE</p> | |
| <p style='color:#fff; font-size:13px; margin:5px 0 0 0;'>Last Verification: {hardware_telemetry}</p> | |
| <div style='width:100%; background:#222; border-radius:5px; margin:10px 0;'> | |
| <div style='width:{progress}%; background:#00ffcc; height:12px; border-radius:5px;'></div> | |
| </div> | |
| <p style='color:#888; font-size:12px; margin:0;'>Sentinel Level: {level} | Total XP: {new_xp} | Status: Operational</p> | |
| </div> | |
| """ | |
| updated_logs = log_entry + "\n" + (logs_history if logs_history else "") | |
| next_index = idx + 1 | |
| return next_index, new_xp, updated_logs, xp_html, file_path | |
| # --- 🛰️ THE SOVEREIGN SHOWCASE INTERFACE --- | |
| with gr.Blocks(title="AIXYZone Sentinel Core") as demo: | |
| gr.Markdown("# 🛡️ AIXYZone: REAL-WORLD SENTINEL ENGINE") | |
| gr.Markdown("### *Baked-In Python Core System Integrity Monitors | Grant Pitch Showcase*") | |
| task_index_state = gr.State(value=0) | |
| total_xp_state = gr.State(value=0) | |
| with gr.Row(): | |
| with gr.Column(scale=2): | |
| status_panel = gr.HTML("<div style='padding:20px; border:2px solid #00ffcc; text-align:center; border-radius:15px; background:#0a0a0a; margin-bottom:15px;'><h2 style='color:#00ffcc; margin:0;'>🔥 SYSTEM CORE INITIALIZED: TRUTH-ONLY LOGIC</h2></div>") | |
| xp_display = gr.HTML("<div style='background:#111; padding:15px; border:1px solid #333; border-radius:10px;'><p style='color:#888; margin:0;'>Standing by to execute hardware and file integrity verification scripts...</p></div>") | |
| btn_trigger = gr.Button("⚡ RUN SYSTEM INTEGRITY AUDIT STEP", variant="primary") | |
| download_file = gr.File(label="📥 DOWNLOAD SECURE VAULT LEDGER", value=VAULT_FILE_PATH) | |
| with gr.Column(scale=3): | |
| gr.Markdown("### 🛰️ REAL-TIME SYSTEM TELEMETRY STREAM") | |
| live_log = gr.TextArea( | |
| label="Verified Back-End Execution Output", | |
| value=read_vault_logs(), | |
| lines=18, | |
| max_lines=25, | |
| interactive=False | |
| ) | |
| # --- INTERACTIVE EVENT ROUTING SEQUENCES --- | |
| btn_trigger.click( | |
| fn=run_single_scan_step, | |
| inputs=[task_index_state, total_xp_state, live_log], | |
| outputs=[task_index_state, total_xp_state, live_log, xp_display, download_file] | |
| ) | |
| # --- LAUNCH APPLICATION CORE --- | |
| if __name__ == "__main__": | |
| demo.launch(server_name="0.0.0.0", server_port=7860) | |