Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -1,25 +1,25 @@
|
|
1 |
-
from
|
2 |
-
from pydantic import BaseModel
|
3 |
-
|
4 |
import subprocess
|
5 |
from regex import find_imports
|
6 |
-
class Item(BaseModel):
|
7 |
-
code: str
|
8 |
-
filename: str = ''
|
9 |
-
|
10 |
|
|
|
11 |
|
12 |
-
app
|
|
|
|
|
13 |
|
14 |
-
@app.
|
15 |
-
def run_mojo_code(
|
|
|
16 |
try:
|
17 |
-
imports = find_imports(item
|
18 |
for imported in imports:
|
19 |
subprocess.call(["python3", "-m", "pip", "install", imported], shell=True)
|
20 |
-
with open(item
|
21 |
-
f.write(item
|
22 |
|
23 |
-
return {"sucess":True, "output": subprocess.check_output(["mojo", item
|
24 |
except:
|
25 |
-
return {"sucess":False}, 500
|
|
|
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
|
|
|
|
2 |
import subprocess
|
3 |
from regex import find_imports
|
|
|
|
|
|
|
|
|
4 |
|
5 |
+
app = Flask(__name__)
|
6 |
|
7 |
+
@app.route("/")
|
8 |
+
def index():
|
9 |
+
return "Hello World!"
|
10 |
|
11 |
+
@app.route("/code", methods=['POST'])
|
12 |
+
def run_mojo_code():
|
13 |
+
item = request.get_json()
|
14 |
try:
|
15 |
+
imports = find_imports(item['code'])
|
16 |
for imported in imports:
|
17 |
subprocess.call(["python3", "-m", "pip", "install", imported], shell=True)
|
18 |
+
with open(item['filename'], "w") as f:
|
19 |
+
f.write(item['code'])
|
20 |
|
21 |
+
return jsonify({"sucess":True, "output": subprocess.check_output(["mojo", item['filename']]).decode("utf-8")}), 200
|
22 |
except:
|
23 |
+
return jsonify({"sucess":False}), 500
|
24 |
+
|
25 |
+
app.run(port=7860, debug=True)
|