Spaces:
Sleeping
Sleeping
File size: 772 Bytes
713ecf1 b887ba2 713ecf1 3014ad5 451eaa9 b887ba2 4ec23ab b887ba2 713ecf1 ab19593 4ec23ab 451eaa9 4ec23ab 451eaa9 4ec23ab 713ecf1 4ec23ab 713ecf1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
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) |