import gradio as gr import requests import time # --- CONFIGURATION --- # Replace this with your actual Droplet IP DROPLET_IP = "134.199.195.151" API_URL = f"http://{DROPLET_IP}:8080/translate" # --- LOGIC --- def ghost_translate(cuda_code): # Step 1: UI Feedback yield "👻 Ghost-Coder: Analyzing CUDA Kernel...", "Loading..." try: # Step 2: Real API Call to your MI300X # We wrap this in a try/except in case the bridge isn't reachable response = requests.post(API_URL, json={"code": cuda_code}, timeout=120) if response.status_code == 200: hip_code = response.json().get("hip_code", "// Error: No code returned") # Step 3: Simulate the 'Self-Healing' steps for visual impact yield "🔄 Analyzing HIP logic on ROCm stack...", "Generating..." time.sleep(1.5) yield "🛠️ Verifying syntax and memory offsets...", "Verifying..." time.sleep(1.5) yield "✅ Self-Healing successful! HIP Code generated.", hip_code else: yield f"❌ Droplet Error: {response.status_code}", "// Check bridge logs on MI300X" except Exception as e: yield f"❌ Connection Error: Ensure bridge is running on {DROPLET_IP}", str(e) # --- UI DESIGN --- with gr.Blocks(theme=gr.themes.Soft()) as demo: gr.Markdown("# 👻 Ghost-Coder: Autonomous CUDA-to-HIP Agent") gr.Markdown("### Powered by AMD Instinct™ MI300X | Qwen2.5-Coder-32B") with gr.Row(): with gr.Column(): input_code = gr.Code(label="Paste CUDA Code Here", language="cpp", lines=15) run_btn = gr.Button("Translate & Verify", variant="primary") with gr.Column(): output_code = gr.Code(label="Generated HIP Code", language="cpp", lines=15) logs = gr.Textbox(label="Agent Status & Self-Healing Logs", interactive=False) run_btn.click(ghost_translate, inputs=[input_code], outputs=[logs, output_code]) demo.queue().launch() # Added .queue() for better streaming performance