-
Notifications
You must be signed in to change notification settings - Fork 6
/
captcha_app.py
44 lines (39 loc) · 1.4 KB
/
captcha_app.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
import urllib2
import time, os
import captcha_crawl
from captcha_recognizer import OCR_recognizer
from flask import Flask, render_template, request, send_from_directory, make_response
app = Flask(__name__, static_url_path='')
app.initialized = False
@app.route("/")
def index():
return render_template('index.html')
@app.route("/recognize", methods=['POST'])
def recognize():
imageurl = request.form['imageurl']
image_fname = './images/recog.jpg'
if imageurl:
img_f = open('images/recog.jpg','wb')
img = urllib2.urlopen(imageurl)
img_f.write(img.read())
img_f.close()
else:
image_fname = './images/right.jpg'
if not app.initialized:
app.recognizer = OCR_recognizer('./models/sintegra_sc_model.ckpt')
app.initialized = True
print image_fname
recognized = app.recognizer.recognize(image_fname)
return render_template('recognized.html', imageurl=image_fname,
recognized=recognized)
@app.route('/images/<path:path>')
def send_images(path):
response = make_response(send_from_directory('images', path))
response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
response.headers['Pragma'] = 'no-cache'
return response
@app.route('/get_url')
def get_url_route():
return captcha_crawl.get_url()
if __name__ == "__main__":
app.run(host="0.0.0.0",debug=True)