RemoteMojo / main.py
SoUmNerd's picture
Upload 3 files
4ec23ab
raw
history blame
588 Bytes
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