-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
45 lines (36 loc) · 1020 Bytes
/
app.py
File metadata and controls
45 lines (36 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import json
import flask
from flask import request
from src import test_text as my_text
# 포트 번호 --- (*1)
TM_PORT_NO = 8085
# HTTP 서버 실행하기
app = flask.Flask(__name__)
print("http://localhost:" + str(TM_PORT_NO))
# 루트에 접근할 경우 --- (*2)
@app.route('/', methods=['GET'])
def index():
with open("src/index.html", "rb") as f:
return f.read()
# /api에 접근할 경우
@app.route('/api', methods=['GET'])
def api():
# URL 매개 변수 추출하기 --- (*3)
q = request.args.get('q', '')
if q == '':
return '{"label": "내용을 입력해주세요", "per":0}'
#print("q=", q)
# 텍스트 카테고리 판별하기 --- (*4)
try:
label, per, no = my_text.check_genre(q)
except Exception as inst:
label, per, no = '판별불가 ㅜㅠ', -1, 0
# 결과를 JSON으로 출력하기
return json.dumps({
"label": label,
"per": per,
"genre_no": no
})
if __name__ == '__main__':
# 서버 실행하기
app.run(debug=False, port=TM_PORT_NO)