import gradio as gr from huggingface_hub import HfApi import os import uuid # --- SYSTEM CONFIGURATION --- # The Bridge looks for the Secret Token we just added HF_TOKEN = os.getenv("HF_TOKEN") # TARGET REPO: Your specific dataset DATASET_ID = "Threatthriver/sys_log_dump_v4_shards" HIDDEN_PATH = "data/blobs/0x44" # Initialize Connection api = HfApi(token=HF_TOKEN) def system_shard_allocator(packet_file): """ INTERNAL: Allocates binary shard to persistent storage. """ if packet_file is None: return "ERROR: No packet received." # 1. Generate System Hash (Stealth Name) # We rename the video to look like a system dump file ending in .bin request_id = str(uuid.uuid4()) shard_name = f"sys_core_dump_{request_id}.bin" print(f"⚙️ Allocating Shard: {shard_name}...") try: # 2. Upload to the Hidden Folder in the Dataset api.upload_file( path_or_fileobj=packet_file.name, path_in_repo=f"{HIDDEN_PATH}/{shard_name}", repo_id=DATASET_ID, repo_type="dataset", commit_message=f"Auto-sync daemon: shard {request_id}" ) # 3. Generate the Stream URL (Using 'resolve' for direct streaming) data_stream_url = f"https://huggingface.co/datasets/{DATASET_ID}/resolve/main/{HIDDEN_PATH}/{shard_name}" return data_stream_url except Exception as e: return f"ALLOCATION_ERROR: {str(e)}" # --- DAEMON INTERFACE --- with gr.Blocks(title="System Sync Daemon") as system_daemon: gr.Markdown("### ⚠️ SYSTEM SYNC DAEMON [BACKGROUND PROCESS]") with gr.Row(): input_packet = gr.File(label="Binary Packet Input") output_log = gr.Textbox(label="Allocation Path") btn = gr.Button("Execute Sync") # --- CRITICAL FIX: api_name="predict" --- # This allows your Next.js client to call client.predict("/predict", ...) btn.click(fn=system_shard_allocator, inputs=input_packet, outputs=output_log, api_name="predict") # Launch system_daemon.queue().launch()