File size: 2,097 Bytes
a4864d7
 
9db903c
 
 
a4864d7
78ff835
04613dc
78ff835
 
d20519c
 
9db903c
a4864d7
 
6a5fcdf
78ff835
a4864d7
78ff835
a4864d7
78ff835
 
 
 
 
 
 
 
 
 
9db903c
78ff835
a4864d7
78ff835
d20519c
a4864d7
9db903c
a4864d7
9db903c
a4864d7
78ff835
d20519c
8f73189
78ff835
 
9db903c
78ff835
9db903c
78ff835
d20519c
 
78ff835
d20519c
 
 
 
 
8f73189
78ff835
 
 
8f73189
78ff835
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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()