Update app.py
Browse files
app.py
CHANGED
@@ -1,44 +1,16 @@
|
|
1 |
-
import
|
2 |
-
import multiprocessing as mp
|
3 |
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
It is instantiated once per connection to the server, and must
|
11 |
-
override the handle() method to implement communication to the
|
12 |
-
client.
|
13 |
-
"""
|
14 |
-
|
15 |
-
def handle(self):
|
16 |
-
# self.rfile is a file-like object created by the handler;
|
17 |
-
# we can now use e.g. readline() instead of raw recv() calls
|
18 |
-
self.bytes = self.rfile.read()
|
19 |
-
self.data = self.bytes.decode("utf-8")
|
20 |
-
with open("script.py", "w") as f:
|
21 |
-
f.write(self.data)
|
22 |
-
# Likewise, self.wfile is a file-like object used to write back
|
23 |
-
# to the client
|
24 |
-
self.wfile.write(self.bytes.upper())
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
HOST, PORT = "localhost", 9999
|
29 |
-
def serverActivate():
|
30 |
-
with socketserver.TCPServer((HOST, PORT), TCPHandler) as server:
|
31 |
-
server.serve_forever()
|
32 |
-
|
33 |
-
def start():
|
34 |
-
import gradio as gr
|
35 |
-
|
36 |
-
def op(name):
|
37 |
-
return ""
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
1 |
+
from flask import Flask, request
|
|
|
2 |
|
3 |
+
app = Flask(__name__)
|
4 |
|
5 |
+
@app.route('/execute', methods=['POST'])
|
6 |
+
def execute_code():
|
7 |
+
python_code = request.get_data(as_text=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
+
try:
|
10 |
+
result = exec(python_code)
|
11 |
+
return str(result)
|
12 |
+
except Exception as e:
|
13 |
+
return str(e)
|
14 |
+
|
15 |
+
if __name__ == '__main__':
|
16 |
+
app.run(host='0.0.0.0', port=12345)
|