-
Notifications
You must be signed in to change notification settings - Fork 1
/
rest.py
34 lines (29 loc) · 880 Bytes
/
rest.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
from cStringIO import StringIO
import segment as s
import tornado.ioloop as ioloop
import tornado.web as web
fnames, vectors = s.load_vectors('images')
class QuiltHandler(web.RequestHandler):
def post(self):
data = StringIO(self.request.body)
seg = s.Segmentation(data)
seg.apply_textures(vectors, fnames)
result = StringIO()
seg.to_pil().save(result, format='PNG')
result.seek(0)
self.set_status(200)
self.set_header('Content-Type', 'image/png')
self.write(result.getvalue())
app = web.Application([
('/quilt', QuiltHandler)
])
if __name__ == '__main__':
import sys
try:
port = int(sys.argv[1])
except:
print 'invalid port. port number should be supplied as first argument'
sys.exit(1)
print port
app.listen(port)
ioloop.IOLoop.current().start()