Spaces:
Sleeping
Sleeping
File size: 588 Bytes
4ec23ab |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
from fastapi import FastAPI
import subprocess, importlib
from tools.regex import find_imports
app = FastAPI()
@app.post("/code")
def run_mojo_code(code:str, filename:str) -> dict[str]:
try:
imports = find_imports(code)
for imported in imports:
subprocess.call(["python3", "-m", "pip", "install", imported], shell=True)
with open(filename, "w") as f:
f.write(code)
return {"sucess":True, "output": subprocess.check_output(["mojo", filename]).decode("utf-8")}, 200
except:
return {"sucess":False}, 500 |