Skip to content

Commit

Permalink
fix #6
Browse files Browse the repository at this point in the history
  • Loading branch information
xzyaoi committed Sep 27, 2018
1 parent 9c3e559 commit d761768
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cvpm/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os
import socket
import traceback

import gevent.pywsgi
from flask import Flask, g, request
from werkzeug.datastructures import ImmutableMultiDict
Expand All @@ -19,6 +18,8 @@

server.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER

def str2bool(v):
return str(v).lower() in ("true", "false", "yes","t","1")

def _isPortOpen(port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Expand Down Expand Up @@ -59,16 +60,22 @@ def infer():
if request.method == 'POST':
results = {}
config = ImmutableMultiDict(request.form)
config = config.to_dict()
if 'file' not in request.files:
return json.dumps({"error": "no file part!", "code": "400"}), 400
file = request.files['file']
if file and allowed_file(file.filename, 'infer'):
filename = secure_filename(file.filename)
# make sure the UPLOAD_FOLDER exists
if not os.path.isdir(server.config['UPLOAD_FOLDER']):
os.makedirs(server.config['UPLOAD_FOLDER'])
file_abs_path = os.path.join(server.config['UPLOAD_FOLDER'],
filename)
file.save(file_abs_path)
try:
results = server.solver.infer(file_abs_path, config.to_dict())
results = server.solver.infer(file_abs_path, config)
if str2bool(config['delete_after_process']):
os.remove(file_abs_path)
return json.dumps(results), 200
except Exception as e:
traceback.print_exc()
Expand Down
1 change: 1 addition & 0 deletions cvpm/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ def train(self, train_x, train_y, **kwargs):
pass

def start(self, port=None):
print('Server will run on port: ' + str(port))
run_server(self, port)
10 changes: 10 additions & 0 deletions dashboard/tpl/runner.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#coding:utf-8
import os
import sys
os.chdir(sys.path[0])

from {{Package}}.{{Filename}} import {{Classname}}

solver = {{Classname}}()

solver.start({{Port}})

0 comments on commit d761768

Please sign in to comment.