Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,52 +2,44 @@ import gradio as gr
|
|
| 2 |
from huggingface_hub import HfApi
|
| 3 |
import os
|
| 4 |
import uuid
|
| 5 |
-
import random
|
| 6 |
|
| 7 |
# --- SYSTEM CONFIGURATION ---
|
|
|
|
| 8 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# Initialize Connection
|
| 13 |
api = HfApi(token=HF_TOKEN)
|
| 14 |
|
| 15 |
-
def get_random_shard_folder():
|
| 16 |
-
"""
|
| 17 |
-
Returns a random hex folder (0x00 to 0xFF).
|
| 18 |
-
This spreads files across 256 folders to prevent Git lag.
|
| 19 |
-
"""
|
| 20 |
-
shard_id = random.randint(0, 255)
|
| 21 |
-
return f"data/blobs/0x{shard_id:02x}"
|
| 22 |
-
|
| 23 |
def system_shard_allocator(packet_file):
|
| 24 |
"""
|
| 25 |
-
Allocates binary shard to persistent storage
|
| 26 |
"""
|
| 27 |
if packet_file is None:
|
| 28 |
return "ERROR: No packet received."
|
| 29 |
|
| 30 |
-
# 1. Generate Stealth
|
|
|
|
| 31 |
request_id = str(uuid.uuid4())
|
| 32 |
shard_name = f"sys_core_dump_{request_id}.bin"
|
| 33 |
|
| 34 |
-
|
| 35 |
-
hidden_path = get_random_shard_folder()
|
| 36 |
-
|
| 37 |
-
print(f"⚙️ Allocating Shard: {hidden_path}/{shard_name}...")
|
| 38 |
|
| 39 |
try:
|
| 40 |
-
#
|
| 41 |
api.upload_file(
|
| 42 |
path_or_fileobj=packet_file.name,
|
| 43 |
-
path_in_repo=f"{
|
| 44 |
repo_id=DATASET_ID,
|
| 45 |
repo_type="dataset",
|
| 46 |
commit_message=f"Auto-sync daemon: shard {request_id}"
|
| 47 |
)
|
| 48 |
|
| 49 |
-
#
|
| 50 |
-
data_stream_url = f"https://huggingface.co/datasets/{DATASET_ID}/resolve/main/{
|
| 51 |
|
| 52 |
return data_stream_url
|
| 53 |
|
|
@@ -55,16 +47,18 @@ def system_shard_allocator(packet_file):
|
|
| 55 |
return f"ALLOCATION_ERROR: {str(e)}"
|
| 56 |
|
| 57 |
# --- DAEMON INTERFACE ---
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
|
|
|
| 69 |
|
| 70 |
-
|
|
|
|
|
|
| 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: Your specific dataset
|
| 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 |
+
# We rename the video to look like a system dump file ending in .bin
|
| 26 |
request_id = str(uuid.uuid4())
|
| 27 |
shard_name = f"sys_core_dump_{request_id}.bin"
|
| 28 |
|
| 29 |
+
print(f"⚙️ Allocating Shard: {shard_name}...")
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
try:
|
| 32 |
+
# 2. Upload to the Hidden Folder in the Dataset
|
| 33 |
api.upload_file(
|
| 34 |
path_or_fileobj=packet_file.name,
|
| 35 |
+
path_in_repo=f"{HIDDEN_PATH}/{shard_name}",
|
| 36 |
repo_id=DATASET_ID,
|
| 37 |
repo_type="dataset",
|
| 38 |
commit_message=f"Auto-sync daemon: shard {request_id}"
|
| 39 |
)
|
| 40 |
|
| 41 |
+
# 3. Generate the Stream URL (Using 'resolve' for direct streaming)
|
| 42 |
+
data_stream_url = f"https://huggingface.co/datasets/{DATASET_ID}/resolve/main/{HIDDEN_PATH}/{shard_name}"
|
| 43 |
|
| 44 |
return data_stream_url
|
| 45 |
|
|
|
|
| 47 |
return f"ALLOCATION_ERROR: {str(e)}"
|
| 48 |
|
| 49 |
# --- DAEMON INTERFACE ---
|
| 50 |
+
with gr.Blocks(title="System Sync Daemon") as system_daemon:
|
| 51 |
+
gr.Markdown("### ⚠️ SYSTEM SYNC DAEMON [BACKGROUND PROCESS]")
|
| 52 |
+
|
| 53 |
+
with gr.Row():
|
| 54 |
+
input_packet = gr.File(label="Binary Packet Input")
|
| 55 |
+
output_log = gr.Textbox(label="Allocation Path")
|
| 56 |
+
|
| 57 |
+
btn = gr.Button("Execute Sync")
|
| 58 |
+
|
| 59 |
+
# --- CRITICAL FIX: api_name="predict" ---
|
| 60 |
+
# This allows your Next.js client to call client.predict("/predict", ...)
|
| 61 |
+
btn.click(fn=system_shard_allocator, inputs=input_packet, outputs=output_log, api_name="predict")
|
| 62 |
|
| 63 |
+
# Launch
|
| 64 |
+
system_daemon.queue().launch()
|