Spaces:
Paused
Paused
| import os | |
| import sys | |
| import gc | |
| import time | |
| import psutil | |
| import shutil | |
| import transformers.utils | |
| import gradio as gr | |
| # --- 1. SOVEREIGN PURGE & MONITOR --- | |
| def sovereign_init(): | |
| process = psutil.Process(os.getpid()) | |
| print(f"--- 🛡️ AIXYZone HARDWARE REPORT ---") | |
| print(f"Active Process ID: {os.getpid()}") | |
| print(f"Real Memory Usage: {process.memory_info().rss / 1024 / 1024:.2f} MB") | |
| # Force-clear Python's cache to load your new agents.py | |
| for module in ['agents', 'transformers', 'smolagents']: | |
| if module in sys.modules: del sys.modules[module] | |
| # Purge local cache to bypass stuck "Payment Required" states | |
| cache_dir = os.path.expanduser("~/.cache/huggingface") | |
| if os.path.exists(cache_dir): shutil.rmtree(cache_dir, ignore_errors=True) | |
| gc.collect() | |
| print("XYZ System: Total State Purge Complete.") | |
| print(f"----------------------------------", flush=True) | |
| sovereign_init() | |
| # --- 2. ENVIRONMENT HEALERS --- | |
| if not hasattr(transformers.utils, 'is_offline_mode'): | |
| transformers.utils.is_offline_mode = lambda: False | |
| # Fixes the 'is_soundfile_availble' typo in the smolagents library | |
| if not hasattr(transformers.utils, 'is_soundfile_availble'): | |
| transformers.utils.is_soundfile_availble = lambda: False | |
| print("XYZ System: Library Typo Healed.") | |
| from agents import nano_patrol_agent | |
| # --- 3. SENTINEL LOGIC --- | |
| def run_autonomous_scrub(iterations): | |
| history = [] | |
| bci_range = "3.4GHz - 4.2GHz (BCI/Neural Feedback)" | |
| for i in range(int(iterations)): | |
| prompt = f"ACT AS BCI SENTINEL: Scan {bci_range}. Neutralize loops and generate a Healed Nano Node JSON." | |
| try: | |
| # The agent uses your new HF_TOKEN/HF_HUB_TOKEN automatically | |
| result = nano_patrol_agent.run(prompt) | |
| history.append(f"[{time.strftime('%H:%M:%S')}] 🛰️ SENTINEL ACTION: {result}") | |
| except Exception as e: | |
| history.append(f"LOG ERROR: {str(e)}") | |
| yield "\n\n".join(history[::-1]) | |
| time.sleep(2) | |
| # --- 4. UI DESIGN --- | |
| with gr.Blocks(title="AIXYZone - BCI Nano Sentinel") as demo: | |
| gr.Markdown("# 🛡️ AIXYZone: Autonomous BCI Sentinel") | |
| with gr.Row(): | |
| with gr.Column(): | |
| sweep_count = gr.Slider(minimum=1, maximum=50, value=10, label="Autonomous Scrub Depth") | |
| btn_sentinel = gr.Button("🛰️ ACTIVATE SENTINEL SCAN", variant="primary") | |
| with gr.Column(): | |
| sentinel_log = gr.Textbox(label="Live Healing Stream", lines=25) | |
| btn_sentinel.click(fn=run_autonomous_scrub, inputs=[sweep_count], outputs=[sentinel_log]) | |
| if __name__ == "__main__": | |
| demo.launch() | |