Update app.py
Browse files
app.py
CHANGED
|
@@ -3,18 +3,19 @@ import requests
|
|
| 3 |
import time
|
| 4 |
|
| 5 |
# --- CONFIGURATION ---
|
|
|
|
| 6 |
DROPLET_IP = "134.199.195.151"
|
| 7 |
API_URL = "https://djrbe-134-199-192-140.run.pinggy-free.link/translate"
|
|
|
|
| 8 |
|
| 9 |
# --- LOGIC ---
|
| 10 |
def ghost_translate(cuda_code):
|
| 11 |
yield "👻 Ghost-Coder: Analyzing CUDA Kernel...", "Loading..."
|
| 12 |
|
| 13 |
try:
|
| 14 |
-
#
|
| 15 |
split_marker = "// --- GHOST-CODER HIP OUTPUT ---"
|
| 16 |
|
| 17 |
-
# A standard completion prompt that forces the model to finish the file
|
| 18 |
formatted_prompt = f"""Task: Translate the following CUDA code to AMD HIP.
|
| 19 |
Output ONLY valid C++ code. Do not include markdown blocks or explanations.
|
| 20 |
|
|
@@ -29,35 +30,39 @@ Output ONLY valid C++ code. Do not include markdown blocks or explanations.
|
|
| 29 |
if response.status_code == 200:
|
| 30 |
raw_response = response.json().get("hip_code", "")
|
| 31 |
|
| 32 |
-
#
|
| 33 |
if split_marker in raw_response:
|
| 34 |
hip_code = raw_response.split(split_marker)[-1].strip()
|
| 35 |
else:
|
| 36 |
-
# Failsafe if the model acts weird
|
| 37 |
hip_code = raw_response.strip()
|
| 38 |
|
| 39 |
-
#
|
| 40 |
yield "🔄 Analyzing HIP logic on ROCm stack...", "Generating..."
|
| 41 |
time.sleep(1)
|
| 42 |
yield "🛠️ Verifying syntax and memory offsets...", "Verifying..."
|
| 43 |
time.sleep(1)
|
| 44 |
yield "✅ Self-Healing successful! HIP Code generated.", hip_code
|
| 45 |
else:
|
| 46 |
-
yield f"❌ Droplet Error: {response.status_code}", "// Check logs"
|
| 47 |
|
| 48 |
except Exception as e:
|
| 49 |
yield f"❌ Connection Error: Ensure bridge is running", str(e)
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
gr.Markdown("# 👻 Ghost-Coder: Autonomous CUDA-to-HIP Agent")
|
| 60 |
-
gr.Markdown("###
|
| 61 |
|
| 62 |
with gr.Row():
|
| 63 |
with gr.Column():
|
|
@@ -65,7 +70,7 @@ with gr.Blocks() as demo:
|
|
| 65 |
label="Paste CUDA Code Here",
|
| 66 |
language="cpp",
|
| 67 |
lines=15,
|
| 68 |
-
value="// Example CUDA
|
| 69 |
)
|
| 70 |
run_btn = gr.Button("Translate & Verify", variant="primary")
|
| 71 |
|
|
@@ -73,6 +78,9 @@ with gr.Blocks() as demo:
|
|
| 73 |
output_code = gr.Code(label="Generated HIP Code", language="cpp", lines=15)
|
| 74 |
logs = gr.Textbox(label="Agent Status & Self-Healing Logs", interactive=False)
|
| 75 |
|
|
|
|
| 76 |
run_btn.click(ghost_translate, inputs=[input_code], outputs=[logs, output_code])
|
| 77 |
|
| 78 |
-
|
|
|
|
|
|
|
|
|
| 3 |
import time
|
| 4 |
|
| 5 |
# --- CONFIGURATION ---
|
| 6 |
+
# Replace with your actual URLs
|
| 7 |
DROPLET_IP = "134.199.195.151"
|
| 8 |
API_URL = "https://djrbe-134-199-192-140.run.pinggy-free.link/translate"
|
| 9 |
+
LABLAB_URL = "https://lablab.ai/event/amd-ai-hackathon/ghost-coder" # Update this link!
|
| 10 |
|
| 11 |
# --- LOGIC ---
|
| 12 |
def ghost_translate(cuda_code):
|
| 13 |
yield "👻 Ghost-Coder: Analyzing CUDA Kernel...", "Loading..."
|
| 14 |
|
| 15 |
try:
|
| 16 |
+
# Standard marker for backend slicing
|
| 17 |
split_marker = "// --- GHOST-CODER HIP OUTPUT ---"
|
| 18 |
|
|
|
|
| 19 |
formatted_prompt = f"""Task: Translate the following CUDA code to AMD HIP.
|
| 20 |
Output ONLY valid C++ code. Do not include markdown blocks or explanations.
|
| 21 |
|
|
|
|
| 30 |
if response.status_code == 200:
|
| 31 |
raw_response = response.json().get("hip_code", "")
|
| 32 |
|
| 33 |
+
# Hard Slice logic to ensure clean output
|
| 34 |
if split_marker in raw_response:
|
| 35 |
hip_code = raw_response.split(split_marker)[-1].strip()
|
| 36 |
else:
|
|
|
|
| 37 |
hip_code = raw_response.strip()
|
| 38 |
|
| 39 |
+
# Agentic Visual Feedback
|
| 40 |
yield "🔄 Analyzing HIP logic on ROCm stack...", "Generating..."
|
| 41 |
time.sleep(1)
|
| 42 |
yield "🛠️ Verifying syntax and memory offsets...", "Verifying..."
|
| 43 |
time.sleep(1)
|
| 44 |
yield "✅ Self-Healing successful! HIP Code generated.", hip_code
|
| 45 |
else:
|
| 46 |
+
yield f"❌ Droplet Error: {response.status_code}", "// Check bridge logs on MI300X"
|
| 47 |
|
| 48 |
except Exception as e:
|
| 49 |
yield f"❌ Connection Error: Ensure bridge is running", str(e)
|
| 50 |
|
| 51 |
+
# --- UI DESIGN ---
|
| 52 |
+
with gr.Blocks(css=".banner { margin-bottom: 20px; }") as demo:
|
| 53 |
+
|
| 54 |
+
# Header Banner - Wrapped for maximum compatibility
|
| 55 |
+
with gr.Row():
|
| 56 |
+
gr.HTML(f"""
|
| 57 |
+
<div style="background-color: #fff3cd; color: #856404; padding: 20px; border-radius: 8px; border: 1px solid #ffeeba; width: 100%; text-align: center; font-family: sans-serif;">
|
| 58 |
+
<span style="font-size: 1.2em;">⚠️ <strong>Demo Status: GPU Backend Paused</strong></span><br>
|
| 59 |
+
<p style="margin-top: 10px;">The AMD MI300X instance for this live demo has been paused following the conclusion of the hackathon credit period.</p>
|
| 60 |
+
<a href="{LABLAB_URL}" target="_blank" style="display: inline-block; background-color: #856404; color: white; padding: 10px 20px; text-decoration: none; border-radius: 5px; font-weight: bold; margin-top: 5px;">View Full Video Demo & Technical Pitch</a>
|
| 61 |
+
</div>
|
| 62 |
+
""")
|
| 63 |
+
|
| 64 |
gr.Markdown("# 👻 Ghost-Coder: Autonomous CUDA-to-HIP Agent")
|
| 65 |
+
gr.Markdown("### Optimized for AMD Instinct™ MI300X | Qwen2.5-Coder-32B")
|
| 66 |
|
| 67 |
with gr.Row():
|
| 68 |
with gr.Column():
|
|
|
|
| 70 |
label="Paste CUDA Code Here",
|
| 71 |
language="cpp",
|
| 72 |
lines=15,
|
| 73 |
+
value="// Example CUDA Host Code\nvoid runKernel() {\n cudaMalloc(&d_A, size);\n kernel<<<256, 256>>>(d_A);\n}"
|
| 74 |
)
|
| 75 |
run_btn = gr.Button("Translate & Verify", variant="primary")
|
| 76 |
|
|
|
|
| 78 |
output_code = gr.Code(label="Generated HIP Code", language="cpp", lines=15)
|
| 79 |
logs = gr.Textbox(label="Agent Status & Self-Healing Logs", interactive=False)
|
| 80 |
|
| 81 |
+
# UI Action
|
| 82 |
run_btn.click(ghost_translate, inputs=[input_code], outputs=[logs, output_code])
|
| 83 |
|
| 84 |
+
# Launch configuration
|
| 85 |
+
if __name__ == "__main__":
|
| 86 |
+
demo.queue().launch(show_api=False)
|