-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.py
49 lines (37 loc) · 1.18 KB
/
server.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
from StringIO import StringIO
import numpy as np
from numpy import array
from skimage.measure import block_reduce
import matplotlib.pyplot as plt
import scipy
from base64 import decodestring
# Only use SSL for hosting
# import ssl
# context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
# context.load_cert_chain('fullchain.pem', 'privkey.pem')
try:
import Image
except ImportError:
from PIL import Image
import pytesseract
from flask import Flask, jsonify, render_template, request, redirect
app = Flask(__name__)
@app.route('/snap_a_signal', methods=["POST", "GET"])
def process_signal():
pixels = request.get_json()['data']
return jsonify(result=im2speech(pixels))
@app.route('/')
def root():
return render_template('index.html')
def im2speech(pixels):
fh = open("imageToSave.png", "wb")
fh.write(str(pixels.split(",")[1].decode('base64')))
fh.close()
text = pytesseract.image_to_string(Image.open('imageToSave.png'))
return text
if __name__ == "__main__":
# Add the following for hosting
# context = ('fulchain.pem', 'privkey.pem')
# app.run(host='0.0.0.0', port=8000, ssl_context=context)
# For testing on local
app.run(debug=True)