Team Ai
Apppublic

Cyfer-ap/AI-Coding-Tutor

sourceHugging Faceupdated 1y agoView on Hugging Face
1likes
code_executor.py15 linesDownload Raw Back to backend
1import subprocess2 3def execute_code(code, language, inputs):4    if language != "Python":5        return "Execution only supported for Python in this version."6 7    try:8        results = []9        for inp in inputs.splitlines():10            result = subprocess.run(["python3", "-c", code], input=inp.encode(), capture_output=True, timeout=5)11            results.append(f"Input: {inp}\\nOutput: {result.stdout.decode()}")12        return "\\n\\n".join(results)13    except Exception as e:14        return f"Execution Error: {str(e)}"15