Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import urllib.request, json | |
| GATEWAY_URL = 'http://34.41.139.70' | |
| def check_health(): | |
| try: | |
| r = urllib.request.urlopen(f'{GATEWAY_URL}/health', timeout=5) | |
| return json.loads(r.read()) | |
| except Exception as e: | |
| return {'error': str(e)} | |
| def settle_payment(amount): | |
| payload = json.dumps({'hash':'demo123','asset':'USDC','network':'Solana','amount':float(amount)}).encode() | |
| try: | |
| r = urllib.request.urlopen(f'{GATEWAY_URL}/api/settlement/verify', data=payload, headers={'Content-Type':'application/json'}, timeout=5) | |
| return json.loads(r.read()) | |
| except Exception as e: | |
| return {'error': str(e)} | |
| with gr.Blocks(title='NullState Gateway Demo') as demo: | |
| gr.Markdown('# NullState Gateway\nOpen-source x402 settlement layer for AI agents') | |
| gr.Markdown(f'Active Gateway: {GATEWAY_URL}') | |
| with gr.Tab('Health'): | |
| btn = gr.Button('Check Gateway Health') | |
| out = gr.JSON(label='Status') | |
| btn.click(fn=check_health, outputs=out) | |
| with gr.Tab('Settlement'): | |
| amt = gr.Number(label='Amount (USDC)', value=1.0) | |
| btn2 = gr.Button('Test Settlement') | |
| out2 = gr.JSON(label='Result') | |
| btn2.click(fn=settle_payment, inputs=amt, outputs=out2) | |
| gr.Markdown('---\n[NullState GitHub](https://github.com/NullStateGGH/nullstate) | [Gateway](http://34.41.139.70)') | |
| demo.launch() | |