Spaces:
Running
Running
from fastapi import FastAPI | |
import subprocess, importlib | |
from tools.regex import find_imports | |
app = FastAPI() | |
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 |