Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -3,23 +3,21 @@ from pydantic import BaseModel
|
|
3 |
|
4 |
import subprocess
|
5 |
from regex import find_imports
|
6 |
-
|
7 |
-
code: str
|
8 |
-
filename: str = ''
|
9 |
|
10 |
|
11 |
|
12 |
app = FastAPI()
|
13 |
|
14 |
@app.post("/code")
|
15 |
-
def run_mojo_code(
|
16 |
try:
|
17 |
-
imports = find_imports(
|
18 |
for imported in imports:
|
19 |
subprocess.call(["python3", "-m", "pip", "install", imported], shell=True)
|
20 |
-
with open(
|
21 |
-
f.write(
|
22 |
|
23 |
-
return {"sucess":True, "output": subprocess.check_output(["mojo",
|
24 |
except:
|
25 |
return {"sucess":False}, 500
|
|
|
3 |
|
4 |
import subprocess
|
5 |
from regex import find_imports
|
6 |
+
|
|
|
|
|
7 |
|
8 |
|
9 |
|
10 |
app = FastAPI()
|
11 |
|
12 |
@app.post("/code")
|
13 |
+
def run_mojo_code(code: str, filename: str = '') -> dict:
|
14 |
try:
|
15 |
+
imports = find_imports(code)
|
16 |
for imported in imports:
|
17 |
subprocess.call(["python3", "-m", "pip", "install", imported], shell=True)
|
18 |
+
with open(filename, "w") as f:
|
19 |
+
f.write(code)
|
20 |
|
21 |
+
return {"sucess":True, "output": subprocess.check_output(["mojo", filename]).decode("utf-8")}, 200
|
22 |
except:
|
23 |
return {"sucess":False}, 500
|