Explorar el Código

add restful web gui when server start

jiangjiajun hace 4 años
padre
commit
e9eb630d59

+ 23 - 3
paddlex_restful/restful/app.py

@@ -23,7 +23,7 @@ import json
 import sys
 import multiprocessing as mp
 from . import workspace_pb2 as w
-from .utils import CustomEncoder, ShareData, is_pic, get_logger, TaskStatus
+from .utils import CustomEncoder, ShareData, is_pic, get_logger, TaskStatus, get_ip
 import numpy as np
 
 app = Flask(__name__)
@@ -921,11 +921,27 @@ def model_file():
         ret = data['path']
         return send_file(ret)
 
-@app.route('/gui', methods=['GET'])
+
+@app.route('/', methods=['GET'])
 def gui():
     if request.method == 'GET':
+        file_path = osp.join(
+            osp.dirname(__file__), 'templates', 'paddlex_restful_demo.html')
+        ip = get_ip()
+        url = 'var str_srv_url = "http://' + ip + ':' + str(SD.port) + '";'
+        f = open(file_path, 'r+')
+        lines = f.readlines()
+        for i, line in enumerate(lines):
+            if '0.0.0.0:8080' in line:
+                lines[i] = url
+                break
+        f.close()
+        f = open(file_path, 'w+')
+        f.writelines(lines)
+        f.close()
         return render_template('/paddlex_restful_demo.html')
 
+
 def run(port, workspace_dir):
     if workspace_dir is None:
         user_home = os.path.expanduser('~')
@@ -940,7 +956,11 @@ def run(port, workspace_dir):
             os.makedirs(dirname)
     logger = get_logger(osp.join(dirname, "mcessages.log"))
     init(dirname, logger)
+    SD.port = port
+    ip = get_ip()
+    url = ip + ':' + str(port)
     try:
+        logger.info("RESTful服务启动成功后,您可以在浏览器打开 {} 使用WEB版本GUI".format(url))
         app.run(host='0.0.0.0', port=port, threaded=True)
     except:
-        print("请确保端口号:{}未被防火墙限制".format(port))
+        print("服务启动不成功,请确保端口号:{}未被防火墙限制".format(port))

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 157 - 157
paddlex_restful/restful/frontend_demo/paddlex_restful_demo.html


+ 1 - 0
paddlex_restful/restful/utils.py

@@ -43,6 +43,7 @@ class ShareData():
     workspace_dir = ""
     has_gpu = True
     monitored_processes = mp.Queue(4096)
+    port = 5000
     current_port = 8000
     running_boards = {}
     machine_info = dict()

+ 14 - 2
setup.py

@@ -27,7 +27,15 @@ setuptools.setup(
     long_description_content_type="text/plain",
     url="https://github.com/PaddlePaddle/PaddleX",
     packages=setuptools.find_packages(),
+    package_data={
+        'paddlex_restful/restful/templates':
+        ['paddlex_restful/restful/templates/paddlex_restful_demo.html']
+    },
     include_package_data=True,
+    data_files=[('paddlex_restful/restful/templates', [
+        'paddlex_restful/restful/templates/paddlex_restful_demo.html'
+    ])],
+    include_data_files=True,
     setup_requires=['cython', 'numpy'],
     install_requires=[
         "pycocotools;platform_system!='Windows'", 'pyyaml', 'colorama', 'tqdm',
@@ -41,5 +49,9 @@ setuptools.setup(
         "Operating System :: OS Independent",
     ],
     license='Apache 2.0',
-    entry_points={'console_scripts': ['paddlex=paddlex.command:main', 'paddlex_restful=paddlex_restful.command:main']})
-
+    entry_points={
+        'console_scripts': [
+            'paddlex=paddlex.command:main',
+            'paddlex_restful=paddlex_restful.command:main'
+        ]
+    })

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio