Update app.py
Browse files
app.py
CHANGED
|
@@ -3,52 +3,51 @@ import requests
|
|
| 3 |
import time
|
| 4 |
|
| 5 |
# --- CONFIGURATION ---
|
| 6 |
-
# Your AMD MI300X Droplet IP
|
| 7 |
DROPLET_IP = "134.199.195.151"
|
| 8 |
-
# Make sure this is your currently active Pinggy URL!
|
| 9 |
API_URL = "https://jqzih-134-199-192-140.run.pinggy-free.link/translate"
|
| 10 |
|
| 11 |
# --- LOGIC ---
|
| 12 |
def ghost_translate(cuda_code):
|
| 13 |
-
# Step 1: Initial UI Feedback
|
| 14 |
yield "👻 Ghost-Coder: Analyzing CUDA Kernel...", "Loading..."
|
| 15 |
|
| 16 |
try:
|
| 17 |
-
# -
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
{
|
| 25 |
-
<|im_start|>assistant
|
| 26 |
"""
|
| 27 |
|
| 28 |
-
# Step 2: Real API Call to your MI300X
|
| 29 |
-
# We send the strictly formatted prompt instead of just the raw code
|
| 30 |
response = requests.post(API_URL, json={"code": formatted_prompt}, timeout=120)
|
| 31 |
|
| 32 |
if response.status_code == 200:
|
| 33 |
-
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
# Step 3: Agentic Visual Steps
|
| 39 |
yield "🔄 Analyzing HIP logic on ROCm stack...", "Generating..."
|
| 40 |
time.sleep(1)
|
| 41 |
yield "🛠️ Verifying syntax and memory offsets...", "Verifying..."
|
| 42 |
time.sleep(1)
|
| 43 |
yield "✅ Self-Healing successful! HIP Code generated.", hip_code
|
| 44 |
else:
|
| 45 |
-
yield f"❌ Droplet Error: {response.status_code}", "// Check
|
| 46 |
|
| 47 |
except Exception as e:
|
| 48 |
-
yield f"❌ Connection Error: Ensure bridge is running
|
| 49 |
|
| 50 |
-
# --- UI DESIGN ---
|
| 51 |
-
# Using gr.Blocks() for a professional, agentic look
|
| 52 |
with gr.Blocks() as demo:
|
| 53 |
gr.Markdown("# 👻 Ghost-Coder: Autonomous CUDA-to-HIP Agent")
|
| 54 |
gr.Markdown("### Powered by AMD Instinct™ MI300X | Qwen2.5-Coder-32B")
|
|
@@ -67,8 +66,6 @@ with gr.Blocks() as demo:
|
|
| 67 |
output_code = gr.Code(label="Generated HIP Code", language="cpp", lines=15)
|
| 68 |
logs = gr.Textbox(label="Agent Status & Self-Healing Logs", interactive=False)
|
| 69 |
|
| 70 |
-
# Linking the button to our translation function
|
| 71 |
run_btn.click(ghost_translate, inputs=[input_code], outputs=[logs, output_code])
|
| 72 |
|
| 73 |
-
# Launching the app with the 'Soft' theme moved to the launch method
|
| 74 |
demo.queue().launch(theme=gr.themes.Soft())
|
|
|
|
| 3 |
import time
|
| 4 |
|
| 5 |
# --- CONFIGURATION ---
|
|
|
|
| 6 |
DROPLET_IP = "134.199.195.151"
|
|
|
|
| 7 |
API_URL = "https://jqzih-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 |
+
# We use a pure-text marker that the backend cannot delete or mangle
|
| 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 |
+
|
| 21 |
+
// --- ORIGINAL CUDA CODE ---
|
| 22 |
+
{cuda_code}
|
| 23 |
|
| 24 |
+
{split_marker}
|
|
|
|
| 25 |
"""
|
| 26 |
|
|
|
|
|
|
|
| 27 |
response = requests.post(API_URL, json={"code": formatted_prompt}, timeout=120)
|
| 28 |
|
| 29 |
if response.status_code == 200:
|
| 30 |
+
raw_response = response.json().get("hip_code", "")
|
| 31 |
|
| 32 |
+
# THE HARD SLICE: Cut away the entire input prompt
|
| 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 |
+
# Step 3: Agentic Visual Steps
|
| 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 |
with gr.Blocks() as demo:
|
| 52 |
gr.Markdown("# 👻 Ghost-Coder: Autonomous CUDA-to-HIP Agent")
|
| 53 |
gr.Markdown("### Powered by AMD Instinct™ MI300X | Qwen2.5-Coder-32B")
|
|
|
|
| 66 |
output_code = gr.Code(label="Generated HIP Code", language="cpp", lines=15)
|
| 67 |
logs = gr.Textbox(label="Agent Status & Self-Healing Logs", interactive=False)
|
| 68 |
|
|
|
|
| 69 |
run_btn.click(ghost_translate, inputs=[input_code], outputs=[logs, output_code])
|
| 70 |
|
|
|
|
| 71 |
demo.queue().launch(theme=gr.themes.Soft())
|