Skip to content

Commit

Permalink
Merge pull request #4 from BaoBaoGitHub/main
Browse files Browse the repository at this point in the history
add logging & CORS & update requirements.txt
  • Loading branch information
liuchaoss authored Nov 13, 2022
2 parents 024b025 + 2c394cf commit 1dea597
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
40 changes: 33 additions & 7 deletions flask_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,58 @@
import parsing
from indexing import SearchEngine
import reranking
import logging
from flask_cors import CORS

se = SearchEngine()
app = Flask(__name__)
jdk = util.load_pkl('data/jdk_vocab.pkl')
CORS(app, supports_credentials=True)


@app.route('/')
def index():
ip = request.environ.get('HTTP_X_REAL_IP', request.remote_addr)
print('ip:', ip)
app.logger.info(f"access from ip:{ip}")
return render_template('index.html')


@app.route('/search/<query>', methods=['POST', 'GET'])
def search(query):
print(query)
app.logger.info("query" + "*" * 50)
app.logger.info(query)
query_parse = parsing.parse(query)
print(1)

data, cmds = se.fuzzy_search(query_parse, top_k=10)
results = reranking.reranking(query_parse, data, cmds, jdk)
print(3)
# print(results)
# return render_template('search.html',results=results)
app.logger.info("results" + "*" * 50)
for result in results:
app.logger.info(result)

json = jsonify({"result": results})
return json


def logging_setting():
handler1 = logging.FileHandler(filename="flask.log", encoding="utf-8")
# handler2 = logging.StreamHandler()

app.logger.setLevel(logging.DEBUG)
handler1.setLevel(logging.INFO)
# handler2.setLevel(logging.NOTSET)

formatter = logging.Formatter(
"%(asctime)s - %(levelname)s - %(filename)s - %(funcName)s - %(lineno)s - %(message)s")
handler1.setFormatter(formatter)
# handler2.setFormatter(formatter)

app.logger.addHandler(handler1)
# app.logger.addHandler(handler2)


if __name__ == '__main__':
app.run(host='localhost', debug=True)
# setting debug as True if you want to see details
# app.debug = True
logging_setting()
app.run(host='0.0.0.0')

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ typing-extensions==4.2.0
urllib3==1.26.9
Werkzeug==2.1.2
zipp==3.8.0
Flask_Cors==3.0.10

0 comments on commit 1dea597

Please sign in to comment.