-
Notifications
You must be signed in to change notification settings - Fork 12
/
cnn.py
58 lines (43 loc) · 1.51 KB
/
cnn.py
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
#!/usr/bin/python
import BaseHTTPServer
import SimpleHTTPServer
import json
import os
import sys
from cnnModule import *
web_port_number = 12345
class webHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_POST(self):
data_string = self.rfile.read(int(self.headers['Content-Length']))
self.send_response(200)
self.send_header('Content-type','text/html')
self.end_headers()
samples = json.loads(data_string)
print '--------------------------------------------------------------------------------'
print 'RECEIVED CLASSIFICATION REQUEST: ' + ','.join([str(x) for x in samples])
dt = RunCNNClassifier(samples)
responses = samples
print 'SENDING RESPONSES: ' + ','.join([str(x) for x in responses])
self.wfile.write(json.dumps({'dt':dt, 'r':responses}))
print '--------------------------------------------------------------------------------'
return
# -----------------------------------------------------------------------------
print
print ' *** CS 61C, Spring 2015: Project 3 ***'
print
if len(sys.argv) > 1:
web_port_number = int(sys.argv[1])
print 'OVERRIDING PORT: %d' % web_port_number
print
try:
server = BaseHTTPServer.HTTPServer(('', web_port_number), webHandler)
print 'Launched web server! Open your browser and open the following page:'
print
print 'http://localhost:%d' % web_port_number
print
print 'Press CTRL+C to terminate'
os.chdir('web')
server.serve_forever()
except KeyboardInterrupt:
print 'CTRL+C received, shutting down the web server'
server.socket.close()