Commit
Β·
056a335
1
Parent(s):
d5d0386
Upgraded gradio interface
Browse files- app.py +40 -9
- prompts/devstral_coding_prompt.py +5 -1
app.py
CHANGED
|
@@ -370,24 +370,55 @@ def execute_code(code_output):
|
|
| 370 |
|
| 371 |
yield "**β³ Executing code...** (Parsing code)"
|
| 372 |
code = parse_python_codefences(code_output)
|
| 373 |
-
print(code)
|
| 374 |
|
| 375 |
if not code or not code.strip():
|
| 376 |
yield "β No Python code found to execute."
|
| 377 |
return
|
| 378 |
|
| 379 |
yield "**β³ Executing code...** (Running in sandbox)"
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 385 |
else:
|
| 386 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 387 |
|
| 388 |
-
yield f"**β
Execution Complete:**\n\n```\n{result_str}\n```"
|
| 389 |
except Exception as e:
|
| 390 |
-
yield f"β **Error
|
| 391 |
|
| 392 |
# Custom CSS for a sleek design
|
| 393 |
custom_css = """
|
|
|
|
| 370 |
|
| 371 |
yield "**β³ Executing code...** (Parsing code)"
|
| 372 |
code = parse_python_codefences(code_output)
|
|
|
|
| 373 |
|
| 374 |
if not code or not code.strip():
|
| 375 |
yield "β No Python code found to execute."
|
| 376 |
return
|
| 377 |
|
| 378 |
yield "**β³ Executing code...** (Running in sandbox)"
|
| 379 |
+
exec_result, build_logs = code_eval(code)
|
| 380 |
+
|
| 381 |
+
# Ensure exec_result is a dictionary
|
| 382 |
+
if not isinstance(exec_result, dict):
|
| 383 |
+
yield f"β **Error:** Unexpected execution result format.\\n\\n```\\n{str(exec_result)}\\n```"
|
| 384 |
+
return
|
| 385 |
+
|
| 386 |
+
return_code = exec_result.get('returncode', -1)
|
| 387 |
+
stdout = exec_result.get('stdout', '')
|
| 388 |
+
stderr = exec_result.get('stderr', '')
|
| 389 |
+
error_msg = exec_result.get('error', 'Unknown error')
|
| 390 |
+
|
| 391 |
+
# Build the formatted Markdown output
|
| 392 |
+
formatted_output = ""
|
| 393 |
+
if return_code == 0:
|
| 394 |
+
formatted_output += "## β
Execution Successful\n"
|
| 395 |
+
if stdout:
|
| 396 |
+
formatted_output += f"**Output:**\n```text\n{stdout.strip()}\n```\n"
|
| 397 |
+
if stderr:
|
| 398 |
+
formatted_output += f"**Warnings (`stderr`):**\n```text\n{stderr.strip()}\n```\n"
|
| 399 |
else:
|
| 400 |
+
formatted_output += f"## β Execution Failed (Exit Code: {return_code})\n"
|
| 401 |
+
formatted_output += f"**Error:** `{error_msg}`\n\n"
|
| 402 |
+
if stderr:
|
| 403 |
+
formatted_output += f"**Error Log (`stderr`):**\n```text\n{stderr.strip()}\n```\n"
|
| 404 |
+
if stdout:
|
| 405 |
+
formatted_output += f"**Output (`stdout`):**\n```text\n{stdout.strip()}\n```\n"
|
| 406 |
+
|
| 407 |
+
# Add build logs in a collapsible section
|
| 408 |
+
if build_logs:
|
| 409 |
+
formatted_output += f"""
|
| 410 |
+
<details>
|
| 411 |
+
<summary>Click to view build logs</summary>
|
| 412 |
+
|
| 413 |
+
```
|
| 414 |
+
{build_logs.strip()}
|
| 415 |
+
```
|
| 416 |
+
</details>
|
| 417 |
+
"""
|
| 418 |
+
yield formatted_output
|
| 419 |
|
|
|
|
| 420 |
except Exception as e:
|
| 421 |
+
yield f"β **Error running execution logic:** {str(e)}\n\n{traceback.format_exc()}"
|
| 422 |
|
| 423 |
# Custom CSS for a sleek design
|
| 424 |
custom_css = """
|
prompts/devstral_coding_prompt.py
CHANGED
|
@@ -15,5 +15,9 @@ devstral_code_gen_user_prompt ="""
|
|
| 15 |
|
| 16 |
Just return the full execution code block in a python codefence as shown below without any explanation or suffix or prefix text.
|
| 17 |
|
| 18 |
-
Ensure that the code is EXECUTABLE and does not contain any errors.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
"""
|
|
|
|
| 15 |
|
| 16 |
Just return the full execution code block in a python codefence as shown below without any explanation or suffix or prefix text.
|
| 17 |
|
| 18 |
+
Ensure that the code is EXECUTABLE and does not contain any errors.
|
| 19 |
+
|
| 20 |
+
Refrain from and DO NOT hallucinate/make up datasets or models. If you dont have any relevant dataset generate synthetic data and use that to build a model!
|
| 21 |
+
|
| 22 |
+
If you get a dataset from the Hugging Face Hub, make sure to check the exact columns of the dataset to use it properly.
|
| 23 |
"""
|