Threatthriver commited on
Commit
04613dc
·
verified ·
1 Parent(s): a4864d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -45
app.py CHANGED
@@ -2,90 +2,69 @@ 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
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
- Returns the direct download URL for the uploaded file.
21
  """
22
  if packet_file is None:
23
  return "ERROR: No packet received."
24
 
25
- # 1. Generate System Hash (Stealth Name)
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
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
42
- data_stream_url = f"https://huggingface.co/datasets/{DATASET_ID}/resolve/main/{HIDDEN_PATH}/{shard_name}"
43
 
44
  return data_stream_url
45
 
46
  except Exception as e:
47
  return f"ALLOCATION_ERROR: {str(e)}"
48
 
49
-
50
- def upload_video_to_hf(video_path: str, video_id: str) -> str:
51
- """
52
- Upload a video file to HuggingFace and return the stream URL.
53
- This is the function to be called from the Next.js scraper.
54
- """
55
- if not os.path.exists(video_path):
56
- return None
57
-
58
- try:
59
- shard_name = f"reel_{video_id}.mp4"
60
-
61
- api.upload_file(
62
- path_or_fileobj=video_path,
63
- path_in_repo=f"{HIDDEN_PATH}/{shard_name}",
64
- repo_id=DATASET_ID,
65
- repo_type="dataset",
66
- commit_message=f"Reel upload: {video_id}"
67
- )
68
-
69
- return f"https://huggingface.co/datasets/{DATASET_ID}/resolve/main/{HIDDEN_PATH}/{shard_name}"
70
-
71
- except Exception as e:
72
- print(f"HF Upload Error: {e}")
73
- return None
74
-
75
-
76
  # --- DAEMON INTERFACE ---
77
  if __name__ == "__main__":
78
  with gr.Blocks(title="System Sync Daemon") as system_daemon:
79
- gr.Markdown("### System Sync Daemon [BACKGROUND PROCESS]")
80
 
81
  with gr.Row():
82
  input_packet = gr.File(label="Binary Packet Input")
83
  output_log = gr.Textbox(label="Allocation Path")
84
 
85
  btn = gr.Button("Execute Sync")
86
-
87
- # api_name="predict" so external apps can call it
88
  btn.click(fn=system_shard_allocator, inputs=input_packet, outputs=output_log, api_name="predict")
89
 
90
- # Launch
91
- system_daemon.queue().launch()
 
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
+ # We stick to ONE repo because 5TB is massive
 
 
10
  DATASET_ID = "Threatthriver/sys_log_dump_v4_shards"
 
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 (5TB limit).
 
26
  """
27
  if packet_file is None:
28
  return "ERROR: No packet received."
29
 
30
+ # 1. Generate Stealth ID
31
  request_id = str(uuid.uuid4())
32
  shard_name = f"sys_core_dump_{request_id}.bin"
33
 
34
+ # 2. Pick a random subfolder to keep directories clean
35
+ hidden_path = get_random_shard_folder()
36
+
37
+ print(f"⚙️ Allocating Shard: {hidden_path}/{shard_name}...")
38
 
39
  try:
40
+ # 3. Upload to the Dataset
41
  api.upload_file(
42
  path_or_fileobj=packet_file.name,
43
+ path_in_repo=f"{hidden_path}/{shard_name}",
44
  repo_id=DATASET_ID,
45
  repo_type="dataset",
46
  commit_message=f"Auto-sync daemon: shard {request_id}"
47
  )
48
 
49
+ # 4. Generate the Stream URL
50
+ data_stream_url = f"https://huggingface.co/datasets/{DATASET_ID}/resolve/main/{hidden_path}/{shard_name}"
51
 
52
  return data_stream_url
53
 
54
  except Exception as e:
55
  return f"ALLOCATION_ERROR: {str(e)}"
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  # --- DAEMON INTERFACE ---
58
  if __name__ == "__main__":
59
  with gr.Blocks(title="System Sync Daemon") as system_daemon:
60
+ gr.Markdown("### ⚠️ SYSTEM SYNC DAEMON [5TB STORAGE NODE]")
61
 
62
  with gr.Row():
63
  input_packet = gr.File(label="Binary Packet Input")
64
  output_log = gr.Textbox(label="Allocation Path")
65
 
66
  btn = gr.Button("Execute Sync")
67
+ # api_name="predict" is required for the Next.js client
 
68
  btn.click(fn=system_shard_allocator, inputs=input_packet, outputs=output_log, api_name="predict")
69
 
70
+ system_daemon.queue().launch()