Nomad1775's picture
Deploy ViperGearLab analyst portal and database sync
7908c39
Raw History Blame Contribute Delete
3.49 kB
import os
import json
from datetime import datetime, timezone
import requests
import gradio as gr
from huggingface_hub import HfApi, hf_hub_download
HF_TOKEN = os.environ.get("HF_TOKEN", "")
DATASET_REPO = os.environ.get("HF_DATASET_REPO", "your_hf_username/ViperGearLab-Analyst-DB")
GUMROAD_PRODUCT_ID = os.environ.get("GUMROAD_PRODUCT_ID", "your_gumroad_product_id")
DB_FILENAME = "analyst_intel.jsonl"
api = HfApi(token=HF_TOKEN)
def verify_gumroad_license(license_key: str) -> tuple[bool, str]:
if not license_key.strip():
return False, "Missing license key."
try:
resp = requests.post(
"https://api.gumroad.com/v2/licenses/verify",
data={
"product_id": GUMROAD_PRODUCT_ID,
"license_key": license_key.strip(),
"increment_uses_count": "false"
},
timeout=10
)
data = resp.json()
if data.get("success") and not data.get("purchase", {}).get("refunded"):
email = data["purchase"].get("email", "Verified Operator")
return True, f"Authenticated: {email}"
return False, "Invalid or expired Gumroad license key."
except Exception as e:
return False, f"Verification error: {e}"
def fetch_database_records() -> list[dict]:
try:
local_path = hf_hub_download(
repo_id=DATASET_REPO,
filename=DB_FILENAME,
repo_type="dataset",
token=HF_TOKEN
)
with open(local_path, "r", encoding="utf-8") as f:
return [json.loads(line) for line in f if line.strip()]
except Exception:
return []
def submit_analyst_entry(license_key: str, handle: str, category: str, payload: str) -> str:
valid, msg = verify_gumroad_license(license_key)
if not valid:
return f"[ACCESS DENIED] {msg}"
records = fetch_database_records()
entry = {
"timestamp": datetime.now(timezone.utc).isoformat(),
"analyst": handle.strip() or "Anonymous",
"category": category,
"payload": payload.strip()
}
records.append(entry)
with open(DB_FILENAME, "w", encoding="utf-8") as f:
for r in records:
f.write(json.dumps(r) + "\n")
api.upload_file(
path_or_fileobj=DB_FILENAME,
path_in_repo=DB_FILENAME,
repo_id=DATASET_REPO,
repo_type="dataset",
commit_message=f"Update from {entry['analyst']} [{category}]"
)
return json.dumps(records[-10:], indent=2)
with gr.Blocks(title="ViperGearLab Analyst Hub") as demo:
gr.Markdown("### ViperGearLab // Shared Analyst Database & Telemetry Node")
license_input = gr.Textbox(label="Gumroad License Key", type="password")
with gr.Row():
handle_input = gr.Textbox(label="Analyst Callsign / Handle")
category_input = gr.Dropdown(
choices=["Benchmark", "Script Patch", "Hardware Config", "Field Telemetry"],
value="Script Patch",
label="Module Category"
)
payload_input = gr.Textbox(label="Technical Finding / Config Snippet", lines=4)
submit_btn = gr.Button("Verify License & Commit to Database")
output_log = gr.Code(label="Latest Shared Analyst Entries (JSON)", language="json")
submit_btn.click(
fn=submit_analyst_entry,
inputs=[license_input, handle_input, category_input, payload_input],
outputs=output_log
)
if __name__ == "__main__":
demo.launch()