Add fuzzy and text-classification light model #1
1 changed files with 5 additions and 5 deletions
|
@ -2,24 +2,24 @@ import http.server
|
|||
import json
|
||||
import logging
|
||||
|
||||
|
||||
def get_server(ip, port, answer_function):
|
||||
class Server(http.server.BaseHTTPRequestHandler):
|
||||
|
||||
|
||||
def do_POST(self):
|
||||
length = int(self.headers.get('content-length'))
|
||||
field_data = self.rfile.read(length)
|
||||
fields = json.loads(field_data)
|
||||
text = fields['text'].strip()
|
||||
|
||||
|
||||
res = answer_function(text)
|
||||
|
||||
logging.info('Get request:' + text)
|
||||
print(text)
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type','text/plain')
|
||||
self.send_header('Content-type', 'text/plain; charset=utf-8')
|
||||
self.end_headers()
|
||||
|
||||
|
||||
self.wfile.write(res.encode())
|
||||
|
||||
return http.server.HTTPServer((ip, port), Server)
|
||||
return http.server.HTTPServer((ip, port), Server)
|
||||
|
|
Loading…
Add table
Reference in a new issue