-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
66 lines (48 loc) · 1.89 KB
/
server.py
File metadata and controls
66 lines (48 loc) · 1.89 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import pymysql
from http.server import BaseHTTPRequestHandler, HTTPServer
import requests
import neural_style as ns
from PIL import Image
import matplotlib.pyplot as plt
from torchvision.utils import save_image
port = 8000
class my_handler(BaseHTTPRequestHandler):
def _set_header(self):
self.send_response(200)
self.send_header('Content-Type', 'text/html; charset=utf-8')
self.end_headers()
def _key_value_parser(self, lists):
data = lists.split("&")
print(data)
set_ = {}
for list in data:
temp = list.split('=')
set_[temp[0]] = temp[1]
return set_
#create
def do_POST(self):
self._set_header()
content_length = int(self.headers['Content-Length'])
body = self.rfile.read(content_length).decode('utf-8')
request = self.path.split("192.168.50.67:8000")[0]
print("=====================")
print(request)
print(body)
kv = self._key_value_parser(body)
print(kv)
if(request == '/synthesizing'):
print("1")
cnn, cnn_normalization_mean, cnn_normalization_std, style_img, content_img, input_img = ns.set_neural_style(kv['content_image'], kv['style_image'])
output = ns.run_style_transfer(cnn, cnn_normalization_mean, cnn_normalization_std,
content_img, style_img, input_img)
save_img = output[0]
output_name = '{}x{}.jpg'.format(kv['style_image'], kv['content_image'])
save_image(save_img, './data/images/output/{}'.format(output_name))
self.wfile.write('{}'.format(output_name).encode('utf-8'))
print('synthesizing')
print('\n\n')
def run():
httpd = HTTPServer(('192.168.50.67', port), my_handler)
print('Server running on port : {}'.format(port))
httpd.serve_forever()
run()