from fastapi import FastAPI, Request, Response from pydantic import BaseModel import subprocess from regex import find_imports app = FastAPI() @app.post("/code") async def run_mojo_code(request:Request) -> Response: data = await request.json() code = data["code"] filename = data["filename"] 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 Response(content={"sucess":True, "output": subprocess.check_output(["mojo", filename]).decode("utf-8")}, status_code=200) except: return Response(content={"sucess":False}, status_code=500)