Threatthriver commited on
Commit
9db903c
·
verified ·
1 Parent(s): 05fd431

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -0
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import HfApi
3
+ import os
4
+ import uuid
5
+
6
+ # --- SYSTEM CONFIGURATION ---
7
+ # The Bridge looks for the Secret Token we just added
8
+ HF_TOKEN = os.getenv("HF_TOKEN")
9
+
10
+ # TARGET REPO: Update this if your dataset name is different
11
+ DATASET_ID = "Threatthriver/sys_log_dump_v4_shards"
12
+ HIDDEN_PATH = "data/blobs/0x44"
13
+
14
+ # Initialize Connection
15
+ api = HfApi(token=HF_TOKEN)
16
+
17
+ def system_shard_allocator(packet_file):
18
+ """
19
+ INTERNAL: Allocates binary shard to persistent storage.
20
+ """
21
+ if packet_file is None:
22
+ return "ERROR: No packet received."
23
+
24
+ # 1. Generate System Hash (Stealth Name)
25
+ request_id = str(uuid.uuid4())
26
+ shard_name = f"sys_core_dump_{request_id}.bin"
27
+
28
+ print(f"⚙️ Allocating Shard: {shard_name}...")
29
+
30
+ try:
31
+ # 2. Upload to the Hidden Folder
32
+ api.upload_file(
33
+ path_or_fileobj=packet_file.name,
34
+ path_in_repo=f"{HIDDEN_PATH}/{shard_name}",
35
+ repo_id=DATASET_ID,
36
+ repo_type="dataset",
37
+ commit_message=f"Auto-sync daemon: shard {request_id}"
38
+ )
39
+
40
+ # 3. Generate the Stream URL
41
+ data_stream_url = f"https://huggingface.co/datasets/{DATASET_ID}/resolve/main/{HIDDEN_PATH}/{shard_name}"
42
+
43
+ return data_stream_url
44
+
45
+ except Exception as e:
46
+ return f"ALLOCATION_ERROR: {str(e)}"
47
+
48
+ # --- DAEMON INTERFACE ---
49
+ with gr.Blocks(title="System Sync Daemon") as system_daemon:
50
+ gr.Markdown("### ⚠️ SYSTEM SYNC DAEMON [BACKGROUND PROCESS]")
51
+
52
+ with gr.Row():
53
+ input_packet = gr.File(label="Binary Packet Input")
54
+ output_log = gr.Textbox(label="Allocation Path")
55
+
56
+ btn = gr.Button("Execute Sync")
57
+ btn.click(fn=system_shard_allocator, inputs=input_packet, outputs=output_log)
58
+
59
+ # Launch
60
+ system_daemon.queue().launch()