Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import time
|
|
| 5 |
# --- CONFIGURATION ---
|
| 6 |
# Your AMD MI300X Droplet IP
|
| 7 |
DROPLET_IP = "134.199.195.151"
|
|
|
|
| 8 |
API_URL = "https://jqzih-134-199-192-140.run.pinggy-free.link/translate"
|
| 9 |
|
| 10 |
# --- LOGIC ---
|
|
@@ -13,12 +14,27 @@ def ghost_translate(cuda_code):
|
|
| 13 |
yield "👻 Ghost-Coder: Analyzing CUDA Kernel...", "Loading..."
|
| 14 |
|
| 15 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
# Step 2: Real API Call to your MI300X
|
| 17 |
-
|
|
|
|
| 18 |
|
| 19 |
if response.status_code == 200:
|
| 20 |
hip_code = response.json().get("hip_code", "// Error: No code returned")
|
| 21 |
|
|
|
|
|
|
|
|
|
|
| 22 |
# Step 3: Agentic Visual Steps (Self-Healing Simulation)
|
| 23 |
yield "🔄 Analyzing HIP logic on ROCm stack...", "Generating..."
|
| 24 |
time.sleep(1)
|
|
|
|
| 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 ---
|
|
|
|
| 14 |
yield "👻 Ghost-Coder: Analyzing CUDA Kernel...", "Loading..."
|
| 15 |
|
| 16 |
try:
|
| 17 |
+
# --- THE MAGIC FIX: ChatML Instruction Template ---
|
| 18 |
+
# This forces the Qwen model to act as an assistant instead of an autocomplete
|
| 19 |
+
formatted_prompt = f"""<|im_start|>system
|
| 20 |
+
You are Ghost-Coder, an expert AI specializing in translating CUDA code to AMD HIP code. Output ONLY the valid, translated HIP code. Do not echo the prompt or include markdown formatting.<|im_end|>
|
| 21 |
+
<|im_start|>user
|
| 22 |
+
Translate this exact CUDA code to HIP:
|
| 23 |
+
|
| 24 |
+
{cuda_code}<|im_end|>
|
| 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 |
hip_code = response.json().get("hip_code", "// Error: No code returned")
|
| 34 |
|
| 35 |
+
# Failsafe: Clean up the output in case the model echoes the prompt
|
| 36 |
+
hip_code = hip_code.replace(formatted_prompt, "").strip()
|
| 37 |
+
|
| 38 |
# Step 3: Agentic Visual Steps (Self-Healing Simulation)
|
| 39 |
yield "🔄 Analyzing HIP logic on ROCm stack...", "Generating..."
|
| 40 |
time.sleep(1)
|