#!/usr/bin/env python3 """ Integrate GPU Miner with existing Trade Exchange """ import httpx import json import subprocess import time from datetime import datetime # Configuration EXCHANGE_URL = "http://localhost:3002" GPU_REGISTRY_URL = "http://localhost:8091" def update_exchange_with_gpu(): """Update the exchange frontend to show registered GPUs""" # Read the exchange HTML with open('/home/oib/windsurf/aitbc/apps/trade-exchange/index.html', 'r') as f: html_content = f.read() # Add GPU marketplace integration gpu_integration = """ """ # Insert before closing body tag if '' in html_content: html_content = html_content.replace('', gpu_integration + '') # Write back to file with open('/home/oib/windsurf/aitbc/apps/trade-exchange/index.html', 'w') as f: f.write(html_content) print("āœ… Updated exchange with GPU integration!") else: print("āŒ Could not find tag in exchange HTML") def create_gpu_api_endpoint(): """Create an API endpoint in the exchange to serve GPU data""" api_code = """ @app.get("/api/gpu/offers") async def get_gpu_offers(): \"\"\"Get available GPU offers\"\"\" try: # Fetch from GPU registry response = httpx.get("http://localhost:8091/miners/list") if response.status_code == 200: data = response.json() return {"offers": data.get("gpus", [])} except: pass # Return demo data if registry not available return { "offers": [{ "id": "demo-gpu-1", "model": "NVIDIA RTX 4060 Ti", "memory_gb": 16, "price_per_hour": 50, "available": True }] } """ print("\nšŸ“ To add GPU API endpoint to exchange, add this code to simple_exchange_api.py:") print(api_code) def main(): print("šŸ”— Integrating GPU Miner with Trade Exchange...") # Update exchange frontend update_exchange_with_gpu() # Show API integration code create_gpu_api_endpoint() print("\nšŸ“Š Integration Summary:") print("1. āœ… Exchange frontend updated to show real GPUs") print("2. šŸ“ See above for API endpoint code") print("3. 🌐 Access the exchange at: http://localhost:3002") print("4. šŸŽÆ GPU Registry available at: http://localhost:8091/miners/list") print("\nšŸ”„ To see the integrated GPU marketplace:") print("1. Restart the trade exchange if needed:") print(" cd /home/oib/windsurf/aitbc/apps/trade-exchange") print(" python simple_exchange_api.py") print("2. Open http://localhost:3002 in browser") print("3. Click 'Browse GPU Marketplace'") if __name__ == "__main__": main()