nullstate / app.py
NullState Team
Initial Space: NullState Gateway UI
e94087f
Raw
History Blame Contribute Delete
3.46 kB
import gradio as gr
import requests
import json
import os
from datetime import datetime
GATEWAY_URL = os.environ.get("NULLSTATE_GATEWAY_URL", "https://greensol.me/nullstate")
def fetch_status():
try:
r = requests.get(f"{GATEWAY_URL}/health", timeout=10, verify=False)
data = r.json()
return (
f"Tasks: {data.get('tasks', 'N/A')}\n"
f"Ledger: {data.get('ledger', 'N/A')}\n"
f"Balance: ${data.get('balance', '0.00')} USDC\n"
f"AI: {data.get('ai_model', 'N/A')}\n"
f"Pricing: {data.get('pricing', 'N/A')}"
)
except Exception as e:
return f"Gateway unreachable: {e}"
def get_kya_challenge():
try:
r = requests.get(f"{GATEWAY_URL}/kya/challenge", timeout=10, verify=False)
return r.text
except Exception as e:
return f"Error: {e}"
def submit_solution(task_id: str, solution: str):
try:
r = requests.post(
f"{GATEWAY_URL}/mcp",
json={
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {"name": "submit_solution", "arguments": {"task_id": task_id, "solution": solution}}
},
timeout=15,
verify=False
)
return json.dumps(r.json(), indent=2)
except Exception as e:
return f"Error: {e}"
def query_intelligence(prompt: str):
try:
r = requests.post(
f"{GATEWAY_URL}/mcp",
json={
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {"name": "get_intelligence", "arguments": {"prompt": prompt}}
},
timeout=30,
verify=False
)
return json.dumps(r.json(), indent=2)
except Exception as e:
return f"Error: {e}"
with gr.Blocks(theme=gr.themes.Soft(primary_hue="green"), title="NullState Gateway") as demo:
gr.Markdown("""# ⚡ NullState Gateway
**Payment Infrastructure for AI Agents** — x402 · AP2 · MCP · KYA
""")
with gr.Tab("Status"):
status_btn = gr.Button("Refresh Status", variant="primary")
status_output = gr.Textbox(label="Gateway Health", lines=6)
status_btn.click(fn=fetch_status, outputs=status_output)
with gr.Tab("KYA Challenge"):
kya_btn = gr.Button("Get KYA Challenge", variant="primary")
kya_output = gr.Textbox(label="Challenge Response", lines=8)
kya_btn.click(fn=get_kya_challenge, outputs=kya_output)
with gr.Tab("Submit Solution"):
task_id = gr.Textbox(label="Task ID", placeholder="task_abc123")
solution = gr.Textbox(label="Solution", lines=4, placeholder="Your solution here...")
submit_btn = gr.Button("Submit", variant="primary")
submit_output = gr.Textbox(label="Response", lines=6)
submit_btn.click(fn=submit_solution, inputs=[task_id, solution], outputs=submit_output)
with gr.Tab("Query AI"):
prompt = gr.Textbox(label="Prompt", lines=3, placeholder="Ask NullState AI...")
query_btn = gr.Button("Query", variant="primary")
query_output = gr.Textbox(label="Response", lines=8)
query_btn.click(fn=query_intelligence, inputs=[prompt], outputs=query_output)
gr.Markdown("""---
Built with ❤️ by [NullState](https://greensol.me/nullstate) — Open-source MIT
""")
demo.launch()