Spaces:
Sleeping
Sleeping
File size: 758 Bytes
ab19593 b887ba2 08b90ab 3014ad5 451eaa9 b887ba2 4ec23ab b887ba2 4ec23ab b887ba2 5e16737 08b90ab fbacf15 ab19593 4ec23ab 451eaa9 4ec23ab 451eaa9 4ec23ab 451eaa9 4ec23ab b887ba2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
from fastapi import FastAPI, Request
import subprocess, json
from regex import find_imports
app = FastAPI()
@app.post("/code")
async def run_mojo_code(request:Request) -> dict:
data_as_str = await request.json()
print(data_as_str)
print(type(data_as_str))
data = data_as_str
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 {"sucess":True, "output": subprocess.check_output(["mojo", filename]).decode("utf-8")}, 200
except:
return {"sucess":False}, 500 |