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