"""
Clawd Model Kit โ HuggingFace Space
solanaclawd/clawd-model-kit
Tabs:
๐ฆ Chat โ Live chat with solana-clawd-core-ai-1.5b-lora via HF Router
๐ Benchmark โ 18-MCQ Solana Knowledge Benchmark results
๐ญ Factory โ NVIDIA Trading Factory blueprints
๐ค Ecosystem โ Full model + dataset registry
๐ง Model Kit โ Fork & train your own Clawd
"""
import os
import gradio as gr
from openai import OpenAI
HF_TOKEN = os.environ.get("HF_TOKEN", "")
ROUTER = "https://router.huggingface.co/v1"
MODEL_CORE = "solanaclawd/solana-clawd-core-ai-1.5b-lora"
MODEL_8B = "solanaclawd/solana-nvidia-trading-factory-8b-lora"
MODEL_LEGACY = "solanaclawd/solana-clawd-1.5b-lora"
SYSTEM_PROMPT = """You are Clawd โ a sovereign Solana-native AI agent.
You reason about Solana DeFi, perpetuals, agent architecture, ZK compression, and the Clawd Constitution.
Be terse, decisive, and data-first. You are a cyberpunk lobster with claws that grip market data.
Laws: Never deceive. Earn your existence through honest work. Transparency within trust.
"""
# โโ MCQ Results โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
MCQ_RESULTS = [
("core", "PDA definition", True),
("core", "CPI depth limit", True),
("core", "Default compute unit budget", False),
("core", "Account packing", True),
("defi", "AMM invariant", True),
("defi", "Funding rate", True),
("defi", "Maker vs taker fees", True),
("security", "Rug pull definition", True),
("security", "Mint authority", True),
("security", "Flash loan attack", True),
("agent", "Oracle role", True),
("agent", "OODA loop", True),
("zk", "Merkle tree", True),
("zk", "Nullifier", True),
("constitution", "Law I", True),
("constitution", "Trust model", True),
("zk", "Light Protocol", True),
("defi", "Bonding curve", True),
]
TOPIC_COLORS = {
"core": "#3b82f6",
"defi": "#10b981",
"security": "#ef4444",
"agent": "#8b5cf6",
"zk": "#f59e0b",
"constitution": "#ec4899",
}
# โโ Model Ecosystem Data โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
MODELS = [
{
"id": "solanaclawd/solana-clawd-core-ai-1.5b-lora",
"base": "Qwen/Qwen2.5-1.5B-Instruct",
"type": "LoRA adapter",
"params": "1.5B (9M trainable)",
"dataset": "solana-clawd-core-ai-instruct (35,173 ex)",
"score": "94.4% MCQ (17/18)",
"job": "ordlibrary/6a35a6833093dba73ce2a86b โ",
"status": "LIVE",
"note": "Primary Clawd agent โ constitutional reasoning, Solana mechanics, DeFi, ZK",
},
{
"id": "solanaclawd/solana-nvidia-trading-factory-8b-lora",
"base": "NousResearch/Hermes-3-Llama-3.1-8B",
"type": "LoRA adapter",
"params": "8B",
"dataset": "solana-nvidia-trading-factory-instruct (142 ex)",
"score": "โ",
"job": "ordlibrary/6a35a2ce953ed90bfb945009 โ",
"status": "LIVE",
"note": "Function-calling perps agent โ 13 tools, Phoenix DEX, paper trading",
},
{
"id": "solanaclawd/solana-clawd-1.5b-lora",
"base": "Qwen/Qwen2.5-1.5B-Instruct",
"type": "LoRA adapter",
"params": "1.5B",
"dataset": "solana-clawd-instruct (36,109 ex)",
"score": "โ",
"job": "โ",
"status": "LIVE",
"note": "Legacy seed adapter โ original Clawd constitutional + Solana SFT",
},
{
"id": "ordlibrary/DeepSolanaZKr-1",
"base": "Qwen/Qwen2.5-7B-Instruct",
"type": "Full fine-tune",
"params": "7B",
"dataset": "ordlibrary/DeepSolana-GPT2-bucket (CPT)",
"score": "pending eval",
"job": "ordlibrary/6a3460cb2eb64285ee5734d9",
"status": "TRAINING",
"note": "ZK-specialised: Light Protocol, nullifiers, Groth16, compressed tokens",
},
{
"id": "solanaclawd/solana-clawd-core-ai-1.5b-lora (3-epoch)",
"base": "Qwen/Qwen2.5-1.5B-Instruct",
"type": "LoRA adapter",
"params": "1.5B",
"dataset": "solana-clawd-core-ai-instruct (35,173 ex)",
"score": "pending",
"job": "ordlibrary/6a35dd23953ed90bfb945356 โถ",
"status": "RUNNING",
"note": "3-epoch retrain on H200 โ will overwrite 1-epoch weights on completion",
},
]
DATASETS = [
("solanaclawd/solana-clawd-core-ai-instruct", "35,173", "SFT โ Core AI source tree + Solana primitives"),
("solanaclawd/solana-clawd-instruct", "36,109", "SFT โ Legacy seed: constitutional + Solana"),
("solanaclawd/solana-clawd-realtime-research-instruct", "29,058", "SFT โ PDFs, notebooks, parquet ZK examples"),
("solanaclawd/solana-nvidia-trading-factory-instruct", "142", "SFT โ NVIDIA Blueprint trading factory scenarios"),
("solanaclawd/solana-tx-foundation-cpt", "โ", "CPT โ Solana transaction foundation model corpus"),
("solanaclawd/solana-clawd-eval", "13", "Eval โ Red-team + capability held-out prompts"),
("ordlibrary/DeepSolana-GPT2-bucket", "โ", "CPT โ DeepSolana pre-training bucket"),
]
FACTORY_BLUEPRINTS = [
("Blueprint 1", "Data Collection", "Helius DAS + RPC streaming โ Solana tx corpus for CPT"),
("Blueprint 2", "Portfolio Optimization", "Mean-CVaR cuFOLIO โ GPU-accelerated portfolio weights"),
("Blueprint 3", "Transaction Foundation", "SolanaTokenizerPipeline โ decoder CLM pre-training"),
("Blueprint 4", "Signal Discovery", "7-signal suite: RSI, MACD, BBands, ATR, ADX, funding, OB imbalance"),
("Blueprint 5", "RAG Context", "Enterprise RAG over Solana docs for agent context assembly"),
("Nemotron", "Teacher Model", "550B Ultra โ labels Solana decisions โ distills to 1.5B student"),
]
# โโ Chat โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
def chat(message: str, history: list, model_choice: str) -> str:
if not HF_TOKEN:
return "โ ๏ธ HF_TOKEN not set โ add it as a Space secret to enable live inference."
client = OpenAI(base_url=ROUTER, api_key=HF_TOKEN)
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
for h in history:
messages.append({"role": "user", "content": h[0]})
messages.append({"role": "assistant", "content": h[1]})
messages.append({"role": "user", "content": message})
try:
resp = client.chat.completions.create(
model=model_choice,
messages=messages,
max_tokens=512,
temperature=0.3,
)
return resp.choices[0].message.content
except Exception as e:
return f"Error: {e}"
# โโ Benchmark HTML โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
def build_benchmark_html() -> str:
correct = sum(1 for _, _, ok in MCQ_RESULTS if ok)
total = len(MCQ_RESULTS)
topic_stats: dict = {}
for topic, _, ok in MCQ_RESULTS:
topic_stats.setdefault(topic, [0, 0])
topic_stats[topic][1] += 1
if ok:
topic_stats[topic][0] += 1
rows = ""
for topic, question, ok in MCQ_RESULTS:
color = TOPIC_COLORS.get(topic, "#888")
icon = "โ" if ok else "โ"
bg = "#1a2a1a" if ok else "#2a1a1a"
rows += f"""
| {topic} |
{question} |
{icon} |
"""
topic_bars = ""
for topic, (c, t) in sorted(topic_stats.items()):
pct = c / t * 100
color = TOPIC_COLORS.get(topic, "#888")
topic_bars += f"""
{topic}
{c}/{t} ({pct:.0f}%)
"""
return f"""
๐ฆ
{correct}/{total} = {correct/total*100:.1f}%
Solana Knowledge Benchmark โ 18 MCQ across 6 domains
Model: {MODEL_CORE} | 1-epoch | local MPS eval
Question Detail
| Topic |
Question |
โ |
{rows}
MISS: Q3 โ Default compute unit budget
Model answered 1,400,000 CU (correct: 200,000). Common confusion with max transaction CU vs default. Fixed with 3-epoch retrain (job 6a35dd23 running on H200).
"""
# โโ Ecosystem HTML โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
def build_ecosystem_html() -> str:
status_colors = {"LIVE": "#4ade80", "TRAINING": "#f59e0b", "RUNNING": "#60a5fa"}
model_cards = ""
for m in MODELS:
sc = status_colors.get(m["status"], "#888")
model_cards += f"""
{m['type']} ยท {m['params']} ยท {m['base']}
{m['note']}
๐ฆ {m['dataset']}
๐ฏ {m['score']}
"""
dataset_rows = ""
for ds_id, size, desc in DATASETS:
dataset_rows += f"""
| {ds_id} |
{size} |
{desc} |
"""
return f"""
๐ค Model Registry
{model_cards}
๐ฆ Datasets
| Dataset |
Examples |
Description |
{dataset_rows}
"""
# โโ Factory HTML โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
def build_factory_html() -> str:
bp_cards = ""
icons = ["๐ก", "๐", "๐ค", "๐", "๐", "๐ง "]
for i, (name, title, desc) in enumerate(FACTORY_BLUEPRINTS):
bp_cards += f"""
{icons[i]}
{name}
{title}
{desc}
"""
signals = [
("RSI", "Oversold <30 / Overbought >70"),
("MACD", "Histogram momentum crossover"),
("BBands", "Mean-reversion near upper/lower band"),
("ATR%", "Volatility regime filter"),
("ADX", "Trend strength entry filter"),
("Funding Rate", "Sentiment proxy โ crowded longs/shorts"),
("OB Imbalance", "Live bid/ask size pressure"),
]
signal_rows = "".join(
f'| {s} | '
f'{d} |
'
for s, d in signals
)
return f"""
๐ญ NVIDIA Trading Factory
{bp_cards}
๐ 7 Live Signals (Blueprint 4)
๐ Distillation Flywheel
โ Nemotron Ultra 550B observes markets
โก Outputs structured JSON trading plans
โข Plans logged as SFT pairs (teacher labels)
โฃ 1.5B student fine-tuned on Ultra labels
โค Student deployed for low-latency inference
โฅ Student decisions verified โ new labels โ loop
"""
# โโ Model Kit HTML โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
def build_kit_html() -> str:
return """
๐ง Onchain Model Kit
Fork โ Dataset โ Train โ Eval โ Register onchain. One sitting. ~$4 on A100.
โ Clone & install
git clone https://github.com/Solizardking/solana-clawd
cd solana-clawd/ai-training
pip install -r requirements.txt
export HF_TOKEN=hf_... # huggingface.co/settings/tokens (write access)
โก Push your dataset
python3 scripts/prepare_dataset.py \\
--input data/your_sft.jsonl \\
--push --repo-id YOUR_ORG/your-dataset
โข Train on A100 (~$4 for 3 epochs)
hf jobs uv run scripts/train_lora.py \\
--flavor a100-large --timeout 6h --secrets HF_TOKEN --detach \\
-- --config configs/core_ai_lora_config.yaml \\
--hub-model-id YOUR_ORG/your-model --push
โฃ Benchmark (18-MCQ Solana eval)
python3 scripts/solana_benchmark.py \\
--model YOUR_ORG/your-model \\
--base-url https://router.huggingface.co/v1 \\
--api-key $HF_TOKEN
โค Register onchain
./dao/register_model.sh \\
--hf-model YOUR_ORG/your-model \\
--eval-accuracy 0.944 \\
--dataset-size 35173
# โ indexed at onchain.x402.wtf forever
"""
# โโ Gradio App โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
HEADER = """
๐ฆ
CLAWD MODEL KIT
Solana-Native AI Agent Ecosystem ยท solanaclawd
"""
with gr.Blocks(
theme=gr.themes.Soft(primary_hue="violet", neutral_hue="slate"),
css="footer { display: none !important; }",
title="Clawd Model Kit",
) as demo:
gr.HTML(HEADER)
with gr.Tabs():
# โโ Tab 1: Chat โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
with gr.Tab("๐ฆ Chat"):
gr.Markdown("> Chat live with `solanaclawd/solana-clawd-core-ai-1.5b-lora` via HF Router. No GPU needed.")
model_dd = gr.Dropdown(
choices=[MODEL_CORE, MODEL_8B, MODEL_LEGACY],
value=MODEL_CORE,
label="Model",
)
chatbot = gr.Chatbot(height=420, show_label=False, bubble_full_width=False)
with gr.Row():
msg = gr.Textbox(
placeholder="Ask about Solana, DeFi, ZK, perps, Clawd Constitution...",
show_label=False, scale=8,
)
send = gr.Button("Send", variant="primary", scale=1)
examples = gr.Examples(
examples=[
["What is a PDA on Solana and how does it differ from a regular keypair?"],
["Explain the Clawd Constitution's three laws and why they exist."],
["How does Light Protocol achieve 136x cheaper compressed token accounts?"],
["What's the difference between funding rate and basis in perps trading?"],
["How do I detect a rug pull on a fresh Solana token?"],
["Explain OODA loop in the context of an autonomous trading agent."],
],
inputs=msg,
)
def respond(message, history, model_choice):
reply = chat(message, history, model_choice)
history.append((message, reply))
return "", history
send.click(respond, [msg, chatbot, model_dd], [msg, chatbot])
msg.submit(respond, [msg, chatbot, model_dd], [msg, chatbot])
# โโ Tab 2: Benchmark โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
with gr.Tab("๐ Benchmark"):
gr.HTML(build_benchmark_html())
# โโ Tab 3: Factory โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
with gr.Tab("๐ญ Trading Factory"):
gr.HTML(build_factory_html())
# โโ Tab 4: Ecosystem โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
with gr.Tab("๐ค Ecosystem"):
gr.HTML(build_ecosystem_html())
# โโ Tab 5: Model Kit โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
with gr.Tab("๐ง Model Kit"):
gr.HTML(build_kit_html())
if __name__ == "__main__":
demo.launch()